Ataching leader note to sketched symbol in drawing

Ataching leader note to sketched symbol in drawing

omartin
Advocate Advocate
500 Views
7 Replies
Message 1 of 8

Ataching leader note to sketched symbol in drawing

omartin
Advocate
Advocate

Trying to attach a leader note to a sketched symbol, but I get errors when adding geometry intent (commenting out the line adding the intent will add the leader but it is not attached)

 

If I were just to add a leader manually to the sketchedsymbol and move around the symbol, this leader is attached as expected.

 

from this manual leader I inspected the properties on the leaderNode with the attachedEntity property and tried to copy the values when creating the geomtryIntent, but did not work.

 

I tried a bunch if different things but here is the simplest version I would think should of worked but I get an, "Expecting object to be local" error.

other times I would get a, "Method 'Add' of object 'LeaderNotes' failed"

 

I am just working in the vb editor right now on IV2023

 

I got some clues form topics such as below: where they talk about hidden leaders to attach to, but cant seem to find out how where to find these nodes to attach to:

Insert Drawing Sketched Symbol Behind DrawingView 

Leader note/node from Sketched Symbol 

 

In my sketchedSymbols defintion I moved the point where I am trying to attach to to 0,0 in its sketch space

omartin_1-1759332298133.png

 

 

any ideas greatly appreciated

 

Public Sub AddLeaderNotetestxx()
    Dim trg As TransientGeometry
    Set trg = ThisApplication.TransientGeometry
    
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.activeDocument
    
    Dim sk As SketchedSymbol
   
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet

    Set sk = oActiveSheet.SketchedSymbols(1).leader.Parent

    Dim oMidPoint As Point2d
    Set oMidPoint = sk.Position

    Dim oLeaderPoints As ObjectCollection
  
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oGeometryIntent As GeometryIntent
    Call oLeaderPoints.Add(trg.CreatePoint2d(oMidPoint.x + 5, oMidPoint.Y + 5))
    Call oLeaderPoints.Add(trg.CreatePoint2d(sk.Position.x, sk.Position.Y + 1.1))
    
    Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(sk.leader.Parent, trg.CreatePoint2d(sk.Position.x, sk.Position.Y + 1.1))
    
    Call oLeaderPoints.Add(oGeometryIntent)

    Dim sText As String
    sText = "API Leader Note"

    Dim oLeaderNote As LeaderNote
    Set oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    
End Sub

 

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
501 Views
7 Replies
Replies (7)
Message 2 of 8

Curtis_Waguespack
Consultant
Consultant

@omartin, I'm not completely sure I understand the request, but here is an example that adds leaders to an existing symbol. 

Hope that helps, Curtis

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSegment As DrawingCurveSegment
oSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select an edge")

If oSegment is nothing then exit sub

Dim oSymbol As SketchedSymbol

Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

oSymbol = oActiveSheet.SketchedSymbols(1)

Dim oMidPoint As Point2d = oSymbol.Position

Dim SelectPt As Point2d = oSegment.Parent.MidPoint

Dim oLeaderPoints As ObjectCollection
oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

Dim oGeometryIntent As GeometryIntent
oLeaderPoints.Add(oSymbol.Position)

oGeometryIntent = oActiveSheet.CreateGeometryIntent(oSegment.Parent)

Call oLeaderPoints.Add(oGeometryIntent)


'oSymbol.LeaderClipping = True
'oSymbol.LeaderVisible = True

Try
	oSymbol.Leader.AddLeader(oLeaderPoints)
Catch 
	'if the symbol already has a leader
	oSymbol.Leader.RootNode.AddLeader(oLeaderPoints)
End Try

 

 EESignature

0 Likes
Message 3 of 8

omartin
Advocate
Advocate

Hey @Curtis_Waguespack thanks for the reply!!

I was actually referring to adding a separate LeaderTextNote, that is attached to the sketchedSymbol (so when the symbol moves the note moves)

 

in the pic, the sketchedSymbol is the 25 with the line in the middle, the "im attached" LeaderNote, is a note I placed manually to try and see how it was attached,  for testing purposes. 

 

so the drawing intent is somehow attached to the sketchedSymbol instead of a drawingCurve.

Hope that is a better explanation. I attached a drawing as well

 

omartin_0-1759339525051.png

 

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @omartin.  I would suggest just specifying the SketchedSymbol object as the first input for the CreateGeometryIntent method, instead of SketchedSymbol.Leader.Parent.  Then, for the second input into that method, which needs to be a point on that object's geometry, we may have some options.  If the SketchedSymbol had a visible leader, then we could likely use the 'position' of one of the leader nodes.  But if it does not have a leader, and maybe not even attached to anything, then we may have to fall back to getting the actual geometry included within the symbol.  To do that, we would have to step down into its SketchedSymbolDefinition, then the DrawingSketch associated with that definition.  Then find the piece of geometry (for example a SketchLine), then get the StartPoint or EndPoint of that Line, then the Point2D associated with that SketchPoint.  As long as it is 'real' visible geometry.  Then, I'm guessing that we would likely have to translate that point from sketch space to sheet space, which could be done with the DrawingSketch.SketchToSheetSpace method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

