能否提供更详细的code,单纯一条代码难说明问题。

https://www.autodesk.com/campaigns/fusion-360/insider-program
Sub ChangeSymbolPromptTextValue()
Dim doc As DrawingDocument
Set doc = ThisDocument
Dim oSheet As Sheet
Set oSheet = thisapplication.ActiveDocument.ActiveSheet
Dim sketchSym As SketchedSymbol
Set sketchSym = oSheet.SketchedSymbols(1)
Dim tBox As TextBox
Dim tboxtext As String
Set tBox = sketchSym.Definition.Sketch.TextBoxes(1)
tboxtext = sketchSym.GetResultText(tBox)
MsgBox (tboxtext)
MsgBox (Chr(176))
Call sketchSym.SetPromptResultText(tBox, Chr(176))
End Sub
如上面的代码: 我在本论坛上找了好多关于此函数的代码 ,均提示上面的错误
我的inventor 版本是Autodesk Inventor Professional 2015。
请尝试如下的VBA代码样本,你可以在此基础上进行编辑。
Sub MofidyPromptedEntry()
Dim oSS As SketchedSymbol
Set oSS = ThisApplication.ActiveDocument.SelectSet(1)
Dim oTB As TextBox
For Each oTB In oSS.Definition.Sketch.TextBoxes
If oTB.Text = "<MyPrompt>" Then
Call oSS.SetPromptResultText(oTB, "NewValue")
End If
Next
End Sub
当然,如果你使用iLogic的话,也可以使用以下的代码样本。
' Set the value for the first sketched symbol
' on the current sheet
Dim oSS As SketchedSymbol
oSS = ActiveSheet.Sheet.SketchedSymbols(1)
Dim oTB As TextBox
For Each oTB In oSS.Definition.Sketch.TextBoxes
If oTB.Text = "<MyPrompt>" Then
Call oSS.SetPromptResultText(oTB, "NewValue")
End If
Next
多谢 提供代码: 但仍是不行:如下面附件 我自己建立的符号“ mytest ”想实现参数化改成”mychange“, 调用SetPromptResultText(oTB, "mychange")
但提示调用失败(引用下面的代码)
Sub MofidyPromptedEntry()
Dim oSS As SketchedSymbol
Set oSS = ThisApplication.ActiveDocument.SelectSet(1)
Dim oTB As TextBox
For Each oTB In oSS.Definition.Sketch.TextBoxes
If oTB.Text = "mytest" Then
Call oSS.SetPromptResultText(oTB, "mychange")
End If
Next
End Sub
你的工程图中的SketchedSymbol的定义里面没有设置TextBox的类型为Prompted Entry,所以你无法通过SetPromptResultText方法来修改其显示的文字,你可以按照下面的所示修改:
1. 编辑matest。
2. 编辑mytest的TextBox.
3. 在图示箭头所指的下拉菜单中选择Prompted Entry。然后保存所有的改动,测试VBA代码。

你是要标示“形位公差”吗?如果是这样的话可以使用FeatureControlFrame来实现。UI上你可以通过 Feature Control Frame的命令创建:
API也可以用参考下面的VBA示例:
Public Sub AddFeatureControlFrame()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the active sheet.
Dim oActiveSheet As Sheet
Set oActiveSheet = oDrawDoc.ActiveSheet
' Set a reference to the drawing curve segment.
' This assumes that a drwaing curve is selected.
Dim oDrawingCurveSegment As DrawingCurveSegment
Set oDrawingCurveSegment = oDrawDoc.SelectSet.Item(1)
' Set a reference to the drawing curve.
Dim oDrawingCurve As DrawingCurve
Set oDrawingCurve = oDrawingCurveSegment.Parent
' Get the mid point of the selected curve
' assuming that the selection curve is linear
Dim oMidPoint As Point2d
Set oMidPoint = oDrawingCurve.MidPoint
' Set a reference to the TransientGeometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oLeaderPoints As ObjectCollection
Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
' Create a few leader points.
Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10))
Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))
' Create an intent and add to the leader points collection.
' This is the geometry that the symbol will attach to.
Dim oGeometryIntent As GeometryIntent
Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
Call oLeaderPoints.Add(oGeometryIntent)
' Create a FeatureControlFrameRows object to define the symbol's rows
Dim oRows As FeatureControlFrameRows
Set oRows = oActiveSheet.FeatureControlFrames.CreateFeatureControlFrameRows
' Add a row
Dim oRow As FeatureControlFrameRow
Set oRow = oRows.Add(kProfileOfAnySurface, "0.20", , "A", "B")
' Create the feature control frame symbol with a leader
Dim oSymbol As FeatureControlFrame
Set oSymbol = oActiveSheet.FeatureControlFrames.Add(oLeaderPoints, oRows)
End Sub

目前没有一个直接的连接形位公差和Excel表格的功能,不过你可以自己实现,在你的程序里面可以建立一个thread来监视Excel的改动(比如比较TimeStamp),一旦Excel有改动就通过API更新相应的形位公差数据,反之可以通过DocumentEvents.OnChange监听工程图的改动,如果是形位公差数据改动了就更新Excel。
希望这个建议能给你带来帮助。

FeatureControlFrame的创建和编辑的API在Inventor 2009里就已经提供了,所以Inventor 2015里可以使用API进行编辑。
