Create Planar Surface Feature Example (VB.NET)
This example shows how to create a planar surface feature.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified document template exists.
' 2. Open an Immediate window.
'
' Postconditions:
' 1. Creates a new model document with a boss extrusion.
' 2. Creates Surface-Radiate1 and Surface-Plane1 in the FeatureManager
' design tree.
' 3. Inspect the Immediate window.
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
Dim Part As ModelDoc2
Dim swSelMgr As SelectionMgr
Dim swSelData As SelectData
Dim swRadiate As SurfaceRadiateFeatureData
Dim swPlane As SurfacePlanarFeatureData
Dim swFeat As Feature
Dim swEnt As Entity
Dim vRadEnt As Object
Dim vBoundEnt As Object
Dim swRadDirEnt As Entity
Dim i As Integer
Dim boolStatus As Boolean
Sub main()
Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2015\templates\Part.prtdot", 0, 0, 0)
Part = swApp.ActiveDoc
boolStatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.0448901407839529, 0.0279954694016864, 0.00466820674117181, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
boolStatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstToRectEntity, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False)
boolStatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
Dim vSkLines As Object
vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0555749908365768, 0.0329075527136081, 0, 0.0478203409524033, -0.0317145296545045, 0)
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
Part.ShowNamedView2("*Trimetric", 8)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
boolStatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)
Dim myFeature As Object
myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.00254, 0.00254, False, False, False, False, 0.0174532925199433, 0.0174532925199433, False, False, False, False, True, True, True, 0, 0, False)
boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0447337592343047, 0.0328467250718631, 0.00258132540182032, False, 2, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0556265649287866, 0.0156695101210289, 0.0025672149453726, True, 2, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0140113588298618, -0.0317157034173761, 0.00254079743683633, True, 2, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "EDGE", 0.047780958393389, -0.00542256709667299, 0.00256078163948814, True, 2, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "FACE", 0.0478203409524554, -0.00305747564971171, 0.000546558985774936, True, 1, Nothing, 0)
Part.InsertRadiateSurface(0.0254, False, False)
swSelMgr = Part.SelectionManager
swSelData = swSelMgr.CreateSelectData
boolStatus = Part.Extension.SelectByID2("Surface-Radiate1", "REFSURFACE", 0, 0, 0, False, 0, Nothing, 0)
swFeat = swSelMgr.GetSelectedObject6(1, -1)
swRadiate = swFeat.GetDefinition
' Get radiate surface data
Debug.Print("File = " & Part.GetPathName)
Debug.Print(" " & swFeat.Name)
Debug.Print(" Distance: " & swRadiate.Distance * 1000.0# & " mm")
Debug.Print(" Flip? " & swRadiate.Flip)
Debug.Print(" Propagate to tangent faces? " & swRadiate.PropagateToTangentFaces)
' Roll back to get direction reference and radiated edges
boolStatus = swRadiate.AccessSelections(Part, Nothing)
swRadDirEnt = swRadiate.DirectionReference
Part.ClearSelection2(True)
vRadEnt = swRadiate.RadiatedEntities
Debug.Print("Type of radiated entities as defined in swSelectType_e:")
For i = 0 To swRadiate.GetRadiatedEntitiesCount - 1
swEnt = vRadEnt(i)
Debug.Print(" Radiated entity(" & i & ") = " & swEnt.GetType)
Next i
swRadiate.ReleaseSelectionAccess()
Part.ClearSelection2(True)
boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0150796523155918, 0.0330635737250304, 0.0277193529692568, False, 1, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0556924155575302, -0.00146678127401856, 0.0280574247206573, True, 1, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.00737846281163002, -0.0317262656324715, 0.0279565971788429, True, 1, Nothing, 0)
boolStatus = Part.Extension.SelectByID2("", "EDGE", 0.047950275020753, 0.00971418585908168, 0.0278100659315328, True, 1, Nothing, 0)
boolStatus = Part.InsertPlanarRefSurface()
Part.ClearSelection2(True)
boolStatus = Part.Extension.SelectByID2("Surface-Plane1", "REFSURFACE", 0, 0, 0, False, 0, Nothing, 0)
' Roll back to get the planar surface bounding edges
swFeat = swSelMgr.GetSelectedObject6(1, -1)
swPlane = swFeat.GetDefinition
boolStatus = swPlane.AccessSelections(Part, Nothing)
vBoundEnt = swPlane.BoundingEntities
Debug.Print("Types of planar surface bounding entities as defined in swSelectType_e:")
For i = 0 To swPlane.GetBoundingEntitiesCount - 1
swEnt = vBoundEnt(i)
Debug.Print(" Bounding entity(" & i & ") = " & swEnt.GetType)
Next i
swPlane.ReleaseSelectionAccess()
End Sub
''' <summary>
''' The SldWorks swApp variable is pre-assigned for you.
''' </summary>
Public swApp As SldWorks
End Class