Mirror Pattern Feature Example (VBA)
This example shows how to mirror a pattern feature.
'*******************************************************************************
'
' Preconditions: A new part document is open.
'
' Postconditions: Two bodies, mirror plane, and chamfer
feature are created
' Chamfer
feature is mirrored from one body to another
'
' ******************************************************************************
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelMgr As SelectionMgr
Dim swFeatMgr As SldWorks.FeatureManager
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swSelMgr = swModel.SelectionManager
Set swFeatMgr = swModel.FeatureManager
Call CreateBodiesAndFeature
boolstatus = swModelDocExt.SelectByID2("Plane1",
"PLANE", 0, 0, 0, False, 2, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Chamfer1",
"BODYFEATURE", 0, 0, 0, True, 1, Nothing, 0)
swFeatMgr.InsertMirrorFeature2
False, True, False, False, swFeatureScope_e.swFeatureScope_SelectedBodiesWithAutoSelect
End Sub
Sub CreateBodiesAndFeature()
boolstatus = swModelDocExt.SelectByID2("Front
Plane", "PLANE", -0.07123644442095, 0.0626824326557, -0.004995018808801,
False, 0, Nothing, 0)
swModel.ClearSelection2
True
swModel.SketchRectangle
-0.03870663771712, 0.03937630272953, 0, 0.0445996898263, -0.02705446650124,
0, 1
swModel.ShowNamedView2
"*Trimetric", 8
swModel.ClearSelection2
True
boolstatus = swModelDocExt.SelectByID2("Line2",
"SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Line1",
"SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Line4",
"SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Line3",
"SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
swFeatMgr.FeatureExtrusion2
True, False, False, 0, 0, 0.02, 0.01, False, False, False, False, 0.01745329251994,
0.01745329251994, False, False, False, False, 1, 1, 1, 0, 0, False
swSelMgr.EnableContourSelection
= 0
boolstatus = swModelDocExt.SelectByID2("",
"FACE", -0.01450930355037, 0.01645564156394, 0.01999999999998,
True, 0, Nothing, 0)
swModel.CreatePlaneAtOffset3
0.03, False, True
swModel.ClearSelection2
True
boolstatus = swModelDocExt.SelectByID2("Plane1",
"PLANE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Extrude1",
"SOLIDBODY", -0.01616769479756, 0.03631008029822, 0.01999999999992,
True, 0, Nothing, 0)
swModel.ClearSelection2
True
boolstatus = swModelDocExt.SelectByID2("Plane1",
"PLANE", 0, 0, 0, False, 2, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Extrude1",
"SOLIDBODY", -0.01616769479756, 0.03631008029822, 0.01999999999992,
True, 256, Nothing, 0)
swFeatMgr.InsertMirrorFeature2
True, False, False, False, swFeatureScope_SelectedBodiesWithAutoSelect
boolstatus = swModelDocExt.SelectByID2("",
"EDGE", -0.01592281338117, 0.03962412355071, 0.01983163419141,
True, 0, Nothing, 0)
swFeatMgr.InsertFeatureChamfer
4, 1, 0.01, 0.7853981633975, 0, 0, 0, 0
End Sub