- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Model parameters in leader FormattedText attached to component via API
Anyone found a workaround for this yet?
Via the API, I'm unable to recreate Leader Text (attached to component), Edit Leader Text, insert Model Property from part. My understanding is that the XML structure for FormattedText holds for an assembly, but not a part.
See these threads:
Brandon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm revisiting this issue and still stumped.
I can manually create a leader that's linked to a parameter in a component, but that's 10+ clicks...
Or, via iLogic, I can create a leader that displays the current value of the parameter, but does not update when the value changes.
Can formattedtext be linked to a parameter? Or does it only display the value when the formattedtext is generated?
Brandon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Feb 2020, and I'm having the same issue.
I can create a 3DA leader in my .ipt file with model parameters inserted in the text,
but I cannot recreate the same leader using the API and VB.Net.
I can create a 3DA leader, but an error is thrown when updating the text to include a parameter xml tag.
System.ArgumentException: 'The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))'
FYI: I used ilogic to extract the parameter xml tag from an existing leader I wanted to duplicate.
Dim oDoc As PartDocument = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition Dim oAnns As ModelAnnotations = oDef.ModelAnnotations Dim oLeader As ModelLeaderNote = oAnns.ModelLeaderNotes.Item(1) Dim oText As String = oLeader.Definition.Text.FormattedText
InputBox("",,oText)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
To update my earlier post, here's the iLogic code that I got to work. It's clunky, and relies on the leader not being visible as it's coincident with visible geometry.
Please note this code applies to a drawing view only -- not a 3D annotation.
Try adding () to the end of:
Dim oText As String = oLeader.Definition.Text.FormattedText()
Here's the code for 2D drawings:
Sub Main() Dim oDrawing as DrawingDocument oDrawing = ThisDrawing.Document Dim oSheet As Sheet oSheet = oDrawing.ActiveSheet Dim oNotes As DrawingNotes oNotes = oSheet.DrawingNotes Dim oEdgeSegment As DrawingCurveSegment oEdgeSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select cabinet edge to attach dimension." & Chr(13) & " ESC to end.") Dim oEdge As DrawingCurve oEdge = oEdgeSegment.Parent
Dim oMinPoint As Point2d oMinPoint = oEdge.Evaluator2D.RangeBox.MinPoint Dim oMaxPoint As Point2d oMaxPoint = oEdge.Evaluator2D.RangeBox.MaxPoint Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oLeaderPoints As ObjectCollection oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection If oMinPoint.X <> oMaxPoint.X Then oLeaderPoints.Add(oTG.CreatePoint2d(oMinPoint.X+.75, oMinPoint.Y+.125)) 'horizontal edge Else oLeaderPoints.Add(oTG.CreatePoint2d(oMinPoint.X+.125, oMinPoint.Y+.125)) 'vertical edge End if Dim oGeometryIntent As GeometryIntent oGeometryIntent = oSheet.CreateGeometryIntent(oEdge) oLeaderPoints.Add(oGeometryIntent) Dim sParameterName As String sParameterName = "CABDEPTH" Dim oPartParameters As Parameters oPartParameters = oEdge.ModelGeometry.ContainingOccurrence.Definition.Parameters For i = 1 to oPartParameters.Count() If oPartParameters.Item(i).Name() = sParameterName Then oPartParameters.Item(i).CustomPropertyFormat.Precision() = 85518 'Sixteenths Fractional Precision' Else End If Next i Dim sIPropertySetName As String sIPropertySetName = "User Defined Properties" Dim sIPropertySet As String sIPropertySet = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" 'Inventor User Defined Properties' Dim sFormattedText As String sFormattedText = "<Property Document='model' PropertySet='" & sIPropertySetName & "' Property='" & sParameterName & "' FormatID='" & sIPropertySet & "'></Property> D" Dim oLeaderNote As LeaderNote oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, "") oLeaderNote.FormattedText = sFormattedText oLeaderNote.Leader.ArrowheadType() = 71948 'No arrowhead End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That's a step in the right direction for me (I think). An error is no longer thrown,
but the parameter value doesn't show up in the model. The 3DA leader text is blank.
There is a parameter tag in the leader's text editor, but the name of the parameter is displayed;
not the underlying value (e.g. <GasketFaceHt> instead of 6.550). The interesting bit is that
the correct parameter is in the recently used list of the editor as if the manual process had been
used to insert it.
Dim sIPropertySet As String = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
Dim sIPropertySetName As String = "User Defined PropDerties"
Dim sParameterName As String = "GasketFaceHt"
Dim annText As String = "<Property Document='model' PropertySet='" & sIPropertySetName & "' Property='" & sParameterName & "' FormatID='" & sIPropertySet & "'></Property>"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can you post the rest of the code?
There's a sequence (while illogical) that is required to get this to work. The formatted text is applied to the leader AFTER the leader is placed.
So, define the formatted text string. Then, place the leader. Then change the formatted text in that leader to the newly defined string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I define the leader properties, create a blank leader, fill in the text of the new leader.
fyi: There's some module level constants used in here (e.g. oPlanes, oTG, oPartDef, etc.).
Private Sub AnnotateTaperedGroove()
Dim annName As String = "GasketFaceNote"
Dim finishedFace As Face = GetFace("GasketFaceSurface")
Dim pointOnFace As Point = finishedFace.PointOnFace
Dim annPlane As WorkPlane = oPlanes.Item("XZ Plane")
Dim annTextPoint As Point = oTG.CreatePoint(pointOnFace.X - 1,, pointOnFace.Z - 1)
Dim sIPropertySet As String = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
Dim sIPropertySetName As String = "User Defined Properties"
Dim sParameterName As String = "GasketFaceHt"
Dim annText As String = "<Property Document='model' PropertySet='" & sIPropertySetName & "' Property='" & sParameterName & "' FormatID='" & sIPropertySet & "'></Property>"
Call AnnotateLeaderNote(annName, annText, finishedFace, pointOnFace, annPlane, annTextPoint)
End Sub
Private Sub AnnotateLeaderNote(ByVal annName As String, ByVal annText As String,
ByRef surfaceGeometry As Object, ByRef surfaceIntent As Object,
ByRef annPlane As Object, ByRef annPoint As Point)
Dim annIntent As GeometryIntent =
oPartDef.CreateGeometryIntent(surfaceGeometry, surfaceIntent)
Dim annLeaderPoints As ObjectCollection =
oApp.TransientObjects.CreateObjectCollection()
annLeaderPoints.Add(annPoint)
annLeaderPoints.Add(annIntent)
Dim annPlaneDef As AnnotationPlaneDefinition =
oAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(annPlane)
Dim annDefinition As ModelLeaderNoteDefinition =
oAnnotations.ModelLeaderNotes.CreateDefinition(annLeaderPoints, "", annPlaneDef)
Dim annLeaderNote As ModelLeaderNote = oAnnotations.ModelLeaderNotes.Add(annDefinition)
annLeaderNote.Definition.Text.FormattedText = annText
NameLastAnnotation(annName)
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What happens when you use a message box to display the value of annText?
I haven't used model based annotations, so my rule was built around 2D drawing views. My best guess is that your rule isn't pulling the property value because there's a disconnect between the leader and the referenced model. The rule looks like it should work, so I'm stumped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It's something about inserting model parameters.
The 3DA leader works as expected with normal text and other iproperty fields.
The concatenated string output from the executable as requested.
<Property Document='model' PropertySet='User Defined Properties' Property='GasketFaceHt' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'></Property>
Creation date works.
<Property Document='model' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='4'>CREATION DATE</Property>
Author works.
<Property Document='model' FormatID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}' PropertyID='4'>AUTHOR</Property>
Area works.
<PhysicalProperty PhysicalPropertyID='72450' Precision='0'>AREA</PhysicalProperty>