CATIA Macro to Open in New Window
|Often times when you’re working in a large assembly in CATIA V5 you want to look at a single part or subsystem and the easiest way to do that is right click on the part or product in the specification tree and click “Open in New Window.” But what if you want to use a CATIA macro to open in new window? The easiest way is to use StartCommand method:
CATIA.StartCommand “Open in New Window”
To open a selection in a new window, try this:
If UserSelection = “Normal” Then
CATIA.StartCommand “Open in New Window”
Else
‘Take some other action…
End If
As long as an instance is selected, this command will open the part in its own window. I added a check to be sure the selection was successful before calling because if nothing is selected CATIA just ignores the command plus you might want to do another action anyways, like close the program.
Not everyone likes using StartCommand method. You could use Use NewWindow method:
CATIA.Documents.Item(“MyPart.CATPart”).NewWindow()
However, it appears NewWindow is either broken or behaves erratically, therefore I usually stick to the StartCommand way.
Here’s an example using SelectElement2 where we will ask the user to select a CATProduct from the tree and the macro will open that product in a new window. Notice the error handling in case there is a problem with the user’s selection.
Option Explicit Sub ProductionSelection() '----------------select product----------------------------------- ' What do you want to select Dim EnableSelectionFor(0) EnableSelectionFor(0) = "Product" Dim productSelection Set productSelection = CATIA.ActiveDocument.Selection productSelection.Clear ' Define Selection Dim UserSelection As String MsgBox "Please select the Product to open in new window." UserSelection = productSelection.SelectElement2(EnableSelectionFor, "Please select a Product", False) ' Evaluation if the selection is correct or not If UserSelection <> "Normal" Then MsgBox "Error with the selection." Exit Sub End If Dim oProdName As Product Set oProdName = productSelection.Item(1).Value CATIA.StartCommand "Open in New Window" MsgBox "The Product selected is : " & oProdName.Name MsgBox "The Product description is : " & oProdName.Nomenclature MsgBox "The Product revision is : " & oProdName.Revision End Sub
Hi,
I have a question regarding to “Open in New Window”.
when I’m working in a large assembly in CATIA V5 i want to look at a single part.
But how can i create short cut on keyboard for “Open in New Window”
Could you please help me?
thank you