Hide Table of Contents

Create Fill Pattern Example (C#)

This example shows how to create a Fill Pattern feature and get its data.

//----------------------------------------------------------------------------
// Preconditions: Ensure the specified template exists.
//
// Postconditions:
// 1. A new part and extrusion are created.
// 2. The specified square Fill Pattern layout is created.
// 3. Inspect the Immediate window for Fill Pattern feature data.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace FeatureFillPattern_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        
ModelDoc2 Part;
        
FeatureManager featMgr;
        
Feature feat;
        
Feature Feature;
        
Component2 Component;
        
FillPatternFeatureData FeatureData;
        
string[] featuresToPatternTypes = new string[3];
        
double pi;
        
double DegreesToRadians;
        
double RadiansToDegrees;
        
double mToInch;
        
bool boolstatus;
        
int stat;

        
public void Main()
        {
            Part = (
ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2014\\templates\\Part.prtdot", 0, 0, 0);
            swApp.ActivateDoc2(
"Part1", false, ref stat);
            Part = (
ModelDoc2)swApp.ActiveDoc;
            featMgr = Part.FeatureManager;

            
// Extrude a rectangular sketch
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.0114967331462065, 9.36611790208E-05, -0.0022811248418421, false, 0, null, 0);
            Part.SketchManager.InsertSketch(
true);
            Part.ClearSelection2(
true);
            
object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0202585524598772, 0.0215183746607767, 0, 0.0717550769780327, -0.0360170798121084, 0);
            Part.ClearSelection2(
true);
            Part.SketchManager.InsertSketch(
true);
            Part.ShowNamedView2(
"*Trimetric", 8);
            Part.SketchManager.InsertSketch(
true);
            Part.ClearSelection2(
true);
            boolstatus = Part.Extension.SelectByID2(
"Sketch2", "SKETCH", 0, 0, 0, false, 4, null, 0);
            
object myFeature = null;
            myFeature = Part.FeatureManager.FeatureExtrusion2(
true, false, false, 0, 0, 0.01, 0.01, false, false, false,
            
false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            0, 0,
false);
            ((
SelectionMgr)Part.SelectionManager).EnableContourSelection = false;
            Part.ClearSelection2(
true);

            
// Select the direction reference; Mark = 2
            boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.0187332584903857, -0.0358645491226639, 0.00989637290047085, true, 2, null, 0);

            
// Select the fill boundary; Mark = 1
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0148641447087243, -0.00450612805275341, 0.00999999999970669, true, 1, null, 0);

            
// Create perforated Fill Pattern of circles
            //Set feat = featMgr.FeatureFillPattern((int)swPatternLayoutType_e.swPatternLayoutPerforation, (int)swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing, 0.00859, 60#, 0, 0, 0, 0, (int)swFeaturesToPatternType_e.swFeaturesToPatternCreateSeedCut, (int)swCreateSeedCutType_e.swCreateSeedCutCircle, 0.008, 0, 0, 0, 0, 0, 0, False, True)

            // Create square Fill Pattern of circles
            feat = featMgr.FeatureFillPattern((int)swPatternLayoutType_e.swPatternLayoutSquare, (int)swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing, 0.01, 0, 0, 0.01, 0, 0, (int)swFeaturesToPatternType_e.swFeaturesToPatternCreateSeedCut, (int)swCreateSeedCutType_e.swCreateSeedCutCircle,
            0.008, 0, 0, 0, 0, 0, 0,
false, true);

            
// Create circular Fill Pattern of circles
            //Set feat = featMgr.FeatureFillPattern((int)swPatternLayoutType_e.swPatternLayoutCircular, (int)swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing, 0.01, 0, 0, 0.01, 0, 0, (int)swFeaturesToPatternType_e.swFeaturesToPatternCreateSeedCut, (int)swCreateSeedCutType_e.swCreateSeedCutCircle, 0.008, 0, 0, 0, 0, 0, 0, False, True)

            // Create polygonal Fill Pattern of circles
            //Set feat = featMgr.FeatureFillPattern((int)swPatternLayoutType_e.swPatternLayoutPolygon, (int)swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing, 0.00859, 0, 0, 0.02, 0, 0, (int)swFeaturesToPatternType_e.swFeaturesToPatternCreateSeedCut, (int)swCreateSeedCutType_e.swCreateSeedCutCircle, 0.008, 0, 0, 0, 3, 0, 0, False, True)

            pi = System.Math.Asin(1) * 2;
            mToInch = 1 / 0.0254;
            DegreesToRadians = pi / 180.0;
            RadiansToDegrees = 1.0 / DegreesToRadians;

            featuresToPatternTypes[0] =
"swFeaturesToPatternSelectedFeatures";
            featuresToPatternTypes[1] =
"swFeaturesToPatternCreateSeedCut";

            boolstatus = Part.Extension.SelectByID2(
"Fill Pattern1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            Feature = (
Feature)((SelectionMgr)Part.SelectionManager).GetSelectedObject6(1, -1);
            Component = (
Component2)((SelectionMgr)Part.SelectionManager).GetSelectedObjectsComponent4(1, -1);
            FeatureData = (
FillPatternFeatureData)Feature.GetDefinition();
            boolstatus = FeatureData.AccessSelections(Part, Component);
 

            Debug.Print("");

            
