Get attributes values from Sketched Symbol

Get attributes values from Sketched Symbol

martinhoos
Advocate Advocate
667 Views
7 Replies
Message 1 of 8

Get attributes values from Sketched Symbol

martinhoos
Advocate
Advocate

Hi all,

i found a code that gives me back the result of "Index Nummer" - the code was written by Curtis Waguespack.

 

The question is: How can i get the highest value of the "Index Nummer"?  The syntax of the field is:  a00, a01, a02, a03 .... a99

 

The code shouldt look on all sheets.

 

 

Dim oDoc  As Document
oDoc = ThisApplication.ActiveDocument

'find the symbol by name
For Each oSymbol In oDoc.ActiveSheet.SketchedSymbols
	If oSymbol.Name = "Aenderungs-Index-Zeile" Then 
		'find the text box by name/label
		For Each oTextBox In oSymbol.Definition.Sketch.Textboxes
			If oTextBox.Text = "Index Nummer"
				oString = oSymbol.GetResultText(oTextBox)
				'write value to iproperty
				iProperties.Value("Status", "Eng. Approved By") = oString
				'display value to user
				MessageBox.Show(oString, "iLogic")
			End If
		Next		
	End If
Next

 

 

Thanks in advance

Regards

Martin

0 Likes
Accepted solutions (1)
668 Views
7 Replies
Replies (7)
Message 2 of 8

HermJan.Otterman
Advisor
Advisor

Hello Martin,

 

I altered your code a little

 

try this:

 Dim oDrawDoc As DrawingDocument
        oDrawDoc = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = Nothing

        Dim HighestNumber As Integer = 0


        For Each oSheet In oDrawDoc.Sheets


            'find the symbol by name
            For Each oSymbol In oSheet.SketchedSymbols
                If oSymbol.Name = "Aenderungs-Index-Zeile" Then
                    'find the text box by name/label
                    For Each oTextBox In oSymbol.Definition.Sketch.Textboxes
                        If oTextBox.Text = "Index Nummer" Then
                            Dim oString As String = oSymbol.GetResultText(oTextBox)

                            'split the string, get the last two characters
                            Dim Number As Integer = Strings.Right(oString, 2)

                            If Number > HighestNumber Then HighestNumber = Number


                            'write value to iproperty
                            iProperties.Value("Status", "Eng. Approved By") = oString
                            'display value to user
                            MessageBox.Show(oString, "iLogic")
                        End If
                    Next
                End If
            Next
        Next

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 8

martinhoos
Advocate
Advocate

Hello HermJan,

thank you for your reply. There is only one Problem, if there is a sketched symbol on sheet one with a01 and a sketched symbol on sheet two with a02, your code writes: a01

Regards Martin

0 Likes
Message 4 of 8

HermJan.Otterman
Advisor
Advisor

Dim oDrawDoc As DrawingDocument

oDrawDoc = _inventorApplication.ActiveDocument 'ThisApplication.ActiveDocument

Dim oSheet As Sheet = Nothing

Dim HighestNumber As Integer = 0

 

 

For Each oSheet In oDrawDoc.Sheets

 

 

'find the symbol by name

For Each oSymbol In oSheet.SketchedSymbols

If oSymbol.Name = "Aenderungs-Index-Zeile" Then

'find the text box by name/label

For Each oTextBox In oSymbol.Definition.Sketch.Textboxes

If oTextBox.Text = "Index Nummer" Then

Dim oString As String = oSymbol.GetResultText(oTextBox)

'split the string, get the last two characters

Dim Number As Integer = Strings.Right(oString, 2)

If Number > HighestNumber Then HighestNumber = Number

End If

Next

End If

Next

Next

'write value to iproperty

iProperties.Value("Status", "Eng. Approved By") = HighestNumber

'display value to user

MessageBox.Show(HighestNumber, "iLogic")

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 5 of 8

HermJan.Otterman
Advisor
Advisor
I hope that it works now.
had to give back the highestNumber, not ostring
If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 6 of 8

HermJan.Otterman
Advisor
Advisor
Accepted solution
change the second line... the green code is correct...
it should say:
oDrawDoc = ThisApplication.ActiveDocument
If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 7 of 8

martinhoos
Advocate
Advocate

Hello HermJan,

thank you very much - your code works!

Regards

Martin

0 Likes
Message 8 of 8

martinhoos
Advocate
Advocate

Hello Jan,

can you help me again? I told you that your code runs... thats right - but in the meantime we found out, that we have old drawings that have a1 or a2 ....a9 included. in that case the code didnt work.

 

We changed our syntax from a1 to a01 and so on - that means that a1 is the same like a01

 

Is it possible for you to modify the code for that case?

 

thanks in advance

Regards

Martin

 

 

0 Likes