We are currently trying to use model annotations to call out information in our assemblies. We came up with the idea of making a sketch in the assembly that has sketchpoints we put in for the leaders so that when we replace components in the assembly to make the next one, we don't have to worry about the annotation disappearing. Especially when the assembly is just shrinking or growing.
I wrote code to make it so that a user can click on all the sketchpoints in the sketch and the leader annotations get added, but they currently do not get constrained to those points so as soon as we go to the next assembly and grow/shrink the assembly and sketch, the annotations don't move.
Is there any way to make it so when the annotations are getting added, they also constrain to the point?
I've tried to do this in the past with placing UCS as well and was not able to get them to constrain, so I'm hoping it is possible and I just haven't found the way yet.
This is my current code for adding the annotations based on the sketchpoints selected. It adds them all to be on the XY plane.
Sub AddCallouts()
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 WorkPlane
Set oFace = oDef.WorkPlanes.Item(3)
Dim oAnnoPlaneDef As AnnotationPlaneDefinition
Set oAnnoPlaneDef = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace) 'this line was crashing Inventor
Dim oLeaderPoints As ObjectCollection
Set oLeaderPoints = InvApp.TransientObjects.CreateObjectCollection
Dim selectedSketchPoints As Object
Set selectedSketchPoints = Doc.SelectSet
If selectedSketchPoints.count = 0 Then
MsgBox ("No sketch points are selected.")
Exit Sub
End If
Dim numX As Integer
numX = 1
'For Each oPoint In oDef.Sketches.Item(1).SketchPoints
For Each oPoint In selectedSketchPoints
oLeaderPoints.Clear
Dim wp As Point
Set wp = oPoint.Geometry3d
Call oLeaderPoints.Add(oTG.CreatePoint(oPoint.Geometry3d.x + 5, oPoint.Geometry3d.Y + 5, oPoint.Geometry3d.Z))
Call oLeaderPoints.Add(wp)
Dim oLeaderIntent As GeometryIntent
Set oLeaderIntent = oDef.CreateGeometryIntent(oFace, wp)
Call oLeaderPoints.Add(oLeaderIntent)
Dim oLeaderDef As ModelLeaderNoteDefinition
Set oLeaderDef = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, numX & "/DXXX", oAnnoPlaneDef)
Dim oLeader As ModelLeaderNote
Set oLeader = oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)
numX = numX + 1
Next
End Sub
We are currently trying to use model annotations to call out information in our assemblies. We came up with the idea of making a sketch in the assembly that has sketchpoints we put in for the leaders so that when we replace components in the assembly to make the next one, we don't have to worry about the annotation disappearing. Especially when the assembly is just shrinking or growing.
I wrote code to make it so that a user can click on all the sketchpoints in the sketch and the leader annotations get added, but they currently do not get constrained to those points so as soon as we go to the next assembly and grow/shrink the assembly and sketch, the annotations don't move.
Is there any way to make it so when the annotations are getting added, they also constrain to the point?
I've tried to do this in the past with placing UCS as well and was not able to get them to constrain, so I'm hoping it is possible and I just haven't found the way yet.
This is my current code for adding the annotations based on the sketchpoints selected. It adds them all to be on the XY plane.
Sub AddCallouts()
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 WorkPlane
Set oFace = oDef.WorkPlanes.Item(3)
Dim oAnnoPlaneDef As AnnotationPlaneDefinition
Set oAnnoPlaneDef = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace) 'this line was crashing Inventor
Dim oLeaderPoints As ObjectCollection
Set oLeaderPoints = InvApp.TransientObjects.CreateObjectCollection
Dim selectedSketchPoints As Object
Set selectedSketchPoints = Doc.SelectSet
If selectedSketchPoints.count = 0 Then
MsgBox ("No sketch points are selected.")
Exit Sub
End If
Dim numX As Integer
numX = 1
'For Each oPoint In oDef.Sketches.Item(1).SketchPoints
For Each oPoint In selectedSketchPoints
oLeaderPoints.Clear
Dim wp As Point
Set wp = oPoint.Geometry3d
Call oLeaderPoints.Add(oTG.CreatePoint(oPoint.Geometry3d.x + 5, oPoint.Geometry3d.Y + 5, oPoint.Geometry3d.Z))
Call oLeaderPoints.Add(wp)
Dim oLeaderIntent As GeometryIntent
Set oLeaderIntent = oDef.CreateGeometryIntent(oFace, wp)
Call oLeaderPoints.Add(oLeaderIntent)
Dim oLeaderDef As ModelLeaderNoteDefinition
Set oLeaderDef = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, numX & "/DXXX", oAnnoPlaneDef)
Dim oLeader As ModelLeaderNote
Set oLeader = oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)
numX = numX + 1
Next
End Sub
When I add the leader manually vs when I add it with code, I get different Definitions for the leader.
They are getting added to the same sketchpoint in the sketch. When I make it manually I also make sure to put it on the same XY plane.
However, constraints only show up as being possible in the manually added leader.
Should I be adding the coded one differently or is it just not possible to access the constraints when adding them with code?
When I add the leader manually vs when I add it with code, I get different Definitions for the leader.
They are getting added to the same sketchpoint in the sketch. When I make it manually I also make sure to put it on the same XY plane.
However, constraints only show up as being possible in the manually added leader.
Should I be adding the coded one differently or is it just not possible to access the constraints when adding them with code?
Can't find what you're looking for? Ask the community or share your knowledge.