Create Imported Solid Body Example (VBA)
This example shows how to create an imported solid body in the shape
of a pyramid.
'-----------------------------------------------
'
' Preconditions: Part
document is open.
'
' Postconditions: A pyramid-shaped, imported, solid body
is
' created.
'
'------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swPart As
SldWorks.PartDoc
Dim
swBody As
SldWorks.body2
Dim
nPt() As
Double
Dim
vPt As
Variant
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swPart = swModel
Set
swBody = swPart.CreateNewBody
'
Front
ReDim
nPt(8)
nPt(0)
= 0#: nPt(1)
= 0#: nPt(2)
= 1#
nPt(3)
= -1#: nPt(4)
= -1#: nPt(5)
= 0#
nPt(6)
= 1#: nPt(7)
= -1#: nPt(8)
= 0#
vPt
= nPt
bRet
= swBody.CreatePlanarTrimSurfaceDLL((vPt),
Empty): Debug.Assert bRet
'
Left
ReDim
nPt(8)
nPt(0)
= 0#: nPt(1)
= 0#: nPt(2)
= 1#
nPt(3)
= -1#: nPt(4)
= -1#: nPt(5)
= 0#
nPt(6)
= -1#: nPt(7)
= 1#: nPt(8)
= 0#
vPt
= nPt
bRet
= swBody.CreatePlanarTrimSurfaceDLL((vPt),
Empty): Debug.Assert bRet
'
Back
ReDim
nPt(8)
nPt(0)
= 0#: nPt(1)
= 0#: nPt(2)
= 1#
nPt(3)
= -1#: nPt(4)
= 1#: nPt(5)
= 0#
nPt(6)
= 1#: nPt(7)
= 1#: nPt(8)
= 0#
vPt
= nPt
bRet
= swBody.CreatePlanarTrimSurfaceDLL((vPt),
Empty): Debug.Assert bRet
'
Right
ReDim
nPt(8)
nPt(0)
= 0#: nPt(1)
= 0#: nPt(2)
= 1#
nPt(3)
= 1#: nPt(4)
= 1#: nPt(5)
= 0#
nPt(6)
= 1#: nPt(7)
= -1#: nPt(8)
= 0#
vPt
= nPt
bRet
= swBody.CreatePlanarTrimSurfaceDLL((vPt),
Empty): Debug.Assert bRet
'
Bottom
ReDim
nPt(11)
nPt(0)
= -1#: nPt(1)
= -1#: nPt(2)
= 0#
nPt(3)
= -1#: nPt(4)
= 1#: nPt(5)
= 0#
nPt(6)
= 1#: nPt(7)
= 1#: nPt(8)
= 0#
nPt(9)
= 1#: nPt(10)
= -1#: nPt(11)
= 0#
vPt
= nPt
bRet
= swBody.CreatePlanarTrimSurfaceDLL((vPt),
Empty): Debug.Assert bRet
bRet
= swBody.CreateBodyFromSurfaces:
Debug.Assert bRet
End Sub
'---------------------------------