Hide Table of Contents

Get Body Outline Example (VBA)

This example shows how to get the outline of a face on a solid body. This example also creates and inserts a 3D sketch of that outline.

 

'--------------------------------------

'

' Preconditions: Part document containing at

'                least body is open.

'

' Postconditions: A 3D of the outline of the

'                body is created.

'

'--------------------------------------

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swPart As SldWorks.PartDoc

Dim swModel As SldWorks.ModelDoc2

Dim swMathVector As SldWorks.MathVector

Dim swMathUtility As SldWorks.MathUtility

Dim swModeler As SldWorks.Modeler

Dim swBody As Body2

Dim dirVar As Variant

Dim bVar As Variant

Dim crvOut As Variant

Dim topol As Variant

Dim outline As Variant

Dim sEva As Variant

Dim eEva As Variant

Dim dirArr(0 To 2) As Double

Dim s As Double

Dim e As Double

Dim nCt As Long

Dim i As Long

Dim isClosed As Boolean

Dim isPer As Boolean

 

Sub main()

 

Set swApp = Application.SldWorks

Set swPart = swApp.ActiveDoc

Set swModel = swPart

 

'Get the bodies in this part

bVar = swPart.GetBodies2(swSolidBody, False)

 

Set swModeler = swApp.GetModeler

Set swMathUtility = swApp.GetMathUtility

 

dirArr(0) = 0#

dirArr(1) = 0#

dirArr(2) = 1#

dirVar = dirArr

 

'Create a MathVector

Set swMathVector = swMathUtility.CreateVector(dirVar)

 

'Copy the bodies in the part

Set bVar(0) = bVar(0).Copy

 

'Get the number of curves in the body outlines

nCt = swModeler.GetBodyOutline((bVar), swMathVector, 0.000001, crvOut, topol, outline)

'Open a 3D sketch in the part document

swPart.Insert3DSketch

' Using the end conditions of the curves, create a 2D sketch of each curve

For i = 0 To nCt - 1

    crvOut(i).GetEndParams s, e, isClosed, isPer

    sEva = crvOut(i).Evaluate(s)

    eEva = crvOut(i).Evaluate(e)

    swModel.CreateLine2 sEva(0), sEva(1), sEva(2), eEva(0), eEva(1), eEva(2)

Next i

 

'Insert the sketches

swModel.InsertSketch2 True

 

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:   Get Body Outline 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) 2010 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.