[Secondary Development of SolidWorks] Feature Modeling -- stretching (1)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.