Insert Grid System Feature Example (VBA)
This example shows how to insert a Grid System feature into a model.
'-----------------------------------------------------------------------------
' Preconditions: Verify that the specified Part template
exists.
'
' Postconditions:
' 1. GridSystem1 is in the FeatureManager design tree.
' 2. GridSystem1 contains Surface-Extrude1, Level1, Level2,
' and two derived sketches.
' 3. The height of each level of the surface extrude is 50.0
mm.
'------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim GridFeature As Feature
Dim Part As ModelDoc2
Dim myModelView As ModelView
Dim skSegment As SketchSegment
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
swApp.ResetUntitledCount 0, 0, 0
Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks
2011\templates\Part.prtdot", 0, 0, 0)
swApp.ActivateDoc2 "Part1", False, longstatus
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ShowNamedView2 "*Isometric", 7
Set skSegment =
Part.SketchManager.CreateCircle(-0.019633, 0.076084, 0#, -0.001997, 0.081475,
0#)
Part.SketchManager.InsertSketch True
boolstatus =
Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Dim offsetArray As Variant
Dim heightsArray() As Double
ReDim heightsArray(0 To 1) As Double
heightsArray(0) = 0.05
heightsArray(1) = 0.05
offsetArray = heightsArray
Set GridFeature = Part.FeatureManager.InsertGridFeature((offsetArray))
Debug.Print GridFeature.Name & " was created."
Part.ViewZoomtofit
End Sub