How to switch a product to design mode using a CATScript macro

Often times when you are dealing with a very large assembly in CATIA the files are setup so that when you open these huge assemblies the parts and products come in as CGR files in visualization mode. To begin working on a part you need to switch the part and products into design mode. This can be accomplished with an easy CATScript macro. In this example, we will check to see if the top level product document is in design mode. If not then we will display a message box asking the user’s permission to automatically switch the product document to design mode.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Sub CATMain()
 
Dim prdRoot As Product
Set prdroot = CATIA.ActiveDocument.Product
 
'check if a product is in Design Mode
If (prdRoot.PartNumber = "") Then 'propose user to switch it in design mode
Dim vbResponse
vbResponse = MsgBox("Product " & prdRoot.Name & " is not in design mode. Would you like to switch it?", vbYesNo, "Warning")
If (vbResponse = vbYes) Then
prdRoot.ApplyWorkMode DESIGN_MODE
End If
Else
Msgbox "product already in design mode"
End If
End Sub

As usual in CATIA, there are multiple ways to accomplish the same task. Another method could be this:

1
2
3
4
5
6
7
8
9
10
Product_activ = InputBox("Activ Assembly it is in Design Mode ? Yes (Y) or No (N) !", "Product representations", "Yes")
If Product_activ = "" Then
MsgBox " Yes (Y) or No (N) ?"
'insert goto desired resulting action here
Else
If Product_activ = "N" Or Product_activ = "n" Then
' goto end sub
Else
End If
End If

This code by itself may not be very important to you but it might be a very good idea to add this to the beginning of a more complex macro designed to modify geometry or something else where the product must be in design mode first. As a programmer, you can never assume anything. Don’t assume the parts will already be in design mode. Make sure your code first checks for design mode and then switch to it if needed. This will save you a lot of time later on when other, less experienced users begin running your code and can’t get it to work because of something simple like being in design mode or not. Subscribe to our newsletter for more free CATIA script and macro tips!