xml text for part parameter in a leader note

xml text for part parameter in a leader note

BromanSillito
Advocate Advocate
1,575 Views
12 Replies
Message 1 of 13

xml text for part parameter in a leader note

BromanSillito
Advocate
Advocate

I am using vb.net to create a drawing of a weldment. I want to create a leader note that includes a parameter from the "preparation state" of the the weldment for one of the specific components in that weldment. I am able to create the leader note just fine but when I try to include the parameter in the FormattedText I get this error:

 

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

I have created the text manually and then used a function that pulls the XML code out of the note so that I can put it in my program. Here is the text I want (3.75 is the parameter from the weldment):

 

DRILL Ø3.75 HOLE

AND BEVEL 37.5°

 

This is the XML code I pulled out using a function:

 

"DRILL Ø <Parameter Resolved='True' ComponentIdentifier='I:\Sillito\Inventor\TwoTest\Pipe\Repad1.ipt' Name='d23' Precision='2'>3.75</Parameter> HOLE<Br/>AND BEVEL 37.5°"

 

 

 

Here is the code I am using to create the note (not all of it, just the relevant section):

 

Dim sText As String
        sText = "DRILL Ø <Parameter Resolved='True' ComponentIdentifier='I:\Sillito\Inventor\TwoTest\Pipe\Repad1.ipt' Name='d23' Precision='2'>3.75</Parameter>  HOLE<Br/>AND BEVEL 37.5°"
        Dim oLeaderNote As LeaderNote
        oLeaderNote = sheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)

 

Can anyone tell me why I'm getting this error and how to resolve it?

0 Likes
Accepted solutions (1)
1,576 Views
12 Replies
Replies (12)
Message 2 of 13

wayne.brill
Collaborator
Collaborator

Hi,

 

Please try first creating the LeaderNote with an empty string and then use the FormattedText property to set the value of the Formatted Text. Below is a VBA example that is working for me.

 

Also this DevBlog post could be of interest:

http://adndevblog.typepad.com/manufacturing/2012/07/create-leader-note-with-the-value-of-user-or-mod...

 

 

Public Sub LeaderNote_Test()
    
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    Dim oLeaderPoints As ObjectCollection
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(30, 30))
    Call oLeaderPoints.Add(oTG.CreatePoint2d(0, 0))
    
    Dim sText As String
    'sText = "DRILL Ø <Parameter Resolved='True' ComponentIdentifier='I:\Sillito\Inventor\TwoTest\P?ipe\Repad1.ipt' Name='d23' Precision='2'>3.75</Parameter>  HOLE<Br/>AND BEVEL 37.5°"
    sText = "DRILL Ø <Parameter Resolved='True' ComponentIdentifier='C:\Users\brillw\Documents\Inventor\WB_2-18-16\Part_WB_2-24-16.ipt' Name='d0' Precision='2'>3.75</Parameter>  HOLE<Br/>AND BEVEL 37.5°"

    Dim oLeaderNote As LeaderNote
    
    'This fails:
    'Set oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    
    'This works:
    Set oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, "")
    oLeaderNote.FormattedText = sText
End Sub

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 13

BromanSillito
Advocate
Advocate

Wayne, thank you for the response. I am using Visual Studio, VB.net. I tried copying your code directly and it creates a leader but when it reaches the line of code that adds the formatted text, it fails, which is what was happening before as well. For some reason it seems like it doesn't like the XML I'm inputting or it can't recognize it. Is there a setting I need to change or a reference I need to add? I already have "Imports Inventor", but is there something else perhaps? 

0 Likes
Message 4 of 13

wayne.brill
Collaborator
Collaborator

Hi,

 

I added my code to this SDK sample and it was able to create the leader with the formatted text.

C:\Users\Public\Documents\Autodesk\Inventor 2016\SDK\DeveloperTools\Samples\VB.NET\Standalone Applications\Inventor\SimpleExe

 

If you upload a simple Visual Studio project and the Inventor files you are using I will try to get it working. (let me know if you want to send it to me privately)

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 5 of 13

BromanSillito
Advocate
Advocate

I tried to run the "developertools.msi" installation file to get access to these folders but it gives me an error when I do and says that I don't have Visual Studio installed.  I have Visual Studio 2015 express installed on my computer. Do I need anything else?

0 Likes
Message 6 of 13

BromanSillito
Advocate
Advocate
I have the reference to Autodesk.Inventor.Interop.dll in my program and all other Inventor functionality is working. However, I have not installed the developertools.msi.
0 Likes
Message 7 of 13

BromanSillito
Advocate
Advocate

Wayne,

 

