Project geometry to sketch from one part to another in an assembly

Project geometry to sketch from one part to another in an assembly

erichter
Advocate Advocate
2,217 Views
6 Replies
Message 1 of 7

Project geometry to sketch from one part to another in an assembly

erichter
Advocate
Advocate

Hi. I'm having trouble with projecting geometry to a part sketch from the geometry belonging to a different part within an assembly. Essentially, I am trying to mimic "Project Geometry" to create a cross-part reference in a sketch.

 

The code below works if the entity selected on line 16 belongs to the same part, but not if it belongs to a different part. I haven't found any info on this in the forums.

 

Can someone help me with this, please?

 

 

Dim oAssemDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAssemDef As AssemblyComponentDefinition = oAssemDoc.ComponentDefinition

Dim oFace As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select face on part for new sketch") 'Selected face on part document

Dim oOcc As ComponentOccurrence = oFace.ContainingOccurrence
oOcc.Edit

Dim oPartDoc As PartDocument = ThisApplication.ActiveEditDocument 'Active part document within an open assembly
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition

If TypeOf oFace Is FaceProxy Then oFace = oFace.NativeObject 'If part is within an assembly
Dim oSketch As PlanarSketch = oPartDef.Sketches.Add(oFace)
oSketch.Edit

Dim oEntity As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select entity to project") 'Selected entity from another part within assembly
If Right(TypeName(oEntity), 5) = "Proxy" Then oEntity = oEntity.NativeObject 'If part is within an assembly

oSketch.AddByProjectingEntity(oEntity) 'Error if entity is from a different part

 

 

0 Likes
Accepted solutions (2)
2,218 Views
6 Replies
Replies (6)
Message 2 of 7

florian_wenzel
Advocate
Advocate
Accepted solution

Hi,

 

not exactly know what you want, but i think:

What you need to do, is in New Part create a Sketch and a SketchProxy,

and then after this, you will able to use  "oSketchProxy.AddByProjectingEntity(oEntity)"

In my Opinion in Assembly Enviroment, The Method AddByProjectingEntity works only with SketchProxy.

 

 

 Dim oSketchProxy As PlanarSketchProxy
        Call oOcc.CreateGeometryProxy(oSketch, oSketchProxy)

 

 

Inventor 2022 Help | PlanarSketchProxy.AddByProjectingEntity Method | Autodesk

 

"In an assembly context (where this method is called on a PlanarSketchProxy object) this method that projects an entity from one part into a sketch in another part. The valid input in this case includes the various 2d sketch proxy objects, the various 3d sketch proxy objects, EdgeProxy, VertexProxy, WorkAxisProxy, and WorkPointProxy objects. WorkPlaneProxy objects that are perpendicular to the sketch are also valid."

 

 

Message 3 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi guys.  This looks fairly similar to the other example I just created in a parallel thread.  In that thread, the originator wanted to transfer an extrude/cut from one part type component in an assembly to another part type component.  I created some test geometry in an assembly and did just that with an iLogic code.  Part of that process was projecting the hole's geometry from the one component in assembly space, down into the other components part space.  Maybe reviewing that code will help you understand the process better.  The main difference is that it is projecting Edge geometry instead of sketch geometry, but the process should be mostly the same.

Here is the link to that other post:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/how-can-i-extrude-a-cut-from-one-par... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

erichter
Advocate
Advocate

Thanks, guys. This works great! I did try creating the EntityProxy before, but I was still missing the SketchProxy. I think I was confused because I was able to work with the sketch without the proxy, but it makes sense that it would need a proxy in this situation as this projection can only be done within the assembly environment. Here's my working code snippet.

 

Dim oAssemDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAssemDef As AssemblyComponentDefinition = oAssemDoc.ComponentDefinition

Dim oFace As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select face on part for new sketch") 'Selected face on part document
If oFace Is Nothing Then Exit Sub

Dim oOcc As ComponentOccurrence = oFace.ContainingOccurrence
oOcc.Edit

Dim oPartDoc As PartDocument = ThisApplication.ActiveEditDocument 'Active part document within an open assembly
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition

Dim oSketch As PlanarSketch = oPartDef.Sketches.Add(oFace.NativeObject)
oSketch.Edit

Dim oEntity As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select entity to project") 'Selected entity from another part within assembly
If oEntity Is Nothing Then Exit Sub
Dim oEntityOcc As ComponentOccurrence = oEntity.ContainingOccurrence
oEntityOcc.CreateGeometryProxy(oEntity, oEntityProxy)
oOcc.CreateGeometryProxy(oSketch, oSketchProxy)
oSketchProxy.AddByProjectingEntity(oEntityProxy)

 

Message 5 of 7

ssyXENBT
Contributor
Contributor

Hey, 

but why the Line always lose ref?

ssyXENBT_0-1664462743252.png

 

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @ssyXENBT.  When projecting geometry between components within an assembly, this creates a dependency.  The sketch within the one part, that had geometry projected into it, is dependent on the geometry of the other component, within the context of the assembly.  If certain things happen to the source component in the assembly, or the geometry within the source component (where the geometry was projected from), that will effect the projected geometry.  If the source component is deleted, that will invalidate the geometry that was projected from it.  If the sketch within the source component is deleted or otherwise changed in some way that results in errors, that will likely also invalidate the geometry that was projected from it.  There are several other things that can cause this too.  It is one of the disadvantages of using this process that you must keep in mind.   If you do not need the projected geometry to remain linked to the source component's geometry, you can break that link, but if you break that link, you may have to constrain that geometry another way, to keep it from moving.  When I break the link of projected geometry, I often just ground (set Fixed constraints on it) the effected geometry afterwards.  If you need the link to remain, so it will remain accurate, then you will have to avoid changing the source component, or the source sketch in those ways, after you have projected that geometry.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

ssyXENBT
Contributor
Contributor
Hi, makes sense and works well! Thank you.
could you maybe take a look on my recent post? (New sketch from assembly down to derived part in Part)
https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/add-new-sketch-in-derivedpartcompone...
Thank you! 🙂
0 Likes