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
Solved! Go to Solution.
Solved by YuhanZhang. Go to Solution.
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.
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