Here is a simplified version of the code I am using to create a leader note with XML code. I am creating it in a weldment, so if you create a weldment and then create a drawing from that, that will simulate what I am trying to do. I have also attached the part I am trying to get the parameter from (parameter d23). Please let me know what you think, thanks,

 

Broman

0 Likes
Message 8 of 13

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi Broman,

 

Thanks for providing the ipt and the details about the drawing view. I am able to recreate the behavior.  A ticket was logged with Inventor Engineering.

 

In my tests if a view on the sheet is referencing an assembly then setting the FormattedText with a parameter fails. If you try your code with a sheet that only has a view that references the ipt then I believe your code will work. (it does in my tests).

 

In the UI if you add a parameter for the leader note, you need to select whch referenced file the parameter is coming from. It seems like there is something missing in the API that would do something similar. I am not finding a work around for this behavior with FormattedText with a referenced assembly.

 

Thanks,

Wayne

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 9 of 13

christoph_stumpf
Contributor
Contributor

Are there now an solution available? I'am working with inventor 2018, but it don't work ???

0 Likes
Message 10 of 13

Anonymous
Not applicable
' This code is for a Part Drawing --> works fine
' The user selects the view, then the dimension, then runs the macro
'
Public Sub Gauge_Dimension_PartDwg()

  Dim oDoc As DrawingDocument
  Set oDoc = ThisApplication.ActiveDocument
  Dim oSSet As SelectSet
  Set oSSet = oDoc.SelectSet
  
  If oSSet.Count <> 2 Then
    MsgBox ("Please select first the drawing view then the dimension (using the CTRL key)")
    Exit Sub
  End If
  
  'reference to the selected view
  Dim oView As DrawingView
  On Error GoTo item1error
  Set oView = oSSet.Item(1)
  'get the part name from the view
  Dim oPartName As String
  oPartName = oView.ReferencedDocumentDescriptor.FullDocumentName
  GoTo item2set

item1error:
  MsgBox ("The first item selected is not a drawing view.")
  Exit Sub
  
item2set:
  'reference to the selected dimension
  Dim oDim As LinearGeneralDimension
  'On Error GoTo item2error
  Set oDim = oSSet.Item(2)
  'refrence to the DimensionText object
  Dim oDimensionText As DimensionText
  Set oDimensionText = oDim.Text
  GoTo do_gauge_dim

item2error:
  MsgBox ("The second item selected is not a dimension.")
  Exit Sub
  
do_gauge_dim:
  'reference to the style manager
  Dim oStylesMgr As DrawingStylesManager
  Set oStylesMgr = oDoc.StylesManager
  
  'get the reference to the target dimension style (by name)
  Dim oNewStyle As DimensionStyle
  Set oNewStyle = oStylesMgr.DimensionStyles.Item("Webb Decimal - 3 Place")
  oDim.Style = oNewStyle
  
  'change text
  oDimensionText.FormattedText = "<Parameter Resolved='True' ComponentIdentifier='" & oPartName & "' Name='GAUGE' Precision='0'></Parameter>" & " GA (<DimensionValue/>)"
  Beep

End Sub

' This is a function used by Gauge_Dimension_AssyDwg to get the
' selected part in the drawing view
Public Function GetSelectedItems(nodes As BrowserNodesEnumerator) As String
    Dim node As BrowserNode
    For Each node In nodes
        If node.Selected Then
            GetSelectedItems = GetSelectedItems + node.BrowserNodeDefinition.Label + vbCrLf
        End If
        
        GetSelectedItems = GetSelectedItems _
            + GetSelectedItems(node.BrowserNodes)
    Next

End Function

' This code is for an Assembly Drawing --> fails on the FormattedText
' The user selects the part in the Model Browser Nodes, then the dimension, then runs the macro
'
Public Sub Gauge_Dimension_AssyDwg()

  Dim oDoc As DrawingDocument
  Set oDoc = ThisApplication.ActiveDocument
  Dim oSSet As SelectSet
  Set oSSet = oDoc.SelectSet
  
  If oSSet.Count <> 2 Then
    MsgBox ("Please select first the drawing view then the dimension (using the CTRL key)")
    Exit Sub
  End If
  
  Dim bp As BrowserPane
  Set bp = oDoc.BrowserPanes("DlHierarchy")
    
  Dim oPartName As String
  oPartName = GetSelectedItems(bp.TopNode.BrowserNodes)
  If oPartName Like "######:##*" Then
     oPartName = Left(oPartName, 6)
  ElseIf oPartName Like "######:#*" Then
     oPartName = Left(oPartName, 6)
  ElseIf oPartName Like "######*" Then
     oPartName = Left(oPartName, 6)
  End If
  Dim cntr As Integer
  Dim cntr2 As Integer
  Dim strRefDocName As String
  Dim strRefDocFolder As String
  Dim strRefDocFullName As String
  cntr = 1
  While cntr <= oDoc.ReferencedDocuments.Count
    cntr2 = 1
    While cntr2 <= oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Count
      strRefDocName = oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2).DisplayName
      If strRefDocName Like (oPartName & "*") Then
        strRefDocFullName = oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2).FullDocumentName
      End If
      cntr2 = cntr2 + 1
    Wend
    cntr = cntr + 1
  Wend
  GoTo item2set

