Monday, October 24, 2011

How to add amacro icon to a toolbar in CATIA V5?

There are multiple ways to initiate a CATScript macro in CATIA V5. Did you know that it is possible to invoke your macro through a tool bar icon? How do you create an icon for your macro? Go to tools >customize >commands > macros > show properties. Next, simply define a logo for your macro by picking one from the 180 plus icons to choose from (or browse to your own custom made icon) and then drag and drop it into the menu bar where you want it. It's that easy. So now you should have three ways to run your VBA CATScripts: going to Tools>Macro>Macros, hitting Alt+F8, or by clicking on your icon in a toolbar.

Saturday, October 22, 2011

Let's Go Design Episode #5: Chassis Design and Assemblies



In the last episode, we discussed weldment features and sketch techniques. This time, we move closer to the final overall CAD design of our Hot Rod Baby Buggy. We watch as Jeremy hot-wires the golf cart motors to show how the aluminum tracks perform flawlessly.

In this episode, Jeremy takes us through:

The Overall Design: Jeremy shares 80% of the CAD design, complete with a 3D model of a dad placed in the center. He shows us the fenders, talks about key components underneath the buggy, and creates a battery compartment using sheet metal.

Sustainability: We use SolidWorks® Sustainability to compare material selections for the fenders of our buggy - sheet metal vs. plastic.

The Assembly: Jeremy shows the basic build and sub-assemblies. He puts together the steel base weldment, aluminum floor, components from the golf cart’s electrical system and finally powers the tank treads.

Watch Episode #5 now at LetsGoDesign.tv

Thursday, October 20, 2011

How to write a vb script to take screen shots within CATIA?

I've finished my image capture macro and have made it available to download. This CATscript takes a screenshot and allows you to name the picture file whatever you would like. Here are all the steps included in the macro, which can easily be modified if need:

1. Reframe on part
2. Zoom in
3. Turn off specification tree
4. Toggle compass
5. Change background color to white
6. Clear selection
7. Increase to full screen to obtain maximum resolution
8. Enter the name to save the picture as
9. Take screenshot
10. Save as .bmp file
11. Restore original background color
12. Toggle compass
13. Turn on specification tree
14. Restore original screen size

All these steps are complete in about two seconds. For even more flexibility you can change the extension into an input box that way each user could import the type of file they would like to save their picture as (.bmp, .jpeg, .png, etc.) You can turn off the iso view or zoom in steps by simply adding a single aprostrophe to the beginning of each line of respective code. The best to make this work may be to create a new macro file in CATIA and copy and paste the code from my text document into the macro editor and then save it, that way CATIA will automatically save and recognize it as a .CATscript file. Please let me know if you need any further help.

Click here to download.



I also created a macro to export properties from CATIA parts into an Excel spreadsheet, which you can check out here.

 CATIA Image Capture Macro .CATScript download

Wednesday, October 12, 2011

How to automatically take a picture using a catscript

Catscripts can be a powerful tool when needing to automate processes in CATIA V5. One common process which is helpful to automate is when you want to take a screenshot of a .catpart or .catproduct with a white background (to put into a powerpoint or Excelfile). This sounds like a daunting task if you are new to VB programming. I find the best thing to do is to break down this large, challenging project into smaller, more manageable tasks. Let's think about each stage we want the macro to complete:
1. Reframe on the part
2. Hide the specification tree
3. Change the background color to white
4. Take a screenshot and save it as a JPEG file
5. Change the background display color back to what it was
6. Unhide the specification tree
Now, if we take each of those steps one at a time it's not so big of a problem. I'll be explaining each of these steps in the next couple of posts starting with step one today- how to automatically reframe (or fit all in) on the part in CATIA. We'll create each step individually then combine them all into one CATScript at the end.  This tutorial will also help you learn visual basic programming and will help you write your own CATScripts.
First, go to Tools>Macro>Macros. Click "Create" and change the Macro language to CATScript. Enter a name for your macro. Copy and paste the following code.

Language="VBSCRIPT"
Sub CATMain()


Dim specsAndGeomWindow1 As Window

Set specsAndGeomWindow1 = CATIA.ActiveWindow


Dim viewer3D1 As Viewer

Set viewer3D1 = specsAndGeomWindow1.ActiveViewer


viewer3D1.Reframe


Dim viewpoint3D1 As Viewpoint3D

Set viewpoint3D1 = viewer3D1.Viewpoint3D


End Sub

What does all of the above actually mean? A CATIA VBA program or “macro” consists of a
“Subroutine” named CATMain(), called out with the line Sub CATMain(). Variables are “dimmed” (declared) and then “set” (given a value). Variables are “dimmed” as a type. A type is either a “primitive” type (single, double, integer, string, etc.) or an object type (more complex). 

Stay tuned to learn more in our next article...