[iLogic / VBA ] Project Edges of a Part/Body on 3D Sketch using iLogic

[iLogic / VBA ] Project Edges of a Part/Body on 3D Sketch using iLogic

Luisfmts
Enthusiast Enthusiast
1,009 Views
4 Replies
Message 1 of 5

[iLogic / VBA ] Project Edges of a Part/Body on 3D Sketch using iLogic

Luisfmts
Enthusiast
Enthusiast

Hi all,

I have some doubts around Skecthes3D object; they are three things that I digged but i couldnt find out how to proceed:

 

[the first and maybe the more complicated]
I would like, within an assembly (assuming it has two or more parts as occurrences), create a 3D Sketch on the first part and project the geometry of a selected surfacebody (solid body) belonging on the second one.

 

[second]
I tried to change the default color of a projected 3D Sketch but it doenst work. It works perfectly when its a new 3D Sketch, but no success when the lines were projectted.

 

[third]
I tried to get the values of rangebox.X but if there is only lines inventor doenst reconize those geometries and return zero instead the max lenght/height.

 

I'd appreciate some ideias 😊

Accepted solutions (1)
1,010 Views
4 Replies
Replies (4)
Message 2 of 5

HideoYamada
Advisor
Advisor

Hello Luisfmts,

 


@Luisfmts wrote:

[the first and maybe the more complicated]
I would like, within an assembly (assuming it has two or more parts as occurrences), create a 3D Sketch on the first part and project the geometry of a selected surfacebody (solid body) belonging on the second one.

I tried this by myself (= manually done).

I created a assembly, placed two different parts, activated one part, created new 3d sketch in the activated part, and projected the edges in the other part to created 3d sketch.

I could do, but the projected lines were fixed and so they cannot follow the model changing at the other part.

Is this enough for you? Could you consider to use derived part?

 

[second]
I tried to change the default color of a projected 3D Sketch but it doenst work. It works perfectly when its a new 3D Sketch, but no success when the lines were projectted.

Where did you change the setting?

 

[third]
I tried to get the values of rangebox.X but if there is only lines inventor doenst reconize those geometries and return zero instead the max lenght/height.

PartComponentDefinition.RangeBox Property seems to only consider solids and surfaces.

So you will have to write code. Let's try!

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 5

Luisfmts
Enthusiast
Enthusiast

Hi @HideoYamada , thanks for your reply.

 

Normally I do it manually, but i would like to do it progamatically instead.

 It doesnt need to be adaptative at all.

 

For changing the the color of a 3D Sketch you can use the property accessed through the following: PartComponentDefinition.Sketch3d.Overridecolor = ThisApplication.TransientObjects.CreateColor( red, green blue ).

Unfortunatelly it doesnt work even if I set the override to "Nothing" before (trying to force it get back to default before given a new on).

 

Yeah, i think it would need to have a lot of MeasureTools.GetMinimumDistance and comparing to pick the greater value, just wondered it could be simpler 😅

 

 

 

0 Likes
Message 4 of 5

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 


@Luisfmts wrote:

Normally I do it manually, but i would like to do it progamatically instead.

 It doesnt need to be adaptative at all.


O.k., I've written the sample code in VBA and the model files for demo attached to this post.

Option Explicit


Sub test()
    Dim aDoc As AssemblyDocument
    Dim sourceOcc As ComponentOccurrence
    Dim destinationOcc As ComponentOccurrence

    Set aDoc = ThisApplication.ActiveDocument
    Set sourceOcc = aDoc.ComponentDefinition.Occurrences(1)
    Set destinationOcc = aDoc.ComponentDefinition.Occurrences(2)
    
    ' Prepare EdgeProxy collection
    Dim sourceDef As PartComponentDefinition
    Set sourceDef = sourceOcc.Definition
    Dim exFeature As ExtrudeFeature
    Set exFeature = sourceDef.Features.ExtrudeFeatures(1)
    Dim objCol As ObjectCollection
    Set objCol = ThisApplication.TransientObjects.CreateObjectCollection
    Dim f As Face
    Dim e As Edge
    For Each f In exFeature.Faces
        For Each e In f.Edges
            Dim pr As Object
            sourceOcc.CreateGeometryProxy e, pr
            objCol.Add pr
        Next e
    Next f
    
    ' Project EdgeProxies
    Dim destinationDef As PartComponentDefinition
    Set destinationDef = destinationOcc.Definition
    If destinationDef.Sketches3D.Count = 0 Then
        destinationDef.Sketches3D.Add
    End If
    Dim skt3d As Sketch3D
    Set skt3d = destinationDef.Sketches3D(1)
    Dim skt3dProxy As Sketch3DProxy
    destinationOcc.CreateGeometryProxy skt3d, skt3dProxy

    Dim ep As EdgeProxy
    For Each ep In objCol
        skt3dProxy.Include ep
    Next ep
End Sub

This code stored in Assembly1.Module1 also.

 

This code will project edges of the first occurrence's first extrude feature to the second occurrence's 3d sketch.

If the 3d sketch is not existing, it will be created.

 

I hope this code will help to resolve your first problem.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 5

Luisfmts
Enthusiast
Enthusiast

You nailed it! thanks @HideoYamada 👍

0 Likes