Edit text in Sketched symbols

Edit text in Sketched symbols

Anonymous
Not applicable
4,025 Views
9 Replies
Message 1 of 10

Edit text in Sketched symbols

Anonymous
Not applicable

Hi,

I have more then one hundred sketched symbols on drawing. Sketched symbols have one text box with certain text.

Is it possible to change this text to another in each sketch symbol?

I know how to go over the collection of  sketched symbols, but I don't know the procedure of editing text in sketched symbols. Please help me with example on VBA/VBnet.

0 Likes
Accepted solutions (1)
4,026 Views
9 Replies
Replies (9)
Message 2 of 10

HermJan.Otterman
Advisor
Advisor

if you know some vba/vb then look in the Inventor programming/API help

 

look for the sketchedsymboldefinition and textboxes...

 

you can change the text in the textboxes of a sketched symbol

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 10

bradeneuropeArthur
Mentor
Mentor

Check this:

 

https://forums.autodesk.com/t5/inventor-customization/get-attributes-values-from-sketched-symbol/td-p/7714141

https://forums.autodesk.com/t5/inventor-customization/get-attributes-values-from-sketched-symbol/td-...

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

Anonymous
Not applicable

Try these scripts out in the API. Depending on whether or not you are using prompted entry for that text box you might want a different Script. I believe you're probably looking for the second of these two scripts though.

 

Uncomment the lines for the symbol's name if you want to isolate a specific symbol by name.

 

Good Luck!

 

Public Sub ChangeTextPromptOfSketchSymbolsOnAllSheets()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub
    Dim oDrawDoc As DrawingDocument: Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Dim oSymbol As SketchedSymbol
    
    Dim strNewText As String: strNewText = InputBox("Enter New Text for Sketched Symbols.")
    
    On Error Resume Next 'this allows the script to skip over the symbol if the first textbox is not a prompted entry textbox
    For Each oSheet In oDrawDoc.Sheets
        For Each oSymbol In oSheet.SketchedSymbols
'            If oSymbol.Name = "STAMP" Then
                Dim oText As TextBox
                Set oText = oSymbol.Definition.Sketch.TextBoxes(1)
                Call oSymbol.SetPromptResultText(oText, strNewText)
'            End If
        Next
    Next
End Sub

Public Sub ChangeFirstTextBoxOfAllSketchedSymbolDefinitionsInDrawing()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub
    Dim oDrawDoc As DrawingDocument: Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Dim oSymbolDef As SketchedSymbolDefinition
    
    Dim strNewText As String: strNewText = InputBox("Enter New Text for Sketched Symbols.")
    
    'as written, this will disregard any prompted entry textboxes and reset them to static text
    For Each oSymbolDef In oDrawDoc.SketchedSymbolDefinitions
'        If oSymbolDef.Name = "STAMP" Then
            Dim oDrawSketch As DrawingSketch
            Set oDrawSketch = oSymbolDef.Sketch
            Call oSymbolDef.Edit(oDrawSketch)
            Dim oText As TextBox
            Set oText = oDrawSketch.TextBoxes.Item(1)
            oText.FormattedText = strNewText
            Call oSymbolDef.ExitEdit(True)
'        End If
    Next
End Sub
0 Likes
Message 5 of 10

Anonymous
Not applicable

@Anonymous wrote:

Try these scripts out in the API. Depending on whether or not you are using prompted entry for that text box you might want a different Script. I believe you're probably looking for the second of these two scripts though.

 

Uncomment the lines for the symbol's name if you want to isolate a specific symbol by name.

 

Good Luck!

 

Public Sub ChangeTextPromptOfSketchSymbolsOnAllSheets()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub
    Dim oDrawDoc As DrawingDocument: Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Dim oSymbol As SketchedSymbol
    
    Dim strNewText As String: strNewText = InputBox("Enter New Text for Sketched Symbols.")
    
    On Error Resume Next 'this allows the script to skip over the symbol if the first textbox is not a prompted entry textbox
    For Each oSheet In oDrawDoc.Sheets
        For Each oSymbol In oSheet.SketchedSymbols
'            If oSymbol.Name = "STAMP" Then
                Dim oText As TextBox
                Set oText = oSymbol.Definition.Sketch.TextBoxes(1)
                Call oSymbol.SetPromptResultText(oText, strNewText)
'            End If
        Next
    Next
End Sub

