Get attributes values from Sketched Symbol

Get attributes values from Sketched Symbol

meck
Collaborator Collaborator
1,587 Views
9 Replies
Message 1 of 10

Get attributes values from Sketched Symbol

meck
Collaborator
Collaborator

Hey All,

Trying to do something I thought would be simple, but I have having some trouble. I need to see what the user has entered for values in a sketched symbol. I thought I could just iterate through the attributes, but I get an error saying "Object doesn't support this property or method" on the line For Each oAttrib In oSketchedSymbol.oAttribSets.

Here is the whole code...

 

Public Function GetAttributes(SymbolName As String) As Boolean
    'This function returns true when SymbolName is inserted into the drawing
    invApp = GetObject(, "Inventor.Application")

    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet

    Dim oSketchedSymbol As SketchedSymbol
    Dim AttSet As AttributeSet

    For Each oSketchedSymbol In oSheet.SketchedSymbols
        If oSketchedSymbol.Name = SymbolName Then
            Dim oAttrib As Inventor.Attribute
           
            For Each oAttrib In oSketchedSymbol.oAttribSets
                MsgBox (oAttrib.Value)
            Next
        End If
    Next
End Function

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Accepted solutions (2)
1,588 Views
9 Replies
Replies (9)
Message 2 of 10

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Hi,

 

The following:

 

Public Sub f()

    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.activesheet
    Dim oSketchedSymbol As SketchedSymbol
    
    For Each oSketchedSymbol In oSheet.SketchedSymbols

          On Error Resume Next
MsgBox oSketchedSymbol.GetResultText(oSketchedSymbol.Definition.Sketch.TextBoxes.Item(1))
Next
End Sub

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

Message 3 of 10

dean.morrison
Advocate
Advocate

Hi,

 

You need to access the text boxes of your sketched symbol.

Attributes are just a way to append data to objects.

 

I have modified your code below.

 

----------------------------------------------------

 

Public Function GetAttributes(SymbolName As String) As Boolean
'This function returns true when SymbolName is inserted into the drawing
invApp = GetObject(, "Inventor.Application")

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

Dim oSketchedSymbol As SketchedSymbol
Dim AttSet As AttributeSet
Dim oSketchDef As Sketch
Dim oTextBoxes As TextBoxes
Dim iTextBox As TextBox

For Each oSketchedSymbol In oSheet.SketchedSymbols
If oSketchedSymbol.Name = SymbolName Then

Set oSketchDef = oSketchedSymbol.Definition.Sketch
Set oTextBoxes = oSketchDef.TextBoxes

For j = 1 To oTextBoxes.Count
Set iTextBox = oTextBoxes.Item(j)
MsgBox iTextBox.Text
Next

End If
Next
End Function

 

------------------------------------------------------

 

Hope that helps you.

 

Dean.

0 Likes
Message 4 of 10

bradeneuropeArthur
Mentor
Mentor

Hi @dean.morrison

,

 

This does not represent the "Filled in" values, as requested.

This will represent the textbox text's!!

 

 

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 5 of 10

dean.morrison
Advocate
Advocate

Yeah! haha thanks.

 

It would appear i added the wrong part of my code..

 

I really shouldn't reply to these first thing in the morning!

 

 

0 Likes
Message 6 of 10

bradeneuropeArthur
Mentor
Mentor

Hi,

 

The intention is the same anyway, ha ha.

 

nice evening

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 7 of 10

Darin.Green
Mentor
Mentor

 

@bradeneuropeArthur

How do you set the value for the prompted entry?

Given your suggestion 

 

oSketchedSymbol.GetResultText(oSketchedSymbol.Definition.Sketch.TextBoxes.Item(1)

 

Which get's the value from the prompted entry value. Is there away to set the value?



If this information was helpful, please consider using the Accept Solution


0 Likes
Message 8 of 10

bradeneuropeArthur
Mentor
Mentor
Accepted solution
oSketchedSymbol.SetPromptResultText(oSketchedSymbol.Definition.Sketch.TextBoxes.Item(1),"YOUR VALUE")

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 9 of 10

Darin.Green
Mentor
Mentor

Ah... I kept trying SetResultText instead of SetPromptResultText....

 

You are the man! Thanks!



If this information was helpful, please consider using the Accept Solution


0 Likes
Message 10 of 10

bradeneuropeArthur
Mentor
Mentor
Your thanks are appreciated....

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