andybak
Automotive
- Jun 23, 2009
- 4
Hello,
I'm in the process of developing a macro to walk through a product tree, access a part and load it into design mode, process it depending on if its parameters meet certain conditions, then put it in visualization mode and continue to the next one. I've figured out most everything, but there is one thing I still can't get working - within the part, one of the things I am trying to do is use the "Hide All Except Selected" command on a selection. To do so, I'm calling the CATIA StartCommand for this function by a user alias that I assigned to it (HideAllExc). However, when running the macro, CATIA does not switch to the Part Design workbench, so I can't call this command. I also think that part of the issue is that I'm not actually activating the part, just the part document. I'm not sure how to do the former within this macro.
For reference, I have tried using the StartWorkbench command in various ways within the macro, but all it does is create a new blank part which it activates the Part Design workbench for; the Assembly Design workbench stays active within my original product. I was trying to figure out how to use the FrmActivate command on the selected part (which I discovered by right clicking on the part, then selecting "MyPart.Object"=>"Edit", but I haven't quite figured out how to use this. Additionally, it seems DS doesn't really support use of this command...
If anyone can give any advice, I'd greatly appreciate it.
Here's what I've got so far:
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products2 As Products
Set products2 = product1.Products
For i = 1 to products2.Count
products2.Item(i).ApplyWorkMode DESIGN_MODE
Dim parentFileName as String
parentFileName = products2.Item(i).ReferenceProduct.Parent.Name
Dim editPart as Product
Set editPart = CATIA.Documents.Item(parentFileName)
editPart.Activate
Dim parameterList As Parameters
Set parameterList = editPart.Product.UserRefProperties
Dim j as Integer
For j = 1 To parameterList.Count
If TypeName(parameterList.Item(j)) = "StrParam" Then
Dim checkParam as String
checkParam = parameterList.Item(j).ValueAsString
If checkParam = myString Then
Set selection1 = editPart.Selection
'addl misc stuff in here
selection1.Search "(SomeCriteria)"
CATIA.StartCommand "HideAllExc"
selection1.Clear
products2.Item(i).Save
End If
End If
Next
products2.Item(i).ApplyWorkMode VISUALIZATION_MODE
Next
End sub
I know I can make this more efficient, but I'm just trying to figure out how to get this working as desired first. Thanks for all your help!
I'm in the process of developing a macro to walk through a product tree, access a part and load it into design mode, process it depending on if its parameters meet certain conditions, then put it in visualization mode and continue to the next one. I've figured out most everything, but there is one thing I still can't get working - within the part, one of the things I am trying to do is use the "Hide All Except Selected" command on a selection. To do so, I'm calling the CATIA StartCommand for this function by a user alias that I assigned to it (HideAllExc). However, when running the macro, CATIA does not switch to the Part Design workbench, so I can't call this command. I also think that part of the issue is that I'm not actually activating the part, just the part document. I'm not sure how to do the former within this macro.
For reference, I have tried using the StartWorkbench command in various ways within the macro, but all it does is create a new blank part which it activates the Part Design workbench for; the Assembly Design workbench stays active within my original product. I was trying to figure out how to use the FrmActivate command on the selected part (which I discovered by right clicking on the part, then selecting "MyPart.Object"=>"Edit", but I haven't quite figured out how to use this. Additionally, it seems DS doesn't really support use of this command...
If anyone can give any advice, I'd greatly appreciate it.
Here's what I've got so far:
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products2 As Products
Set products2 = product1.Products
For i = 1 to products2.Count
products2.Item(i).ApplyWorkMode DESIGN_MODE
Dim parentFileName as String
parentFileName = products2.Item(i).ReferenceProduct.Parent.Name
Dim editPart as Product
Set editPart = CATIA.Documents.Item(parentFileName)
editPart.Activate
Dim parameterList As Parameters
Set parameterList = editPart.Product.UserRefProperties
Dim j as Integer
For j = 1 To parameterList.Count
If TypeName(parameterList.Item(j)) = "StrParam" Then
Dim checkParam as String
checkParam = parameterList.Item(j).ValueAsString
If checkParam = myString Then
Set selection1 = editPart.Selection
'addl misc stuff in here
selection1.Search "(SomeCriteria)"
CATIA.StartCommand "HideAllExc"
selection1.Clear
products2.Item(i).Save
End If
End If
Next
products2.Item(i).ApplyWorkMode VISUALIZATION_MODE
Next
End sub
I know I can make this more efficient, but I'm just trying to figure out how to get this working as desired first. Thanks for all your help!