omartin
Advocate
Advocate

Right, let me give  it a shot with the sketch definitions and DrawingSketch.SketchToSheetSpace

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 6 of 8

omartin
Advocate
Advocate

Hey @WCrihfield  thanks for replying!

Im still getting the expecting object to be local error.

 

in the skecthedSymbol's sketch definition space, the point I'm connecting to is @0,0

when I use the  DrawingSketch.SketchToSheetSpace () I still get 0,0 returned

But even If I hard code the coordinates (by taking them from the note that I manually added) it still does not work

 

I also tried to add a leader, and use the root node but no luck...

omartin_0-1759344448289.png

according to the docs, it lists sketchedEntites as valid input for the createIntent function but not sketchedSymbols.

I also tried using the sketchline, with varioous points but a no go.

 

Maybe it is just not possible or a bug ...But Why is works manaully 😕

 

 

Public Sub AddLeaderNotetestxx()
    Dim trg As TransientGeometry
    Set trg = ThisApplication.TransientGeometry
    
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.activeDocument
    
    Dim sk As SketchedSymbol
    Dim ds As DrawingSketch
   
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet

    Set sk = oActiveSheet.SketchedSymbols(1)
    Set ds = sk.Definition.Sketch
    
    Dim sl As SketchLine
    Set sl = ds.SketchLines(1)
    
    Dim oMidPoint As Point2d
    Set oMidPoint = ds.SketchToSheetSpace(sl.Geometry.StartPoint)

    Dim oLeaderPoints As ObjectCollection
  
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oGeometryIntent As GeometryIntent
    
    Call oLeaderPoints.Add(trg.CreatePoint2d(oMidPoint.x + 5, oMidPoint.Y + 5))
    Call oLeaderPoints.Add(trg.CreatePoint2d(sk.Position.x, sk.Position.Y + 1.1))
    Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(sk, sk.leader.RootNode.Position)
'also tried
' Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(sk, omidpoint)
' Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(sk, trg.CreatePoint2d(sk.Position.x, sk.Position.Y + 1.1) (this is the start point of the line on the sheetpace)
    
    Call oLeaderPoints.Add(oGeometryIntent)

    Dim sText As String
    sText = "API Leader Note"
    

    Dim oLeaderNote As LeaderNote
    Set oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    
End Sub

 

 

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @omartin.  I was just making educated guesses at what might work above, without actually trying it myself at the time, due to lots of things going on.  I thought I remembered this being possible, but its very possible I was wrong.  I just got to a slow point at work, so I tried out several things myself, but couldn't make it 'attach' to the sketched symbol either.  When inspecting the GeometryIntent of the manually placed LeaderNote that is properly attached, the GeometryIntnent.IntentType = kPoint2dIntent, but then the GeometryIntnent.Geometry property also had a value of type "SketchedSymbol", which allows it access to the properties of the SketchedSymbol.  So, the user interface tools allow us to make this connection / attachment, but it is all handled automatically behind the scenes, and we don't know how they are able to make it happen.

I do not understand how to replicate that by Inventor API code in Inventor 2024 though, because it seems like we've tried about every possible combination.  Since a DrawingDimension is one of the types of objects that we can specify as the first input for creating a GeometryIntent, it would seem like providing a SketchedSymbol would also work, due to certain similarities.  LeaderNotes use a DimensionStyle to dictate their style, just like a DrawingDimension, then the SketchedSymbol uses a LeaderStyle, which the DimensionStyle also uses, so I made the assumption that they may be compatible.  I have seen several cases where other types of objects would work for Inventor API methods, other than the ones mentioned in their 'help' documentation, so I was hoping this might be another case of that type of situation.  Maybe they just haven't exposed that specific functionality to us users yet, I don't know.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

omartin
Advocate
Advocate

Hey @WCrihfield, no worries thanks for taking the time to look at it. You are probably right the userInteraction must have some background stuff happening not available pragmatically (or some other steps may need to happen).

 

Through out the years both you and Curtis's input were a big help, I'm still digging up your old posts!

 

I am going to have to accept defeat on this one ...

 

For Posterity:

  • I found some other clues, when placed manually, the geometryIntent's parent is a leaderNode object but when using the createIntent function it is a sheet object (could have something to do with the not local error)
  • If you were to place the leader using the command manager and sendkeys, so your leader lands on the sketched geometry, It seems to work. Problem is a reliable way to get the screen coordinates

 

Was my reply Helpful ? send a Kudos or accept as solution