Hello.
I am trying to read "Source" and other parameters through "Leader Text" via iLogic code, but I am unable to figure out how to get them. If anybody has an idea on how to access them, it would be a great help! Thank you.
Best regards,
Rene Repina
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @ReneRepina. We do not have a super easy way of retrieving those individual pieces of information. The LeaderNote object has a FormattedText property that will usually contain some regular text, but will also usually contain XML tags, which are used to 'format' the data. It can be pretty complicated to read and edit that formatted text at times. Here is a simple little iLogic rule you can play around with. When you run this rule, it will ask you to pick a LeaderNote type object on your drawing sheet. Then it will retrieve the contents of its formatted text and show it to you, using an InputBox, instead of a MsgBox or MessageBox.Show, so that its contents will be selectable, and copyable.
Dim oLNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select a leader note to inspect.")
If oLNote Is Nothing Then Return
Dim oEditedFText As String = InputBox("Here is the LeaderNote.FormattedText:", "LeaderNote.FormattedText", oLNote.FormattedText)
oLNote.FormattedText = oEditedFText
Here is the official online help page explaining some of the stuff you may see inside of these formatted text, in various different situations.
Wesley Crihfield
(Not an Autodesk Employee)
Oh, and by the way...in the picture you posted, there does not seem to be any special contents added into the regular text box area yet. If you want to add some 'linked' data into your main textbox area, once you set all those drop-down boxes where you want them, then you must click that little button on the far right of them which looks like a cursive letter X, and a down arrow. When you click that button, it will drop that specified block of data into the main textbox area as a single selectable linked block. You can usually have other text on either side of that linked block, but not always. For instance, when creating a 'Prompted Entry', no other text is allowed in the TextBox except that linked block that it inserts. Once one (or more) of those linked blocks are present, the FormattedText starts getting a lot more complicated and interesting.
Wesley Crihfield
(Not an Autodesk Employee)
Hello @WCrihfield .
Basically what we want to achieve:
To have a "Leader Text", which is attached to some specific "model" (its properties are now available to select in the textbox), we will have some "manually" written text in it (for example "Motor"), with no parametric fields, BUT in iLogic, we want to get a reference of attached model document object via this "Leader Text" (because we can then read all the properties and do some other iLogic code behind the scenes.
So if we check above example, we have "Leader Text" attached to model "VLT-189881", with manual written text "leader note" and we want to directly access this model via iLogic (we do not want to burden users to parametrically add model filename to "FormattedText", so we can read it in code after).
Is this possible?
For example, if we run code on drawing, we can get its "model" referenced document object. Is this also possible via attached "Leader Text" or it is not that simple?
Best regards,
Rene Repina
If I am understanding correctly, then yes, that is possible...sort of. If the LeaderNote's FormattedText does not contain any 'linked' stuff, then there will not be a reference within that to source the 'model' from. However, we may be able to check if LeaderNote.Leader.HasRootNode (a Boolean), and if so, we may be able to use LeaderNote.Leader.RootNode.AttachedEntity to get a reference to the GeometryIntent object that specifies how/what it is attached to. Then that GeometryIntent can sometimes be inspected a few steps further to get a reference to a DrawingCurve. And from there we can access the DrawingView (which has a document reference), and can often get the actual 'model geometry' (for example an Edge object). Then once we have something like an Edge (we would have to check what type of 'model geometry' we've got), we can usually step back up the ladder to the owning ComponentDefinition, then the Document. It's a complicated path at times for sure.
Wesley Crihfield
(Not an Autodesk Employee)
Here is a basic example of that complicated stuff I just mentioned. It is very narrow in its capability right now though, because it will only work if several things work out the right way. The leader note must be attached to something, and it must be a DrawingCurve, and that curve must represent an Edge in the model. All that stuff can be expanded upon to make it much more robust.
Dim oLNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select a leader note to inspect.")
If oLNote Is Nothing Then Return
Dim oLeader As Inventor.Leader = oLNote.Leader
If oLeader.HasRootNode Then
Dim oRNode As LeaderNode = oLeader.RootNode
Dim oNodes As LeaderNodesEnumerator = oLeader.AllNodes
For Each oNode As LeaderNode In oNodes
If oNode.AttachedEntity Is Nothing Then Continue For
Dim oGI As GeometryIntent = oNode.AttachedEntity
Dim oGeom As Object = Nothing : Try : oGeom = oGI.Geometry : Catch : End Try
If oGeom Is Nothing Then Continue For
MsgBox("TypeName(oGeom) = " & TypeName(oGeom),,"")
If TypeOf oGeom Is DrawingCurve Then
Dim oDC As DrawingCurve = oGeom
Dim oDView As DrawingView = oDC.Parent
Dim oDViewDoc As Document = oDView.ReferencedDocumentDescriptor.ReferencedDocument
MsgBox("View Model Doc = " & oDViewDoc.FullDocumentName,,"")
Dim oMGeom As Object = oDC.ModelGeometry
If TypeOf oMGeom Is Edge Then
Dim oEdge As Edge = oMGeom
Dim oNoteDoc As Document = oEdge.Parent.ComponentDefinition.Document
MsgBox("Note Model Doc = " & oNoteDoc.FullDocumentName, , "")
ElseIf TypeOf oMGeom Is Face Then
Dim oFace As Face = oMGeom
Dim oNoteDoc As Document = oFace.Parent.ComponentDefinition.Document
MsgBox("Note Model Doc = " & oNoteDoc.FullDocumentName, , "")
End If
ElseIf TypeOf oGeom Is SketchEntity Then
Dim oSE As SketchEntity = oGeom
Dim oSketch As Sketch = oSE.Parent
Dim oSketchParent As Object = oSketch.Parent
MsgBox("TypeName(oSketchParent) = " & TypeName(oSketchParent),,"")
End If
Next 'oNode
End If
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Uh, nice @WCrihfield , really well done to get this! Thank you so much for such troublesome and complex, yet working solution!
We are going to try to tweak a little and try to make it work as we want from your example.
An quick side question:
In your code, there is "Face" code block, how can you select a "Face" on drawing, I only manage to select "Edges"?
P.S.:
It would be really nice to have something like "LeaderNote.ReferencedDocument", huh?
Hi @ReneRepina. If the model in the view has some exterior cylindrical/spherical (or otherwise rounded) faces, then it is possible for there to be lines and/or curves shown in the view that represent 'profiles' rather than edges, and profiles represent the outer limits of faces. For example, a cylinder viewed from the side, instead of from the round, end will have two straight lines on each side, both representing the same exterior cylindrical face. Yes, the LeaderNote.ReferencedDocument would be nice. For many years now folks have wanted a quick & simple way to determine what DrawingView things like DrawingDimensions, Centermarks, Centerlines, and other types of drawing annotations belong to, but unfortunately, they all belong to the Sheet, instead of to a specific DrawingView. So several different workaround routines have been devised to accomplish tasks like that. The GeometryIntent route is likely the most complicated of those routes. Another route involved suppressing & unsuppressing DrawingViews, and figuring out which dimensions remained (or were removed) from the sheet when that happens. Another route involved capturing a 'location' on the sheet associate with the annotation, then calculating the bounding box of the DrawingView(s), then checking if that annotation location is within a specific DrawingView's bounds. There may be other too. The point is that there is no direct property on most of these objects to make it simple or easy.
Wesley Crihfield
(Not an Autodesk Employee)
Hello @WCrihfield .
Ah! Thank you for the explanation.
"LeaderNote.ReferencedDocuments" would save us so much trouble, but I guess other users do not need this.
Well, I have to say that your "GeometryIntent" route is exacly what we need, so we will stick with it and thank you for that!
Thank you for your help and have a nice weekend!
Can't find what you're looking for? Ask the community or share your knowledge.