SetPromptResultText()

SetPromptResultText()

zhikaobi1725
Contributor Contributor
12,342 次查看
17 条回复
1 条消息(共 18 条)

SetPromptResultText()

zhikaobi1725
Contributor
Contributor

 SetPromptResultText() 函数调用失败

 

 

 run_time error ‘5’

 

invalid procedure call or argument

 

 

0 个赞
12,343 次查看
17 条回复
回复 (17)
2 条消息(共 18 条)

Steven_Gao
Community Manager
Community Manager

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



Steven Gao
Fusion & Inventor Quality Assurance

https://www.autodesk.com/campaigns/fusion-360/insider-program 

0 个赞
3 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

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。

0 个赞
4 条消息(共 18 条)

Xun.Zhang
Alumni
Alumni

请尝试如下的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

 


Xun
0 个赞
5 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

多谢 提供代码: 但仍是不行:如下面附件 我自己建立的符号“ 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

 

0 个赞
6 条消息(共 18 条)

Xun.Zhang
Alumni
Alumni

Hi,

 

请问报了什么错误?我这边是好的。

有video记录下来问题就更好了。


Xun
0 个赞
7 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

谢谢关注:

其他运行正常 调用此函数时 出现附件的提示:

我们单位计算机,我们权限有一定的限制, 无法自行安装软件,C盘下的程序文件夹下无写入权限, 注册表无写入权限,

不知道是否和此有关。

0 个赞
8 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

调用此函数目的想实现形位公差参数化,inventor  有其他方法实现形位公差参数化(企业自己的标准 ) 请指教

0 个赞
9 条消息(共 18 条)

Xun.Zhang
Alumni
Alumni

能把你的文件传上来吗?我们可以仔细看看问题的所在。


Xun
0 个赞
10 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

你好

 我是新接触二次开发,就是简单建立了个零件和工程图,然后来测试这个函数,最后都出现这个问题。代码都是从这个论坛上或得的

0 个赞
11 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

零件图

0 个赞
12 条消息(共 18 条)

YuhanZhang
Autodesk
Autodesk
已接受的解答

你的工程图中的SketchedSymbol的定义里面没有设置TextBox的类型为Prompted Entry,所以你无法通过SetPromptResultText方法来修改其显示的文字,你可以按照下面的所示修改:

 

1. 编辑matest。

2. 编辑mytest的TextBox.

3. 在图示箭头所指的下拉菜单中选择Prompted Entry。然后保存所有的改动,测试VBA代码。

 

PromptedText.png



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.

0 个赞
13 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

按方法已经解决 多谢,

 形位公差参数化,还有其他方法吗?

0 个赞
14 条消息(共 18 条)

YuhanZhang
Autodesk
Autodesk
已接受的解答

你是要标示“形位公差”吗?如果是这样的话可以使用FeatureControlFrame来实现。UI上你可以通过 Feature Control Frame的命令创建:

 

FCF.png

 

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


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.

0 个赞
15 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

多谢指教, 我用电子表格上的数据来控制形位公差上的数据,形位公差数据根据电子表格上的尺寸变换来后台控制变化, 有没有更简单的方法,象ilogic中电子表格参数表一样来控制。

0 个赞
16 条消息(共 18 条)

YuhanZhang
Autodesk
Autodesk
已接受的解答

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

 

希望这个建议能给你带来帮助。



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.

17 条消息(共 18 条)

zhikaobi1725
Contributor
Contributor

多谢,

用inventor 自带的形位公差标注(非自己建立的符号),能否用API变更,2015版本有相应变更函数吗?

0 个赞
18 条消息(共 18 条)

YuhanZhang
Autodesk
Autodesk
已接受的解答

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



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.

0 个赞