Project perpendicular origin planes into sketch

<?xml encoding=”UTF-8″>By Adam Nagy

Projecting entities into a sketch is really easy through the API.
E.g. projecting the origin planes which are perpendicular to the sketch can be done like this in VBA:

Public Sub ProjectPerpendicularOriginPlanes()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
If Not TypeOf doc Is PartDocument Then
Call MsgBox("You need to be inside a part document")
Exit Sub
End If
Dim ao As PlanarSketch
Set ao = ThisApplication.ActiveEditObject
If Not TypeOf ao Is PlanarSketch Then
Call MsgBox("You need to be inside a sketch")
Exit Sub
End If
Dim pd As PartDocument
Set pd = doc
Dim cd As PartComponentDefinition
Set cd = pd.ComponentDefinition
Dim sk As PlanarSketch
Set sk = ao
' The origin planes are the first 3
' in the WorkPlanes collection
Dim i As Integer
For i = 1 To 3
Dim wp As WorkPlane
Set wp = cd.WorkPlanes(i)
' If the WorkPlane was already added
' then AddByProjectingEntity would throw
' an error.
' To avoid that we can do error handling:
On Error Resume Next
If wp.Plane.IsPerpendicularTo(sk.PlanarEntityGeometry) Then
' Checking if the workplane is perpendicular might
' be an overkill because if not, then the below
' function would throw an error.
' But I think it's nicer if we check :)
Call sk.AddByProjectingEntity(wp)
End If
On Error GoTo 0
Next i
End Sub

 


Comments

One response to “Project perpendicular origin planes into sketch”

  1. Good post Adam. How can I project sketch from iPart member to another part and using this projection for adaptive cut out.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading