Hide Table of Contents

Create Fill Pattern Example (VBA)

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.
' ---------------------------------------------------------------------------

Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim featMgr As SldWorks.FeatureManager
Dim feat As SldWorks.Feature
Dim Feature As Feature
Dim Component As SldWorks.Component2
Dim FeatureData As FillPatternFeatureData
Dim featuresToPatternTypes(2) As String
Dim pi As Double
Dim DegreesToRadians As Double
Dim RadiansToDegrees As Double
Dim value As Double
Dim mToInch As Double
Dim boolstatus As Boolean
Dim longstatus As Long
Option Explicit

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2014\templates\Part.prtdot", 0, 0, 0)
    swApp.ActivateDoc2 "Part1", False, longstatus
    Set Part = swApp.ActiveDoc
    Set featMgr = Part.FeatureManager
   

    ' Extrude a rectangular sketch
    boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -1.14967331462065E-02, 9.36611790208E-05, -2.2811248418421E-03, False, 0, Nothing, 0)
    Part.SketchManager.InsertSketch True
    Part.ClearSelection2 True
    Dim vSkLines As Variant
    vSkLines = Part.SketchManager.CreateCornerRectangle(-2.02585524598772E-02, 2.15183746607767E-02, 0, 7.17550769780327E-02, -3.60170798121084E-02, 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, Nothing, 0)
    Dim myFeature As Object
    Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.01, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)
    Part.SelectionManager.EnableContourSelection = False
    Part.ClearSelection2 True
   

    ' Select the direction reference; Mark = 2
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 1.87332584903857E-02, -3.58645491226639E-02, 9.89637290047085E-03, True, 2, Nothing, 0)
   

    ' Select the fill boundary; Mark = 1
    boolstatus = Part.Extension.SelectByID2("", "FACE", 1.48641447087243E-02, -4.50612805275341E-03, 9.99999999970669E-03, True, 1, Nothing, 0)
   

    ' Create perforated Fill Pattern of circles
    'Set feat = featMgr.FeatureFillPattern(swPatternLayoutPerforation, swPatternLayoutTargetSpacing, 0.00859, 60#, 0, 0, 0, 0, swFeaturesToPatternCreateSeedCut, swCreateSeedCutCircle, 0.008, 0, 0, 0, 0, 0, 0, False, True)
   

    ' Create square Fill Pattern of circles
    Set feat = featMgr.FeatureFillPattern(swPatternLayoutSquare, swPatternLayoutTargetSpacing, 0.01, 0, 0, 0.01, 0, 0, swFeaturesToPatternCreateSeedCut, swCreateSeedCutCircle, 0.008, 0, 0, 0, 0, 0, 0, False, True)
   

    ' Create circular Fill Pattern of circles
    'Set feat = featMgr.FeatureFillPattern(swPatternLayoutCircular, swPatternLayoutTargetSpacing, 0.01, 0, 0, 0.01, 0, 0, swFeaturesToPatternCreateSeedCut, swCreateSeedCutCircle, 0.008, 0, 0, 0, 0, 0, 0, False, True)
   

    ' Create polygonal Fill Pattern of circles
    'Set feat = featMgr.FeatureFillPattern(swPatternLayoutPolygon, swPatternLayoutTargetSpacing, 0.00859, 0, 0, 0.02, 0, 0, swFeaturesToPatternCreateSeedCut, swCreateSeedCutCircle, 0.008, 0, 0, 0, 3, 0, 0, False, True)
   

    pi = Arcsin(1) * 2
    mToInch = 1 / 0.0254
    DegreesToRadians = pi / 180#
    RadiansToDegrees = 1# / DegreesToRadians
   

    featuresToPatternTypes(0) = "swFeaturesToPatternSelectedFeatures"
    featuresToPatternTypes(1) = "swFeaturesToPatternCreateSeedCut"
   

    boolstatus = Part.Extension.SelectByID2("Fill Pattern1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
   

    Set Feature = Part.SelectionManager.GetSelectedObject6(1, -1)
    Set Component = Part.SelectionManager.GetSelectedObjectsComponent4(1, -1)
    Set FeatureData = 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 " 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 diamond, square, and polygonal seed cuts
    'Debug.Print " Rotation                    = " & FeatureData.Rotation * RadiansToDegrees & " deg"

 

    ' Properties for square and diamond seed cuts
    'Debug.Print " Dimension                   = " & FeatureData.Dimension * mToInch & " in"
   

    ' 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
    Dim pattDirection As Edge
    pattDirection = 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
   

End Sub
Function layoutType(n As Long) As String

    Select Case n
    Case swPatternLayoutPerforation:
        layoutType = "swPatternLayoutPerforation"
    Case swPatternLayoutCircular:
        layoutType = "swPatternLayoutCircular"
    Case swPatternLayoutSquare:
        layoutType = "swPatternLayoutSquare"
    Case swPatternLayoutPolygon:
        layoutType = "swPatternLayoutPolygon"
    End Select
 

End Function
Function spacingType(n As Long) As String

    Select Case n
    Case swPatternLayoutTargetSpacing:
        spacingType = "swPatternLayoutTargetSpacing"
    Case swPatternLayoutInstances:
        spacingType = "swPatternLayoutInstances"
    End Select
 

End Function
Function seedCutType(n As Long) As String

    Select Case n
    Case swCreateSeedCutCircle:
        seedCutType = "swCreateSeedCutCircle"
    Case swCreateSeedCutSquare:
        seedCutType = "swCreateSeedCutSqaure"
    Case swCreateSeedCutDiamond:
        seedCutType = "swCreateSeedCutDiamond"
    Case swCreateSeedCutPolygon:
        seedCutType = "swCreateSeedCutPolygon"
    End Select

End Function

 



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 (VBA)
*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) 2015 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.