We use cookies to operate this website, improve its usability and track visits. Please note that by using this site you are consenting to the use of cookies.
Learn More |

I would like to draw sketch lines onto the same plane (or face) as the bend-lines and the bounding-box of a flat-pattern.

Does anybody know a way to select the plane (or face) by the API and draw sketch lines on it.


In fact I am asking two questions here:

- How to get a handle to the plane/face of the flat-pattern through the API.

- How to draw a sketch on that plane through the API


I have been searching through the API documents and on this forum but have not been able to find any helpful information yet.

All help is appreciated.




Categories: API∕Macros

Last comment By: Dennis Beeren   Thu, 14 Sep 2017 06:35:42 GMT
Re: API: How to sketch a line on the flat-pattern

Hi Dennis,


Try this code.helps to draw a line normal to the plane.


Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim longstatus As Long

Dim swRefPlane As SldWorks.RefPlane

Dim swfeat As SldWorks.Feature

Dim swsketch As SldWorks.Sketch

Dim swSketchPlane As Object

Dim swOriginPoint As SldWorks.MathPoint

Dim swRefPlaneTransform As SldWorks.MathTransform

Dim swMathUtility As SldWorks.MathUtility

Dim aPointData(2) As Double

Dim vPointData As Variant

Dim swOriginPointOnRefPlane As SldWorks.MathPoint

Dim swNormalVector As SldWorks.MathVector

Dim swNormalVectorRefPlane As SldWorks.MathVector

Dim aVectorData(2) As Double

Dim vVectorData  As Variant

Dim dScaleFactor As Double

Dim strRefPlaneName As String

Dim aRefPlanes(6) As String

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swfeat = swModel.FeatureByName("Bend-Lines2")

Set swsketch = swfeat.GetSpecificFeature2

Set swSketchPlane = swsketch.GetReferenceEntity(longstatus)

Set swRefPlane = swSketchPlane

Set swRefPlaneTransform = swRefPlane.Transform

        ' Create a math point that represents the reference plane's origin

        ' in the canonical position in world coordinates; this is

        ' (0.0, 0.0, 0.0)

        ' Create array data

        aPointData(0) = 0#

        aPointData(1) = 0#

        aPointData(2) = 0#

        ' Turn into a Variant

        vPointData = aPointData

        ' Create a math point

           Set swMathUtility = swApp.GetMathUtility

        Set swOriginPoint = swMathUtility.CreatePoint(vPointData)

        ' Transform the reference plane origin from its canonical

        ' position to its actual position

        Set swOriginPointOnRefPlane = swOriginPoint.MultiplyTransform(swRefPlaneTransform)

        ' Get point data

        vPointData = swOriginPointOnRefPlane.ArrayData

        ' Create a math vector that represents the reference plane's normal in

        ' the canonical orientation in world coordinates; this is [0.0, 0.0, 1.0]

        ' Create array data

        aVectorData(0) = 0#

        aVectorData(1) = 0#

        aVectorData(2) = 1#

        ' Turn into a Variant

        vVectorData = aVectorData

        ' Create a math vector

        Set swNormalVector = swMathUtility.CreateVector(vVectorData)

         ' Now transform the reference plane normal from its canonical

        ' orientation to its actual orientation

        Set swNormalVectorRefPlane = swNormalVector.MultiplyTransform(swRefPlaneTransform)

        ' Get vector data

        vVectorData = swNormalVectorRefPlane.ArrayData

        ' Visualize

        ' As the reference plane normal is normalized, it may be bit out of

        ' proportion; this factor is arbitrary

        dScaleFactor = 0.1

        ' Insert a 3D sketch

        swModel.Insert3DSketch2 True

        ' Create a line from the reference plane origin in the direction

        ' of the reference plan normal

        swModel.CreateLine2 vPointData(0), vPointData(1), vPointData(2), vPointData(0) + dScaleFactor * vVectorData(0), vPointData(1) + dScaleFactor * vVectorData(1), vPointData(2) + dScaleFactor * vVectorData(2)

        ' Close the sketch

        swModel.Insert3DSketch2 True

        ' The sketch is still selected

        Set swFeature = swModel.SelectionManager.GetSelectedObject6(1, 0)

         ' Rename it

        swFeature.Name = strRefPlaneName & "-Normal"

        ' Clear selection for the next pass

        swModel.ClearSelection2 True

End Sub



By: Manikandan Babu  Tue, 22 Aug 2017 13:08:53 GMT
Re: API: How to sketch a line on the flat-pattern

Thanks Manikandan!

Thanks to your code sample I was able to find the end points and draw lines between them on the flat-pattern.

I can continue with my code now.

By: Dennis Beeren  Thu, 14 Sep 2017 06:35:42 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.