Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to load and process parts within product

Status
Not open for further replies.

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!
 
Replies continue below

Recommended for you

Ferdo,

I actually cheecked this script when I was looking through your CATIA Portable Script Center earlier today (which is a good reference, by the way, so thank you for creating that!) However, I'm trying to keep some elements (e.g. lines, points, etc.) in some geometric sets/part bodies, and hide other elements of the same type in different ones. So, to counter this, I was using the "Hide All Except Selected Elements" command on the part level after searching for bodies/sets I wanted to keep, and it was working well. However, I hadn't figured that the "Hide All Except Selected Elements" command wouldn't be available in the Assembly workbench. I was trying to figure out a way to mimic this command, such as by searching parent part bodies I wanted to keep and adding them to a selection, then searching for their children and adding them to a selection, then subtracting those selections from a selection set containing all elements within the part body, but I can't figure out if that's possible (and it's also a lot more difficult to do than using the "Hide All Except..." command!) Anyway, those are the main reasons why I can't really use the method you did in your macro. However, I appreciate your response, and if you've got any other suggestions, please let me know.

Thank you for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor