Accessto the CATIA object model is provided using scripts in different waysdepending on the operating system and on the applications that can share theirown objects with CATIA. This also applies for ENOVIA DMU and DELMIA products. In the following you can subsitute "DMU" or "DELMIA" to "CATIA" if you need to access or launch another application based on the common V5 platform.
In-process access means that the script interpretation is performed in thesame process as CATIA. You usually run the macros from the Macros windowtriggered from the interactive Tools->Macros command. In this case,the macro is processed by CATIA just like any other command.
Out-process access means that you run the macro from another applicationrunning in another process. In this case, the macro should first connect toCATIA to then access its data. This connection starts CATIA if no CATIA processis being running.
In-process access means that the script interpretation is performed in thesame process as CATIA using the scripting engine(s) hosted by CATIA. You can runin-process macros with UNIX and Windows. You have three means to run in-processmacros:
Note that even if you use a macro language allowing to type to those arguments, the types won't be user at runtime, so it is recommended to give an explicit name to the variable to avoid end-user mystakes:
Running Out-process MacrosOut-process access means that you run the macro from another applicationrunning in another process, such as from Visual Basic for Applicationsassociated with products such as Excel or Word, or from Microsoft Visual Basic 5Development Studio. You can also use the Windows Scripting Host to run VBScriptor JScript macros by simply double clicking the macro name from the Windowsdesktop or Explorer, or from the command console. You can finally use VBScriptor JScript macros embedded in html pages.
The macro should first connect to CATIA to then access its data. Thisconnection starts CATIA if no CATIA process is being running. The script isinterpreted by the scripting engine hosted by the application from which youstart the macro.
Another way is to use the Windows Scripting Host. This is alanguage-independent scripting host which enables scripts written in differentlanguages such as Visual Basic, JScript, and Perl, to be run from the Windowsdesktop, the Windows Explorer, or the command console.
Alf may be used as a scripting language to write simple expressions without the need to compile the script. Scripts can be used in the body of Opaque Actions, Opaque Behaviors, Opaque Expressions, State Machine Guards, or even directly in the Simulation Console.
I got the idea for this article from a reader of this blog. He sent me an email asking what would be the best way to extract some information from thousands of drawings in an automated way. That information in his scenario is the value of a handful of parameters that are attached to the root drawing node in each drawing. I recommended to execute a script in batch mode that would open each drawing one by one and read those parameter values and write the data to a text file.
In our email exchanges, we both agreed that this seemed like a great topic to share with everyone for a few reasons. First, this is a relatively common scenario so many people could benefit by sharing the code that opens the drawings and writes out the parameter values. Also, I have a feeling that many have never run a script in batch mode so this article might unlock some new capabilities. So in this article, I will discuss the basics of running a batch and share the code we developed and tested.
One of the key items above is that CATIA will run considerably faster in batch mode than it does in interactive mode. This is because when it runs in interactive mode, it constantly has to process updates to the interactive graphical display but in batch mode none of those updates are done. At the end of this article, I will share the performance numbers for the drawing example batch.
As mentioned earlier, our scenario is to open thousands of drawings and extract some parameter values and write them to a text file. We want to do this as efficiently as possible since there are thousands of files to process. The parameters we need to access exist on the root parameters collection of each drawing. All of the drawings will be located in a single folder on the local file system. The program should be flexible enough so that we can easily specify a list of parameter names whose values should be retrieved from each drawing without having to modify the code each time the script is used.
I am not going to explain how the script works because the focus of this article is running a batch not this specific script. However, I did add some brief comments throughout the code to aid in understanding what the macro is doing. Take a little time and read through it because there are some interesting things in it.
If you want to try the script yourself either in interactive mode or batch, simply make some drawings that have one or more parameters in their root parameters set. Then just edit the variables at the start of the script to specify the parameter name(s) you want to look for and the folder where the drawing files exist.
I want to point out that you should always test your script in interactive mode first before running it in batch mode. As I mentioned earlier, you will not see messages or receive any feedback from the run unless your code outputs any error information to a text file or the command window. So for our scenario, a dozen or so files were placed in a folder and the script was run to make sure it works properly before moving on to the batch.
Lets look at what goes into this command string for a couple of common scenarios. In each case you need to first specify where the CATIA executable is located (CNext.exe). After that, you specify options by typing dash (-) followed by the name of the option followed by a space then the value for the option.
In most cases you will probably want to start CATIA with the custom environment that is used at your company, so you will use the second example above. Below is an example command line string (note that you will have to customize it for your own company specific installation). Save this string in a text file and save it with a .bat extension. To test it, simply double click on this .bat file and CATIA should start with the options specified and run the script.
You can launch a CATIA V5 batch by starting CNEXT.exe directly or you can use the CATSTART.exe process. The command line syntax is slightly different for each method so I have listed some examples for each below.
The above script was run on a set of drawings both in batch mode and interactive mode and average time per drawing was calculated for both scenarios. In interactive mode, the script averaged about 2.6 minutes per drawing. Most of this is due to the load time to open the drawing then load it all into memory and update the display with all of that information. The actual task we are automating (reading the parameter values) probably only takes a small fraction of a second but it takes considerable time to load the data in interactive mode.
In this article my goal was to expose you to running a script in batch mode. I think the basic information I provided should be enough to setup most batch scenarios. Finally, I hope the real world example and the results it produced were interesting to read about and maybe you can benefit from using a batch in the future.
I was very interesting by this article
first reason , all your articles are always very good
second reason, I run many batch on catia data , so I was very exited about the performance boost between interactive and batch mode (At the moment , I have always run batch with Catia Intercative session)
That should work fine. Start by recording a macro of yourself creating a new part and making the geometry you want manually. While the macro is still being recorded, go to File-SaveAs and change the file type to the one you want and click OK. Finally, close the part then stop the macro recording. Next, play the macro and see if it runs right and produces the data you expect. You might also want to add some loops, etc. depending on your goals. Once you have the macro running correctly, then follow the instructions in this article to set it up as a batch. Good luck!
In this course, you will learn about Vb Scripting Beginner's Basics for Catia V5. You will learn about scripting language, Msgbox, Inputbox, declaration of variables, variable types and research, data types, subtypes, adding two numbers, conversion function, calculation of simple interest, arithmetic operators, comparison operators, logical operators, concatenate operators, greater number, operator execution order, control statements, simple if and if else, checking if a number is odd or even, billing application, nested if, select case statements, for loops, factorial with limited input, printing 100 odd numbers b/w 100-200, checking is a number is prime, Fibonacci series, adding digits of a given number, custom toolbar and icon, finding file path, do loop, while loop, FileSelectionBox, and much more.
We've all seen the "hype" around ChatGPT etc etc but I'm curious about using the OpenAI infrastructure/API to generate CAD. There's an example here of integration to Fusion 360 but it obviously has a ways to go before it's effective. In personal experience, I've experimented by asking ChatGPT to write code for OpenSCAD, then copy/pasted that to OpenSCAD, then exported to F360 to more modification... and I'll be honest it's had mixed results but it kind of works.
Does Autodesk have any developers working to create a "fork" of OpenAI/ChatGPT and make a legitimate integration to Fusion 360? I'm envisioning a chat-like feature where designer would communicate what they desire (hopefully in professional terms, not as a layman!) and follow up with modifications.
3a8082e126