Hide Table of Contents

Insert Extruded Reference Surface Example (VBA)

This example shows how to insert an extruded surface into a model.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified part template exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Creates Surface-Extrude1 in the FeatureManager design tree.
' 2. Expand the Surface Bodies folder to verify that it contains:
'    * Surface-Extrude[1]
'    * Surface-Extrude[2]
'    * Surface-Extrude[3]
' 3. Inspect the Immediate window.
'---------------------------------------------------------------------------
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim selMgr As SldWorks.SelectionMgr
Dim surfExtrudeFeat As SldWorks.Feature
Dim surfExtrude As SldWorks.SurfExtrudeFeatureData
Dim boolstatus As Boolean
Dim longstatus As Long

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2016\templates\Part.prtdot", 0, 0, 0)
    swApp.ActivateDoc2 "Part1", False, longstatus
    Set Part = swApp.ActiveDoc
    Dim myModelView As SldWorks.ModelView
    Set myModelView = Part.ActiveView
    myModelView.FrameState = swWindowState_e.swWindowMaximized
    Part.SketchManager.InsertSketch True
    boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.03891024234798, 0.02968528649877, 3.646590412283E-04, False, 0, Nothing, 0)
    Part.ClearSelection2 True
    Dim vSkLines As Variant
    vSkLines = Part.SketchManager.CreateCornerRectangle(-0.05517876768764, 0.008130204900836, 0, -0.02399076855985, -0.0155939995639, 0)
    Part.ClearSelection2 True
    vSkLines = Part.SketchManager.CreateCornerRectangle(-0.003731897331531, 0.008130204900836, 0, 0.0285223581767, -0.02998846069981, 0)
    Part.ClearSelection2 True
    Dim skSegment As SldWorks.SketchSegment
    Set skSegment = Part.SketchManager.CreateCircle(0.053579, 0.013995, 0#, 0.06819, 0.018462, 0#)
    Part.ClearSelection2 True
    Part.SketchManager.InsertSketch True
    Part.ShowNamedView2 "*Trimetric", 8
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

    Dim myFeatMr As SldWorks.FeatureManager
    Set myFeatMr = Part.FeatureManager
  

    ' Create a blind surface extrude of 10 mm
    ' in two directions from the selected sketch
    ' in a direction normal to the selected sketch plane
    myFeatMr.FeatureExtruRefSurface2 False, False, False, 0, 0, 0.01, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, False, False, False, False
 

    Part.ClearSelection2 True
    Set selMgr = Part.SelectionManager
   

    ' Get Surface-Extrude1 data
    boolstatus = Part.Extension.SelectByID2("Surface-Extrude1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
   

    Set surfExtrudeFeat = selMgr.GetSelectedObject6(1, -1)
    Set surfExtrude = surfExtrudeFeat.GetDefinition
   

    surfExtrude.AccessSelections Part, Nothing
   

    Debug.Print surfExtrudeFeat.Name
    Debug.Print "  Depth:"
    Debug.Print "    Forward direction: " & surfExtrude.GetDepth(True)
    Debug.Print "    Reverse direction: " & surfExtrude.GetDepth(False)
    Debug.Print "  End condition as defined in swSurfaceExtendEndCond_e:"
    Debug.Print "    Forward direction: " & surfExtrude.GetEndCondition(True)
    Debug.Print "    Reverse direction: " & surfExtrude.GetEndCondition(False)
    Debug.Print "  Reverse offset enabled:"
    Debug.Print "    Forward direction? " & surfExtrude.GetReverseOffset(True)
    Debug.Print "    Reverse direction? " & surfExtrude.GetReverseOffset(False)
    Debug.Print "  Translate surface setting enabled:"
    Debug.Print "    Forward direction? " & surfExtrude.GetTranslateSurface(True)
    Debug.Print "    Reverse direction? " & surfExtrude.GetTranslateSurface(False)
    Debug.Print "  Surface extruded in both directions? " & surfExtrude.BothDirections
    Debug.Print "  Extrusion reversed? " & surfExtrude.ReverseDirection
   

    surfExtrude.ReleaseSelectionAccess

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 Extruded Reference Surface 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) 2016 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.