// Properties for square Fill Pattern layouts of circular seed cuts
            Debug.Print(" Pattern layout type          = " + layoutType(FeatureData.PatternLayoutType));
            
Debug.Print(" Pattern layout spacing type  = " + spacingType(FeatureData.LayoutSpacingType));
            
Debug.Print(" Loop spacing                 = " + FeatureData.LoopSpacing * mToInch + " in");
            
Debug.Print(" Instance spacing             = " + FeatureData.InstanceSpacing * mToInch + " in");
            
Debug.Print(" Margins                      = " + FeatureData.Margins * mToInch + " in");
            
Debug.Print(" Features to pattern type     = " + featuresToPatternTypes[FeatureData.FeaturesToPatternType]);
            
Debug.Print(" Seed cut type                = " + seedCutType(FeatureData.CreateSeedCutType));
            
Debug.Print(" Diameter                     = " + FeatureData.Diameter * mToInch + " in");
            
Debug.Print(" Geometry pattern             = " + FeatureData.GeometryPattern);
            
Debug.Print(" Propagate visual property?   = " + FeatureData.PropagateVisualProperty);
            
Debug.Print(" Feature scope                = " + FeatureData.FeatureScope);

            
// Properties for perforated Fill Pattern layouts
            //Debug.Print " Stagger angle               = " & FeatureData.StaggerAngle * RadiansToDegrees & " Deg"

            // Properties for polygonal Fill Pattern layouts
            //Debug.Print " Polygon layout sides        = " & FeatureData.PatternLayoutPolygonSides

            // Properties for IFillPatternFeatureData::LayoutSpacingType = swPatternLayoutSpacingType_e.swPatternLayoutInstances
            //Debug.Print " Number of instances         = " & FeatureData.NoOfInstances

            // Properties for diamond seed cuts
            //Debug.Print " Diagonal                    = " & FeatureData.Diagonal * mToInch & " in"

            // Properties for square and diamond seed cuts
            //Debug.Print " Dimension                   = " & FeatureData.Dimension * mToInch & " in"
            //Debug.Print " Rotation                    = " & FeatureData.Rotation * RadiansToDegrees & " deg"

            // Properties for polygonal seed cuts
            //Debug.Print " Polygon seed cut sides      = " & FeatureData.CreateSeedCutPolygonSides
            //Debug.Print " Outer radius                = " & FeatureData.OuterRadius * mToInch & " in"
            //Debug.Print " Inner radius                = " & FeatureData.InnerRadius * mToInch & " in"

            // Reference pattern direction is an extrusion edge
            Edge pattDirection = default(Edge);
            pattDirection = (
Edge)FeatureData.PatternDirection;
            
Debug.Print("Pattern reference direction ID: " + pattDirection.GetID());

            
// Properties if IFillPatternFeatureData::FeaturesToPatternType = swFeaturesToPatternType_e.swFeaturesToPatternSelectedFeatures
            //Dim pattFeatArray As Variant
            //pattFeatArray = FeatureData.PatternFeatureArray

            FeatureData.ReleaseSelectionAccess();

        }
        
public string spacingType(int n)
        {
            
string functionReturnValue = null;
            functionReturnValue =
null;
            
switch (n)
            {
                
case (int)swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing:
                    functionReturnValue =
"swPatternLayoutTargetSpacing";
                    
break;
                
case (int)swPatternLayoutSpacingType_e.swPatternLayoutInstances:
                    functionReturnValue =
"swPatternLayoutInstances";
                    
break;
            }
      
            
return functionReturnValue;
        }
        
public string layoutType(int n)
        {
            
string functionReturnValue = null;
            functionReturnValue =
null;
            
switch (n)
            {
                
case (int)swPatternLayoutType_e.swPatternLayoutPerforation:
                    functionReturnValue =
"swPatternLayoutPerforation";
                    
break;
                
case (int)swPatternLayoutType_e.swPatternLayoutCircular:
                    functionReturnValue =
"swPatternLayoutCircular";
                    
break;
                
case (int)swPatternLayoutType_e.swPatternLayoutSquare:
                    functionReturnValue =
"swPatternLayoutSquare";
                    
break;
                
case (int)swPatternLayoutType_e.swPatternLayoutPolygon:
                    functionReturnValue =
"swPatternLayoutPolygon";
                    
break;
            }

            
return functionReturnValue;
        }
        
public string seedCutType(int n)
        {
            
string functionReturnValue = null;
            functionReturnValue =
null;
            
switch (n)
            {
                
case (int)swCreateSeedCutType_e.swCreateSeedCutCircle:
                    functionReturnValue =
"swCreateSeedCutCircle";
                    
break;
                
case (int)swCreateSeedCutType_e.swCreateSeedCutSquare:
                    functionReturnValue =
"swCreateSeedCutSqaure";
                    
break;
                
case (int)swCreateSeedCutType_e.swCreateSeedCutDiamond:
                    functionReturnValue =
"swCreateSeedCutDiamond";
                    
break;
                
case (int)swCreateSeedCutType_e.swCreateSeedCutPolygon:
                    functionReturnValue =
"swCreateSeedCutPolygon";
                    
break;
            }

            
return functionReturnValue;
        }


        
public SldWorks swApp;

    }
}

 


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Fill Pattern Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.