在CATIA中更改切割视图文本 [英] Change cut view text in CATIA
问题描述
我目前正在使用CATIA V5,并且我想使用宏(VBA),但是我有一些问题!
I'm currently working with CATIA V5, and I want to use Macros (VBA), but I have some problems!
我的问题是:如何更改剪切视图的文字? (参见图片)
My question is: how to change the text of a cut view? (see the picture)
我尝试使用:myView.Texts.item(1)访问此文本,但我认为CATIA不会将其视为文本 ...
I tried to use : myView.Texts.item(1) to access to this "text" but I think that CATIA dont consider it as text...
我想在没有用户干预的情况下(无需选择)更改此文本,我可以这样做吗?
I want to change this text without the intervention of the user ( without selections), can I do that?
推荐答案
IME,起草工作台中的VBA脚本起初非常棘手... MyTexts是DrawingText对象的集合。
IME, VBA scripting in drafting workbench is quite tricky at first..."MyTexts" is a collection of DrawingText objects.
MyDrawingText.Text = "MyNewTextValue"
您将要遇到的主要麻烦是要处理要修改的特定文本对象。我发现解决此问题的最佳方法是扫描DrawingView中的整个DrawingTexts集合,并应用唯一的名称 DrawingText.Name = UniqueObjectName
或创建脚本中的绘图文本,您可以更轻松地在DrawingText对象上获取一个句柄,以在其中放置所需的任何值。创建唯一的名称使您的绘图对于以后的脚本更强大
The main trouble you will have is getting a handle on the specific text object that you want to modify. I found that the best way around this is to either scan the entire DrawingTexts collection in the DrawingView, and apply a unique name, DrawingText.Name="UniqueObjectName"
, or you create the drawing text from the script and you can more easily get a handle on the DrawingText object to put whatever value you want in there. Creating Unique Names makes your drawing more robust for future scripting
MyView.Texts.Count
对于获取项目编号(如果最后创建的DrawingText对象)。
MyView.Texts.Count
will also be useful to get the item number if the last created DrawingText object(s).
很高兴进一步解释您是否需要。祝您好运!
I'm happy to further explain if you need. Good luck!
更新/编辑:
如上所述,使用绘图工作台编写脚本并不总是那么简单。事实证明,标注文本并不完全存在于 DrawingView
的 DrawingTexts
集合中,但是它们确实位于工程图视图中的某处...在这种情况下,您正在尝试编辑剖面图的 ID。该属性也不会通过VBA公开。
Update/
As mentioned above, scripting with the drafting workbench is not always straight forward. It turns out that the callout texts do not exactly live in the DrawingTexts
collection of a DrawingView
, but they do live somewhere inside the drawing view...In this case, you're trying to edit the "ID" of the section view..That property isn't exposed through VBA either.
有一个 hack / work-around ,它可以在父视图中搜索绘图文本,然后使用一些逻辑,您需要提出一些逻辑,扫描选择
以查找要更改的文本。
There is a hack/work-around which is to search the parent view for drawing texts and and then with some logic, which you'll need to come up with, scan the Selection
for the texts you want to change. You should rename then while you're at it, this way it's easier to come back and find them again.
这里是一个示例,该示例从前视图的对象分辨率开始(剖视图的父视图)
Here's an example starting with an Object Resolution of the Front View (the parent view of the section view)
Sub ChangeCallout()
'---- Begin resolution script for object : Front View
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Front view") 'this is the parent view of the section view
'---- End resolution script
Dim sel As Selection
Set sel = drawingDocument1.Selection
Dim CalloutText As drawingText
sel.Clear 'clear the selection / good practice
sel.Add drawingView1 'add the parent view to the selection
sel.Search "Drafting.Text,sel" 'this will search the current selection for all drawing texts and add them to the selection
Dim thing As Variant
Dim i As Integer
For i = 1 To sel.Count
Set thing = sel.Item2(i)
Set CalloutText = thing.Value
'do some things/logic here to determine if this is a callout with some Ifs or Case statements
'CalloutText.Name = "Useful Unique Name"
'CalloutText.Text = "New Callout Label" 'whatever you want to rename it to
Next
End Sub
这篇关于在CATIA中更改切割视图文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!