Project workplane from an assembly to a sketch in a part

Project workplane from an assembly to a sketch in a part

jiri.paur
Participant Participant
590 Views
3 Replies
Message 1 of 4

Project workplane from an assembly to a sketch in a part

jiri.paur
Participant
Participant

Hello,

I am tryring to project a workplane geometry from an assembly to a plannar sketch i a part. 

Anybody who can help me?

 

Private Sub projectGeometryWP(colWP As Collection, coloOcc As Collection)

    Dim oWorkPlane As WorkPlane
    Dim oOcc As ComponentOccurrence
    
    For Each oOcc In coloOcc
        Call oOcc.Edit
        
        Dim oSketch As PlanarSketch
        On Error Resume Next
        Set oSketch = oOcc.Definition.Sketches.Item("Stender")
        
        If Err.Number <> 0 Then
            Set oSketch = oOcc.Definition.Sketches.Add(oOcc.Definition.WorkPlanes.Item(1))
        End If
        On Error GoTo 0

        Call oSketch.Edit
    
        For Each oWorkPlane In colWP
            
            Call oSketch.AddByProjectingEntity(oWorkPlane)
       
        Next oWorkPlane
        
        Call oSketch.ExitEdit
        Call oOcc.ExitEdit(kExitToTop)
    Next oOcc
End Sub

image.png

0 Likes
Accepted solutions (1)
591 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @jiri.paur 

What you need to do is to create a proxy object for the skecth. If the workplanes aren't in the top level assembly you need to create proxies for them as well.

Here's a very simple example on how to project a workplane from the main assembly into a sketch named "Sketch 1" in a partoccurrence named "Part1:1" in the assembly.

 

 

'Get the active assembly
Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument

'Get a part occurrence in the assembly
Dim oOcc As ComponentOccurrence
Set oOcc = oAsm.ComponentDefinition.Occurrences.ItemByName("Part1:1")

'Get the sketch in the part
Dim oSketch As PlanarSketch
Set oSketch = oOcc.Definition.Sketches("Sketch 1")

'Create a proxy for the sketch
Dim oSketchProx As PlanarSketchProxy
Call oOcc.CreateGeometryProxy(oSketch, oSketchProx)

'Get the plane in the assembly
Dim oPlane As WorkPlane
Set oPlane = oAsm.ComponentDefinition.WorkPlanes.Item("XY Plane")

'Project the plane into the sketch
Call oSketchProx.AddByProjectingEntity(oPlane)

'Update the assembly
oAsm.Update

 

 

Message 3 of 4

jiri.paur
Participant
Participant
Thank you Jhoel! This is exactly what I needed (proxy of the sketch) 🙂
I believe, there is no way to keep associativity of the projected geometry for this case (Assembly -> Part), right?
0 Likes
Message 4 of 4

JhoelForshav
Mentor
Mentor

Hi @jiri.paur 

I'm glad to hear it helped! 🙂 And yes, unfortunately in this case adaptivity isn't possible. You'll get the same unadaptive result if you project the plane manually as well 😕

0 Likes