Project sketch point from root assembly

Project sketch point from root assembly

nedeljko.sovljanski
Advocate Advocate
676 Views
3 Replies
Message 1 of 4

Project sketch point from root assembly

nedeljko.sovljanski
Advocate
Advocate

I have structure such as:

nedeljkosovljanski_0-1626965394417.png

I want to project SketchPoint from Sketch 1 to Sketch 32. This is quote from Inventor API 2022 doc for  PlanarSketch.AddByProjectingEntity method: "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."

So, input is proxy object, but how to get proxy object from root assembly, it is not occurrence and there is no CreateGeometryProxy method?

 

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

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @nedeljko.sovljanski 

In my experience, things are a bit more complicated in general when we're working with geometry in assemblies. A lot of functions mimic the functionality from part environment but under the hood they look different. I think this is one of those cases too. Notice that if you project a point like this manually through the UI, you don't get an adaptive sketch referencing the point. Instead you get a sketchpoint in the correct position but grounded and non-adaptive. So I think what we need to do is mimic that result. Something like this seems like the way to go:

'Get top level assembly document and definition
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
'Get the sub-assembly
Dim subAsm As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName("100252:1")
'Create a proxy for the targetsketch
Dim oSketchProx As PlanarSketchProxy = Nothing
subAsm.CreateGeometryProxy(subAsm.Definition.Sketches("Sketch 32"), oSketchProx)
'Get the location of the point we want to project in 3D-space
Dim oPoint3D As Point = oAsmCompDef.Sketches("Sketch 1").SketchPoints(1).Geometry3d
'Transform the point to sketch space for our target skecth
Dim oPoint2D As Point2d = oSketchProx.ModelToSketchSpace(oPoint3D)
'Add Point to the skecth
Dim oProjPoint As SketchPoint = oSketchProx.SketchPoints.Add(oPoint2D)
'Ground the Point in sketch
oSketchProx.GeometricConstraints.AddGround(oProjPoint)
'Update Assembly
oAsm.Update
Message 3 of 4

nedeljko.sovljanski
Advocate
Advocate

Hi Jhoel,

 

I made similar solution with copy whole sketch but it is also non adaptive. As I can see, on assembly level, all projected entities will not keep reference and will not be automatically updated. I believe there will be no solution for my problem so I will accepted your code as solution for other members.

 

Thanks!

0 Likes
Message 4 of 4

robertast
Collaborator
Collaborator

@JhoelForshav  How fun to see you back in the forum. Human problems will be solved faster. 😉

Thank you