Hide Table of Contents

Create Fill Pattern Example (VB.NET)

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.
' ---------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics


Partial Class SolidWorksMacro

    
Dim Part As ModelDoc2
    
Dim featMgr As FeatureManager
    
Dim feat As Feature
    
Dim Feature As Feature
    
Dim Component As 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 stat As Integer

    Sub main()

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

        
' Extrude a rectangular sketch
        boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.0114967331462065, 0.0000936611790208, -0.0022811248418421, False, 0, Nothing, 0)
        Part.SketchManager.InsertSketch(
True)
        Part.ClearSelection2(
True)
        
Dim vSkLines As Object
        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, Nothing, 0)
        
Dim myFeature As Object
        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)
        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, Nothing, 0)

        
' Select the fill boundary; Mark = 1
        boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0148641447087243, -0.00450612805275341, 0.00999999999970669, True, 1, Nothing, 0)

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

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

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

        ' Create polygonal Fill Pattern of circles
        'Set feat = featMgr.FeatureFillPattern(swPatternLayoutType_e.swPatternLayoutPolygon, swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing, 0.00859, 0, 0, 0.02, 0, 0, swFeaturesToPatternType_e.swFeaturesToPatternCreateSeedCut, 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, Nothing, 0)

        Feature = Part.SelectionManager.GetSelectedObject6(1, -1)
        Component = Part.SelectionManager.GetSelectedObjectsComponent4(1, -1)
        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(
" 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
        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 spacingType(ByVal n As Integer) As String
        spacingType = Nothing
        Select Case n
            
Case swPatternLayoutSpacingType_e.swPatternLayoutTargetSpacing
                spacingType =
"swPatternLayoutTargetSpacing"
            Case swPatternLayoutSpacingType_e.swPatternLayoutInstances
                spacingType =
"swPatternLayoutInstances"
        End Select
        Return spacingType
    
End Function
    Function layoutType(ByVal n As Integer) As String
        layoutType = Nothing
        Select Case n
            
Case swPatternLayoutType_e.swPatternLayoutPerforation
                layoutType =
"swPatternLayoutPerforation"
            Case swPatternLayoutType_e.swPatternLayoutCircular
                layoutType =
"swPatternLayoutCircular"
            Case swPatternLayoutType_e.swPatternLayoutSquare
                layoutType =
"swPatternLayoutSquare"
            Case swPatternLayoutType_e.swPatternLayoutPolygon
                layoutType =
"swPatternLayoutPolygon"
        End Select
        Return layoutType
    
End Function
    Function seedCutType(ByVal n As Integer) As String
        seedCutType = Nothing
        Select Case n
            
Case swCreateSeedCutType_e.swCreateSeedCutCircle
                seedCutType =
"swCreateSeedCutCircle"
            Case swCreateSeedCutType_e.swCreateSeedCutSquare
                seedCutType =
"swCreateSeedCutSqaure"
            Case swCreateSeedCutType_e.swCreateSeedCutDiamond
                seedCutType =
"swCreateSeedCutDiamond"
            Case swCreateSeedCutType_e.swCreateSeedCutPolygon
                seedCutType =
"swCreateSeedCutPolygon"
        End Select
        Return seedCutType
    
End Function


  
    
Public swApp As SldWorks


End Class
 

 



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 (VB.NET)
*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.