Public Sub ChangeFirstTextBoxOfAllSketchedSymbolDefinitionsInDrawing()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub
    Dim oDrawDoc As DrawingDocument: Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Dim oSymbolDef As SketchedSymbolDefinition
    
    Dim strNewText As String: strNewText = InputBox("Enter New Text for Sketched Symbols.")
    
    'as written, this will disregard any prompted entry textboxes and reset them to static text
    For Each oSymbolDef In oDrawDoc.SketchedSymbolDefinitions
'        If oSymbolDef.Name = "STAMP" Then
            Dim oDrawSketch As DrawingSketch
            Set oDrawSketch = oSymbolDef.Sketch
            Call oSymbolDef.Edit(oDrawSketch)
            Dim oText As TextBox
            Set oText = oDrawSketch.TextBoxes.Item(1)
            oText.FormattedText = strNewText
            Call oSymbolDef.ExitEdit(True)
'        End If
    Next
End Sub

Thanks for your reply! You are right I am looking for the second script but it is not working properly:(  

I'm testing the script on small drawing and I have created some Leader Text symbols (in Annotate tab) on the drawing with certain text.

(I suppose object "Leader Text" relates to Sketched symbols, am I right?)

Then I run the script. It changes text to specified in the sketched symbols and formatting of the text is reset. But if I open symbol by standard editor I see the old text. You can try it yourself.

Any ideas?

0 Likes
Message 6 of 10

Anonymous
Not applicable
Accepted solution

Good call. I was working with sketched symbols that did not have any formatting on the text so I was ignoring retaining it. Try this.

 

Public Sub ChangeFirstTextBoxOfAllSketchedSymbolDefinitionsInDrawing()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub
    Dim oDrawDoc As DrawingDocument: Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Dim oSymbolDef As SketchedSymbolDefinition
    
    Dim strNewText As String: strNewText = InputBox("Enter New Text for Sketched Symbols.")
    
    'as written, this will disregard any prompted entry textboxes and reset them to static text
    For Each oSymbolDef In oDrawDoc.SketchedSymbolDefinitions
'        If oSymbolDef.Name = "STAMP" Then
            Dim oDrawSketch As DrawingSketch
            Set oDrawSketch = oSymbolDef.Sketch
            Call oSymbolDef.Edit(oDrawSketch)
            Dim oText As TextBox
            Set oText = oDrawSketch.TextBoxes.Item(1)
            Dim strTextFormat As String: strTextFormat = oText.FormattedText
            strTextFormat = Replace(strTextFormat, oText.Text, strNewText)
            oText.FormattedText = strTextFormat
            Call oSymbolDef.ExitEdit(True)
'        End If
    Next
End Sub
Message 7 of 10

Anonymous
Not applicable

@Anonymous wrote:

Good call. I was working with sketched symbols that did not have any formatting on the text so I was ignoring retaining it. Try this.

 

Public Sub ChangeFirstTextBoxOfAllSketchedSymbolDefinitionsInDrawing()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Sub
    Dim oDrawDoc As DrawingDocument: Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Dim oSymbolDef As SketchedSymbolDefinition
    
    Dim strNewText As String: strNewText = InputBox("Enter New Text for Sketched Symbols.")
    
    'as written, this will disregard any prompted entry textboxes and reset them to static text
    For Each oSymbolDef In oDrawDoc.SketchedSymbolDefinitions
'        If oSymbolDef.Name = "STAMP" Then
            Dim oDrawSketch As DrawingSketch
            Set oDrawSketch = oSymbolDef.Sketch
            Call oSymbolDef.Edit(oDrawSketch)
            Dim oText As TextBox
            Set oText = oDrawSketch.TextBoxes.Item(1)
            Dim strTextFormat As String: strTextFormat = oText.FormattedText
            strTextFormat = Replace(strTextFormat, oText.Text, strNewText)
            oText.FormattedText = strTextFormat
            Call oSymbolDef.ExitEdit(True)
'        End If
    Next
End Sub

This one works better. The formatting remains the same.

But there is still one bug I mentioned in my previous message - after script finished working I see the text has changed on the drawing but when I open symbol in standard editor I see the old text. Why?

0 Likes
Message 8 of 10

Anonymous
Not applicable

I'm not sure on that one. I can't seem to replicate that problem. If you want to attach a drawing with one of the sketched symbols, maybe I can see what you're seeing.

0 Likes
Message 9 of 10

MechMachineMan
Advisor
Advisor

Try hitting the Update button or Rebuild before editting the sketched symbol, after the code has run.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 10

Anonymous
Not applicable

OK, thanks guys for your help

I solved the problem!

There was a problem with one special inventor add-in, when I turned it off - your solution works great!!

0 Likes