I am automating the creation of a new product with a Python script and have run into a problem with the interactive events getting stuck at the "Part Number" dialog. This does not occur when creating a new part, just a new product. Here is the applicable portion of the script (CATIA is open):
import win32com.client.dynamic
CATIA = win32com.client.Dispatch("CATIA.Application")
catDocs = CATIA.Documents
# Create a new product
newProductDoc = catDocs.Add("Product")
# "Part Number" window appears, requesting a name for the product
# Interactive processes will not proceed
newProduct = newProductDoc.Product
newProductSet = newProduct.Products
newPart = newProductSet.AddNewComponent("Part", "dummyPart")
...
The problem is that I am developing a small tool for others to use and it is not very useful if it hangs up.
Clicking on "Cancel" gets rid of the dialog box, but no interactive actions occur afterwards. Clicking on "Ok" resolves the problem, but it would be preferable for the script to be able to prepare the product as a final result without interaction in order to restrict user error and improve ease of use.
I know that I can create a product and manipulate it (i.e. add parts, add new products, etc.), then successfully save it. So the processes are being executed, they just aren't being displayed anymore. I just can't seem to find a way to get past the "Part Number" dialog box. I even tried naming it programmatically, which worked but didn't kill the dialog box.
Opening an existing product works very well, and any scripting processes can continue without problems. However, programmatically creating the product, saving, and closing causes CATIA to lock up... so the option of saving and re-opening as an existing product is out the window.
I also referenced the v5Automation.chm, but I couldn't find a way of interacting with dialog boxes.
I also tried .Update()
on the new product and it's parts. Some other assurances were CATIA.Visible = True
and CATIA.RefreshDisplay = True
.
Disclaimer: I know that VBA can be used and does not pose this problem. I am looking for a solution to this problem using Python (2 or 3, doesn't matter).
The only way I have found, so far, to circumvent this problem is to create a template product (in this case, just an empty product) and do a
catDocs.NewFrom(<templateProductPath>)
and add the product structure as necessary.This post is old but since I found this page when having the same issue I figured I'll add my solution. I've found a handful of methods in CATIA that behave this way - works fine in CATIA VBA but not through the COM interface. The best solution I've found is to write a mini VBA function in a string and then call it in CATIA through Python. Here is an example:
I was trying to replicate your issue, but I dind't encounter it. Products just created fine using incremental default names. Then I thought it was something related to Settings since the dialog is simlar to the one that optionally pops up when addin a new part. I discovered that I had the option Infrastructure > Product Infrastructure > Product structure > Part Number: Manual input unchecked.
I don't know how this was related to using VBA or not, but checking it created the issue and unchecking it removed the issue, while still sending the same command from Python.