First, record a macro that generates the stretching feature and analyze the VBA code.
Recording macro:
1. Call the macro recording function;
2. Insert stretching features
2.1 draw a sketch
2.2 complete feature Creation
3. Tensile features are obtained.
View macro code
1 '************************************** ****************************************
2 'C: \ DOCUME ~ 1 \ ADMINI ~ 1 \ LOCALS ~ 1 \ Temp \ swx1944 \ Macro1.swb-macro recorded on 02/20/09 by Administrator
3 '************************************** ****************************************
4 Dim swApp As Object
5 Dim Part As Object
6 Dim SelMgr As Object
7 Dim boolstatus As Boolean
8 Dim longstatus As Long, longwarnings As Long
9 Dim Feature As Object
10 Sub main ()
11
12 Set swApp = Application. SldWorks
13 Set Part = swApp. ActiveDoc
14 Set SelMgr = Part. SelectionManager
15
16 boolstatus = Part. Extension. SelectByID2 ("front view PLANE", "PLANE",-0.02702695540936, 0.05597407407407, 0, False, 0, Nothing, 0)
17' 1. Sketch start
18 Part. SketchManager. InsertSketch True
19 Part. ClearSelection2 True
20' 2. 1. Draw a polygon
21 Dim vSkLines As Variant
22 vSkLines = Part. SketchManager. CreatePolygon (0, 0, 0, 0.06108281893004,-0.02843127572016, 0, 6, True)
23 Part. ClearSelection2 True
24' 2. 2 draw circles
25 Dim SkCircle As Object
26 Set SkCircle = Part. SketchManager. CreateCircle (0,-0.005126179673967, 0, 0.02643220164609,-0.01865802469136, 0)
27 Part. ClearSelection2 True
28' 3. The sketch ends
29 Part. SketchManager. InsertSketch True
30
31 Part. ShowNamedView2 "* upper and lower second-class angle Axis Test", 8
32 Part. SketchManager. InsertSketch True
33 Part. ClearSelection2 True
34 '4. Stretch features
35 boolstatus = Part. Extension. SelectByID2 ("SKETCH 1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
36 Part. featureManager. featureExtrusion2 True, False, False, 0, 0, 0.05, 0.01, False, 0.01745329251994, 0.01745329251994, False, 1, 1, 1, 0, 0, False
37 Part. SelectionManager. enabledeletion selection = 0
38 End Sub
Code Analysis:
The FeatureExtrusion2 method of the FeatureManager class is used to generate tensile features. Of course, before generating features, we need to use the SelectByID2 method to select the contour to be stretched (that is, the sketch ).