Hide Table of Contents

Insert Swept-surface Feature Example (VBA)

This example shows how to create a swept-surface feature.

'---------------------------------------------------------------------------
' Preconditions: Verify that the part template exists.
'
' Postconditions:
' 1. Opens a new part.
' 2. Creates two sketches.
' 3. Inserts a swept-surface feature.
' 4. Examine the FeatureManager design tree and
'    graphics area.
'---------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSketchManager As SldWorks.SketchManager
Dim swSketchSegment As SldWorks.SketchSegment
Dim swPathFeat As SldWorks.Feature
Dim swFeatureMgr As SldWorks.FeatureManager
Dim swSweep As SldWorks.SweepFeatureData
Dim status As Boolean
Sub main()
    Set swApp = Application.SldWorks    
    'Open new part document
    Set swModel = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\part.prtdot", 0, 0, 0)
    Set swModelDocExt = swModel.Extension    
    'Create a sketch
    Set swSketchManager = swModel.SketchManager
    swSketchManager.InsertSketch True
    status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
    Set swSketchSegment = swSketchManager.CreateLine(0#, 0#, 0#, 0.068491, 0.049604, 0#)
    Set swSketchSegment = swSketchManager.CreateLine(0.068491, 0.049604, 0#, 0.10923, 0.112837, 0#)
    Set swSketchSegment = swSketchManager.CreateLine(0.10923, 0.112837, 0#, 0.194652, 0.154023, 0#)
    swSketchManager.InsertSketch True    
    swModel.ViewZoomtofit2
    swModel.ShowNamedView2 "*Isometric", 7
    swModel.ClearSelection2 True
    'Create another sketch
    status = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
    swSketchManager.InsertSketch True
    Set swSketchSegment = swSketchManager.CreateLine(-0#, 0#, 0#, 0.021042, 0.091756, 0#)
    Set swSketchSegment = swSketchManager.CreateLine(0.021042, 0.091756, 0#, 0.098366, 0.085093, 0#)
    Set swSketchSegment = swSketchManager.CreateLine(0.098366, 0.085093, 0#, 0.143062, 0.122696, 0#)
    swModel.ClearSelection2 True
    swSketchManager.InsertSketch True    
    'Insert surface sweep
    status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, False, 1, Nothing, 0)
    status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, True, 4, Nothing, 0)
    

    Set swFeatureMgr = swModel.FeatureManager

    Set swSweep = swFeatureMgr.CreateDefinition(swFmRefSurface)

    swSweep.TangentPropagation = False
    swSweep.TwistControlType = 0
    swSweep.MaintainTangency = False
    swSweep.AdvancedSmoothing = False
    swSweep.StartTangencyType = 0
    swSweep.EndTangencyType = 0
    swSweep.PathAlignmentType = 0
    swSweep.FeatureScope = True
    swSweep.AutoSelect = True
    swSweep.SetTwistAngle 0#
    swSweep.MergeSmoothFaces = True
    swSweep.CircularProfile = False
    swSweep.CircularProfileDiameter = 0#
    swSweep.Direction = 0
   

    Set swPathFeat = swFeatureMgr.CreateFeature(swSweep)
 

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:   Insert Swept-surface Feature 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) 2019 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.