Adding Model Annotations (ModelLeaderNotes) works in Part, but fails in Assembly

Adding Model Annotations (ModelLeaderNotes) works in Part, but fails in Assembly

josh.nieman
Advocate Advocate
1,305 Views
5 Replies
Message 1 of 6

Adding Model Annotations (ModelLeaderNotes) works in Part, but fails in Assembly

josh.nieman
Advocate
Advocate

I've used the code samples shown here: http://adndevblog.typepad.com/manufacturing/2018/03/adding-modelfeaturecontrolframe-in-partdocument-...

 

and gotten them to work in the part environment.  I'm trying to now adapt this code to work in an assembly, and running into confusing errors.  Well... confusing to me (I'm pretty new to this)


I get the following error at the line in red below:
System.Runtime.InteropServices.COMException: 'The remote procedure call failed. (Exception from HRESULT: 0x800706BE)'

 

What is causing this?  I can't seem to find the root cause.

 

 

Private Sub TEST_Click(sender As Object, e As EventArgs) Handles TEST.Click
Dim Doc As Document
Dim oDef As AssemblyComponentDefinition
Dim oTG As TransientGeometry
Dim dViewRepMgr As RepresentationsManager
Dim dWeldView As DesignViewRepresentations

InvApp = Marshal.GetActiveObject("Inventor.Application")
Doc = InvApp.ActiveDocument
oDef = Doc.ComponentDefinition

oTG = InvApp.TransientGeometry

dViewRepMgr = oDef.RepresentationsManager
dWeldView = dViewRepMgr.DesignViewRepresentations

Dim oFace As Face
oFace = InvApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face to attach leader")

Dim oAnnoPlaneDef As AnnotationPlaneDefinition
oAnnoPlaneDef = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace)

Dim oLeaderPoints As ObjectCollection
oLeaderPoints = InvApp.TransientObjects.CreateObjectCollection

oLeaderPoints.Add(oTG.CreatePoint(5, 10, 0))

Dim oLeaderIntent As GeometryIntent
oLeaderIntent = oDef.CreateGeometryIntent(oFace)

oLeaderPoints.Add(oLeaderIntent)

Dim oLeaderDef As ModelLeaderNoteDefinition
oLeaderDef = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, "Finally it works", oAnnoPlaneDef)

Dim oLeader As ModelLeaderNote
oLeader = oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)

End Sub

0 Likes
Accepted solutions (1)
1,306 Views
5 Replies
Replies (5)
Message 2 of 6

clutsa
Collaborator
Collaborator

It doesn't look like assembly documents support ModelFeatureControlFrames yet. Can you do what you're trying to do manually? When I try I don't see the Geometric Annotation 

 

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 6

josh.nieman
Advocate
Advocate

That's correct.  I think assemblies SHOULD support FCFs but that's a discussion for another day 🙂

Right now I'm trying to add a LEADER TEXT object (ModelLeaderNotes object) 

 

But the method should be quite similar to how you add a FCF to a part model, I would think.  So I was starting with those samples, as I haven't found samples of anyone adding Model Annotations in an assembly yet.  I'd welcome any of those, as well.

0 Likes
Message 4 of 6

clutsa
Collaborator
Collaborator
Accepted solution

try oFace.Geometry on the line that's crashing.

This is what I did in VBA and it works (after several crashes)

Private Sub TEST()
Dim Doc As Document
Dim oDef As AssemblyComponentDefinition
Dim oTG As TransientGeometry
Dim dViewRepMgr As RepresentationsManager
Dim dWeldView As DesignViewRepresentations

Set InvApp = ThisApplication 'Marshal.GetActiveObject("Inventor.Application")
Set Doc = InvApp.ActiveDocument
Set oDef = Doc.ComponentDefinition

Set oTG = InvApp.TransientGeometry

Set dViewRepMgr = oDef.RepresentationsManager
Set dWeldView = dViewRepMgr.DesignViewRepresentations

Dim oFace As Face
Set oFace = InvApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face to attach leader")

Dim oAnnoPlaneDef As AnnotationPlaneDefinition
Set oAnnoPlaneDef = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace.Geometry) 'this line was crashing Inventor

'Set oAnnoPlaneDef = oDef.ModelAnnotations.Item(1).Definition.AnnotationPlaneDefinition 'used the planeDef from an existing annotation for test

Dim oLeaderPoints As ObjectCollection
Set oLeaderPoints = InvApp.TransientObjects.CreateObjectCollection

Call oLeaderPoints.Add(oTG.CreatePoint(5, 10, 0))

Dim oLeaderIntent As GeometryIntent
Set oLeaderIntent = oDef.CreateGeometryIntent(oFace)

Call oLeaderPoints.Add(oLeaderIntent)

Dim oLeaderDef As ModelLeaderNoteDefinition
Set oLeaderDef = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, "Finally it works", oAnnoPlaneDef)

Dim oLeader As ModelLeaderNote
Set oLeader = oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)

End Sub
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 5 of 6

josh.nieman
Advocate
Advocate

That absolutely did it...  I appreciate your solution.


I'm not sure why it was necessary in this assembly, but not in a part file, but I'm perfectly happy simply remembering to try the properties of these objects in the future, should I run into something similar.  


Thanks!

0 Likes
Message 6 of 6

clutsa
Collaborator
Collaborator

My best guess is in the part the oFace is a "Face" but in the assy oFace is actually a "FaceProxy" and they aren't being handled the same... That's totally me guessing though. 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates