Insert MidSurface in Component (VB.NET)
This example shows how to insert a midsurface feature in a component.
'---------------------------------------------------------------
' Preconditions: Assembly
is open in SolidWorks and must contain at least
' one
component. The component must contain a solid body.
'
' Postconditions: A midsurface feature is inserted in
the component.
'----------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
Dim
swModel As ModelDoc2
Dim
swExt As ModelDocExtension
Dim
swSelMgr As SelectionMgr
Dim
swComp As Component2
Dim
swFeat As Feature
Dim
swView As View
Dim
filePath As String
Dim
macroPath As String
Dim
swAssem As AssemblyDoc
Dim
swPart As PartDoc
Dim
swDraw As DrawingDoc
Dim
boolStatus As Boolean
Dim
featMgr As FeatureManager
Public
Sub main()
swModel
= swApp.ActiveDoc
swExt
= swModel.Extension
swSelMgr
= swModel.SelectionManager
featMgr
= swModel.FeatureManager
swAssem
= swModel
Dim
vComponents As Object
vComponents
= swAssem.GetComponents(True)
swComp
= vComponents(0)
Dim
vBodies As Object
vBodies
= swComp.GetBodies2(swBodyType_e.swSolidBody)
Dim
pBody As Body2
pBody
= vBodies(0)
Dim
midSurf As MidSurface3
midSurf
= featMgr.InsertMidSurface(pBody,
swComp.GetModelDoc2, 0.5, True)
Debug.Print("Face
count: " & midSurf.GetFaceCount)
End
Sub
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class