Hide Table of Contents

Change Wrap Feature Face Example (VBA)

This example shows how to insert a wrap feature and change the face on which to apply a wrap feature.

' ******************************************************************************
' Preconditions:
' 1. Specified part document to open exits.
' 2. Run the macro.
'
' Postconditions:
' 1. Opens the part document.
' 2. Sketches a rectangle on the top plane.
' 3. Selects the sketch of the rectangle and the
'    face where to scribe the sketch as a wrap feature.
' 4. Inserts the wrap feature.
' 5. Rotates the part about its center.
' 6. Selects another face on the part.
' 7. Edits the wrap feature and wraps the rectangular
'    sketch on the second face.
'
' NOTE: Because this part document is used elsewhere, do not
' save any changes when closing it.
' ******************************************************************************
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSketchManager As SldWorks.SketchManager
Dim swFeature As SldWorks.Feature
Dim swFeatureManager As SldWorks.FeatureManager
Dim swModelView As SldWorks.ModelView
Dim swWrapFeature As SldWorks.Feature
Dim swWrapFeatureData As SldWorks.WrapSketchFeatureData
Dim swSelectionManager As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim sketchLines As Variant
Dim status As Boolean
Dim errors As Long, warnings As Long
Dim fileName As String
Sub main()
    Set swApp = Application.SldWorks    
    ' Open part document
    fileName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\clamp1.sldprt"
    Set swModel = swApp.OpenDoc6(fileName, swDocPART, swOpenDocOptions_Silent, "", errors, warnings)
    Set swModelDocExt = swModel.Extension    
    ' Sketch a rectangle on the top plane
    swModel.ViewZoomtofit2
    swModel.ShowNamedView2 "*Top", 5
    status = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
    Set swSketchManager = swModel.SketchManager
    swSketchManager.InsertSketch True
    swModel.ClearSelection2 True
    swModel.ViewZoomtofit2
    sketchLines = swSketchManager.CreateCornerRectangle(-1.69758295694522E-03, 9.48506512727088E-04, 0, 1.3668226995581E-03, -9.84987532447629E-04, 0)
    swModel.ClearSelection2 True
    swSketchManager.InsertSketch True
    swModel.ClearSelection2 True    
    ' Select the sketch of the rectangle and the
    ' face where to scribe the sketch as a wrap feature
    status = swModelDocExt.SelectByID2("Sketch11", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)
    status = swModelDocExt.SelectByID2("", "FACE", 2.27884819256505E-03, 0.036653462145523, -2.91848157762346E-04, True, 1, Nothing, 0)    
    ' Insert the wrap feature
    Set swFeatureManager = swModel.FeatureManager
    Set swFeature = swFeatureManager.InsertWrapFeature(2, 0.001, False)
    swModel.ClearSelection2 True    
    ' Rotate the part about its center to select another face
    Set swModelView = swModel.ActiveView
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 0.039572760932108, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 5.08792640555675E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 5.08792640555675E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 0.039572760932108, -8.45813406735716E-03
    swModelView.RotateAboutCenter 5.08792640555675E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 0.039572760932108, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 5.08792640555675E-02, -1.69162681347143E-02
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 5.08792640555675E-02, 0
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 9.61052765494052E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 0.039572760932108, 0
    swModelView.RotateAboutCenter 6.78390187407566E-02, 0
    swModelView.RotateAboutCenter 6.21857671790269E-02, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 5.08792640555675E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 2.26130062469189E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 3.39195093703783E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, -8.45813406735716E-03
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.82662578086486E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 2.26130062469189E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.69597546851892E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, -8.45813406735716E-03
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, -8.45813406735716E-03
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 1.13065031234594E-02, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    swModelView.RotateAboutCenter 5.65325156172972E-03, 0
    
    ' Select another face where to apply the wrap feature
    status = swModelDocExt.SelectByID2("", "FACE", 2.39269080197957E-03, 2.63524999999731E-02, -4.79719888705432E-04, True, 0, Nothing, 0)
    Set swSelectionManager = swModel.SelectionManager
    Set swFace = swSelectionManager.GetSelectedObject6(1, -1)    
    ' Edit the wrap feature to wrap the rectangular 
    ' sketch on the second face
    Set swWrapFeature = swModel.FeatureByName("Wrap1")
    Set swWrapFeatureData = swWrapFeature.GetDefinition
    status = swWrapFeatureData.AccessSelections(swModel, Nothing)
    swWrapFeatureData.Face = swFace
    Debug.Print "Wrap type: " & swWrapFeatureData.Type
    Debug.Print "Wrap thickness: " & swWrapFeatureData.Thickness
    Debug.Print "Reverse direction? " & swWrapFeatureData.ReverseDirection
    status = swWrapFeature.ModifyDefinition(swWrapFeatureData, swModel, Nothing)    
    swModel.ClearSelection2 True
    
End Sub


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:   Change Wrap Feature Face Example (VBA)
*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.