item1error:
  MsgBox ("The first item selected is not a drawing view.")
  Exit Sub
  
item2set:
  'reference to the selected dimension
  Dim oDim As LinearGeneralDimension
  'On Error GoTo item2error
  Set oDim = oSSet.Item(2)
  'refrence to the DimensionText object
  Dim oDimensionText As DimensionText
  Set oDimensionText = oDim.Text
  Dim ftext1 As String
  ftext1 = oDimensionText.FormattedText
  GoTo do_gauge_dim

item2error:
  MsgBox ("The second item selected is not a dimension.")
  Exit Sub
  
do_gauge_dim:
  'reference to the style manager
  Dim oStylesMgr As DrawingStylesManager
  Set oStylesMgr = oDoc.StylesManager
  
  'get the reference to the target dimension style (by name)
  Dim oNewStyle As DimensionStyle
  Set oNewStyle = oStylesMgr.DimensionStyles.Item("Webb Decimal - 3 Place")
  oDim.Style = oNewStyle
  
  oDimensionText.FormattedText = "<Parameter Resolved='True' ComponentIdentifier='" & strRefDocFullName & "' Name='GAUGE' Precision='0'></Parameter>" & " GA (<DimensionValue/>)"
  Beep

End Sub

I hope someone can help also.  I am having the same problem.  I made one macro to change the parameter for a linear dimension in a part drawing to add the GAUGE value.  This worked fine.  However, making another macro to work in an assembly fails for the FormattedText line.

 

0 Likes
Message 11 of 13

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Your "strRefDocFullName" has no value because of "Else" Missing or is the wrong reference:

Your referenced was to the part or sub assembly (item1) in the Active Document.

 

like this:

strRefDocFullName=oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2).FullFileName

means >> oDoc = Drawing

oDoc.ReferencedDocuments.Item(cntr) = Assembly

oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2) = Subassembly or part

 

but more critical was the else statement missing

 

 

#################################################
While cntr <= oDoc.ReferencedDocuments.Count
    cntr2 = 1
    
    While cntr2 <= oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Count
      strRefDocName = oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2).DisplayName
      
      If strRefDocName Like (oPartName & "*") Then

        strRefDocFullName = oDoc.ReferencedDocuments.Item(cntr).FullDocumentName 'oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2).FullFileName '.FullDocumentName
        
        Else
        
        strRefDocFullName = oDoc.ReferencedDocuments.Item(cntr).FullDocumentName 'oDoc.ReferencedDocuments.Item(cntr).ReferencedDocuments.Item(cntr2).FullFileName '.FullDocumentName
      
      End If
      cntr2 = cntr2 + 1
    Wend
    cntr = cntr + 1
  Wend
  GoTo item2set
#################################

Think this will solve your problem!

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 13

Anonymous
Not applicable

1) Yes, I am aware I currently don't have an ELSE statement.

2) The statement "If strRefDocName Like (oPartName & "*") Then" is setup to find a match

3) When the match is found, then set strRefDocFullName to the part document full name

4) When I run this, I do get the value I want for strRefDocFullName (even though I don't have an ELSE)

5) The problem is that the FormattedText statement fails.  I see other posts with users having the same problem.

6) It appears that a couple of Autodesk's AU instructors don't even have an answer.

7) At this time, I think this is a problem with Inventor's API, but still hoping someone has a solution.

8) The FormattedText line even fails when I do the following:

a) Edit the dimension manually, adding the GAUGE parameter

b) add code to save this FormattedText value to a string

c) do a FormattedText statement using this string (essentially replacing the current text with the same text)

d) and this fails also

 

Thanks,

 

JCKCAD

 

 

0 Likes
Message 13 of 13

bradeneuropeArthur
Mentor
Mentor

For me the code works now because of the else statement.

You should put at least an on error step into the code if the requirements are not found!


strRefDocFullName is sometimes empty. That is why it does not work to my opinion. At least at my side.

What is the difference between your side and mine?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes