CATIA v5。用于将 3Dpart 的参数值提取到绘图上的文本框中的宏
CATIA v5. Macro for extracting value of 3Dpart's parameter into a text box on the drawing
一天多来我一直在尝试做标题描述的事情,但我似乎无法弄清楚。
情况:
我有一个 3D 部件,其中包含多个 user-made 参数作为字符串。
我创建了一个包含前视图、俯视图和等距视图的新绘图。
我想创建一个宏来读取我的 3D 零件参数的字符串值,并将它们写入图纸上的特定位置。
目前工作:
我可以在我的绘图中使用宏召唤文本,但我不知道如何在 VB 环境中从 user-made 中提取字符串值我的 3D 部分中的参数。
我试过使用
myValue = material.Value
其中 "material" 是我的 3D 零件的参数,但我无法获得 return。我不知道要声明什么以及如何正确引用参数。
此外,我可以通过编写以下代码在我的绘图上使用宏编写纯文本:
Set myText = MyDrawingViews.ActiveView.Texts.Add("description", 22, 38)
我在我的绘图上的预定位置收到一条文字,上面写着 "description",但我不知道如何使用变量来驱动文字。
当我尝试时:
dim myValue as string
myValue = "description"
Set myText = MyDrawingViews.ActiveView.Texts.Add(myValue, 22, 38)
我没有收到 return。
我一直在努力,但我似乎无处可去,任何帮助将不胜感激。
您需要从文本中所需的 Part
或 Product
中获取对 Parameter
的引用。此外,您应该使用 DrawingText
对象的 InsertVariable
方法来 link 参数。当零件中的参数发生变化时,可以在图纸中进行更新。
这是一个简单的Sub,可以完成你想要的(你可以修改它来更具体地完成你想要的):
Sub AddTextWithLinkedParameter(dViewToContainTheText As DrawingView, xPos, yPos, Optional param As Parameter)
Dim dtext As DrawingText
Set dtext = dViewToContainTheText.Texts.Add("", xPos, yPos)
If Not param Is Nothing Then
dtext.InsertVariable 0, 0, param
End If
End Sub
这里有一些示例代码来测试它:
Sub testParameterText()
Debug.Assert False
'
'Manually Activate the Part Document
'that contains a string parameter called "Property
'
Dim myParam As Parameter
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument
Set myParam = partDoc.Part.Parameters.Item("Property")
Debug.Assert False
'manually switch to a drawing document
Dim dDoc As DrawingDocument
Set dDoc = CATIA.ActiveDocument
Dim dSheet As DrawingSheet
Set dSheet = dDoc.Sheets.ActiveSheet
Dim dView As DrawingView
Set dView = dSheet.Views.Item("Main View")
AddTextWithLinkedParameter dView, 20, 20, myParam
End Sub
一天多来我一直在尝试做标题描述的事情,但我似乎无法弄清楚。
情况:
我有一个 3D 部件,其中包含多个 user-made 参数作为字符串。 我创建了一个包含前视图、俯视图和等距视图的新绘图。 我想创建一个宏来读取我的 3D 零件参数的字符串值,并将它们写入图纸上的特定位置。
目前工作:
我可以在我的绘图中使用宏召唤文本,但我不知道如何在 VB 环境中从 user-made 中提取字符串值我的 3D 部分中的参数。 我试过使用
myValue = material.Value
其中 "material" 是我的 3D 零件的参数,但我无法获得 return。我不知道要声明什么以及如何正确引用参数。
此外,我可以通过编写以下代码在我的绘图上使用宏编写纯文本:
Set myText = MyDrawingViews.ActiveView.Texts.Add("description", 22, 38)
我在我的绘图上的预定位置收到一条文字,上面写着 "description",但我不知道如何使用变量来驱动文字。 当我尝试时:
dim myValue as string
myValue = "description"
Set myText = MyDrawingViews.ActiveView.Texts.Add(myValue, 22, 38)
我没有收到 return。
我一直在努力,但我似乎无处可去,任何帮助将不胜感激。
您需要从文本中所需的 Part
或 Product
中获取对 Parameter
的引用。此外,您应该使用 DrawingText
对象的 InsertVariable
方法来 link 参数。当零件中的参数发生变化时,可以在图纸中进行更新。
这是一个简单的Sub,可以完成你想要的(你可以修改它来更具体地完成你想要的):
Sub AddTextWithLinkedParameter(dViewToContainTheText As DrawingView, xPos, yPos, Optional param As Parameter)
Dim dtext As DrawingText
Set dtext = dViewToContainTheText.Texts.Add("", xPos, yPos)
If Not param Is Nothing Then
dtext.InsertVariable 0, 0, param
End If
End Sub
这里有一些示例代码来测试它:
Sub testParameterText()
Debug.Assert False
'
'Manually Activate the Part Document
'that contains a string parameter called "Property
'
Dim myParam As Parameter
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument
Set myParam = partDoc.Part.Parameters.Item("Property")
Debug.Assert False
'manually switch to a drawing document
Dim dDoc As DrawingDocument
Set dDoc = CATIA.ActiveDocument
Dim dSheet As DrawingSheet
Set dSheet = dDoc.Sheets.ActiveSheet
Dim dView As DrawingView
Set dView = dSheet.Views.Item("Main View")
AddTextWithLinkedParameter dView, 20, 20, myParam
End Sub