Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing the text in a textbox attached to a sketched symbol

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1570 Views, 2 Replies

Changing the text in a textbox attached to a sketched symbol

Hello all,

 

I'm currently in confusion over the dilemma of how to use VBA to get to the text in a sketched symbol. More specifically, I want to modify in the same way I can change a value after I've right clicked on the sketched symbol and chosen "edit field text". I can't find anything that looks useful in the API - actually there were a few that looked useful, but I couldn't get them to work. Here some code that doesn't work very well:

 

Sub WhereIsWaldo()
    Dim doc As DrawingDocument
    Set doc = ThisDocument

    Dim sktchSym As SketchedSymbol
    Set sktchSym = doc.Sheets(1).SketchedSymbols(5)
    Dim tBox As TextBox
    sktchSym.GetResultText tBox, "999"
End Sub

 

That was my last attempt to get at the textbox that appears to contain the value that needs to be changed on a regular basis. I just can't seem to find the textbox inside the sketched symbol. Any ideas?

 

Thanks,

Mike

2 REPLIES 2
Message 2 of 3
YuhanZhang
in reply to: Anonymous

Seems what you want to do is to change the prompted text value in a sketched symbol, if so you should use the SetPromptResultText instead of the GetResultText. Below is a VBA code sample, you should in UI select a sketched symbol first then run below code:

 

Sub ChangeSymbolPromptTextValue()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    If TypeName(oDoc.SelectSet(1)) = "SketchedSymbol" Then
        Dim oSymbol As SketchedSymbol
        Set oSymbol = oDoc.SelectSet(1)
    
        Dim oSymbolDef As SketchedSymbolDefinition
        Set oSymbolDef = oSymbol.Definition
        
        Dim oSk As DrawingSketch
        Set oSk = oSymbolDef.Sketch
        
        Dim oText As TextBox, oTempText As TextBox
        For Each oTempText In oSk.TextBoxes
            If InStr(1, LCase(oTempText.FormattedText), LCase("</Prompt>")) Then
                Set oText = oTempText
                Exit For
            End If
        Next
        
        If Not oText Is Nothing Then
            oSymbol.SetPromptResultText oText, "999"
        End If
    End If
End Sub

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 3
Anonymous
in reply to: YuhanZhang

That helps a great deal. I had seen SetPromptResultText , but I just couldn't figure out where the text box was supposed to come from for the first parameter. Here's the code I ended up using for a specific sketched symbol. I also snuck a degree symbol in there because that is what these represent (Chr(176)) in the drawing I'm working with.

 

Sub ChangeSymbolPromptTextValue()
    Dim doc As DrawingDocument
    Set doc = ThisDocument

    Dim sktchSym As SketchedSymbol
    Set sktchSym = doc.Sheets(1).SketchedSymbols(5)
    Dim tBox As TextBox
    Set sktchSym = doc.Sheets(1).SketchedSymbols(8)
    Set tBox = sktchSym.Definition.Sketch.TextBoxes(1)
    sktchSym.SetPromptResultText tBox, "999" & Chr(176)
End Sub

 

Thanks,

Mike

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report