Configuration 5
of KwrProfilesDesignTable.xls
applied to
KwrBottleProfiles.CATPart
A macro is a way to store instructions intended to be repeated many times. It can also be a good means to store intricate interactions or describe a document in a clear text file easy to edit and requiring less memory than a document. Knowledgeware automation provides you with a way to store operations in the form of a .CATScript file. In this chapter we discuss the macro used to create the assembly in About Rule Firing, then we introduce the knowledgeware automation objects. We will not dwell on the part which consists in creating an assembly as this guide deals more specifically with knowledgeware techniques. If you need a brush up on how to create an assembly, see the Assembly User's Guide.
A CATScript macro is written in a language similar to the Visual Basic language. You can record a CATScript macro, then replay it later on or write it from scratch. The recommended method is to start from a record then, depending on your needs, edit and modify the pre-recorded macro.
To record the macro used in About Rule Firing:
Close all the documents open in your session.
Select the Tools->Macro->Start Recording... command from the standard menu bar then in the Record Macro dialog box displayed, specify the path of an external file. Press the Start button to start the macro recording. From now on, all the interactions are recorded in the CATScript file you have just specified.
Select the Start->Infrastructure->Product Structure command from the standard tool bar. The product1 root product is created.
Select the Components->Existing Component... command from the root product contextual menu to add the KwrTipCreateAssembly.CATPart component then the KwrCap1.CATPart component.
In the Assembly Design workbench, specify an offset
constraint of 1 mm between the Plane.1 plane of the bottle and the Pad.2
surface. Refer to the figure below to see how to select the elements to be
constrained.
Specify a coincidence constraint to make the cap and the bottle axes coaxial. For more information, refer to the Assembly User's Guide. If need be, update the document.
Select the Tools->Macro->Stop Recording command from the standard tool bar. This closes the file which records all the interactions described above.
The CATScript macro you have just recorded is similar to the one below. For the sake of clarity and to make lines shorter:
|
|
Before replaying this macro, you should replace the path specified as the argument of the AddComponentsFromFiles method.
|
This macro can be started from a rule (see About Rule Firing) or directly by selecting the Tools->Macro->Run command from the standard menu bar.
There is a lot to be learned before you can write a complete macro in Visual Basic, but once you understand the basics of the language, you can be up and running in no time at all. Visual Basic is based on objects which have their own methods and properties. To set the value of a property, you follow the reference to an object with a period, the property name, an equal sign (=), and the new property value. At first sight, it is simple. The tedious thing when you have no previous programming skills is that the macro you record is a raw macro with objects and properties chained in one statement as in the extract below:
|
When you tackle automation, there are two ways to proceed:
|
|
Generic naming is a CATIA technique which creates a label whenever an element has been selected interactively. This label is a coded description of the selected element.
This generic naming label appears when you record a .CATScript macro by
using the
If you perform interactions such as selecting an edge or a face, the value
specified for the arguments of some methods are written using generic naming.
When you take a look at the macro, you can see arguments which are neither
Visual Basic objects nor usual data. These arguments are written in a form
similar to the simple example below:
Brp:(Pad.1:0(Brp:Sketch.1;1)).
You don't have to worry much about generic naming as the definitions relying on this technique are automatically inserted in CATIA macros.
The objects below can be created and managed in a .CATScript macro:
|
|
|
|
The knowledgeware features are created from the collection which refers to their type. For example, to create a relation in a Part type feature, you must first retrieve the collection object containing the Part relations by using the Relations method on the Part object. To create a parameter in a Part, you must retrieve the collection object containing the Part parameters by using the Parameters method on the Part object.
To manipulate a knowledgeware object, you just have to use the methods and properties of the relevant object.
Open the KwrTipCreateAssembly.CATPart document and run the KwrRelations.CATScript macro.
|
This macro displays the list of relations within the document, changes the design table configuration and updates the document.
Tips |
Operations that Cannot be Recorded
|
Retrieving Collections
|
Retrieving a Collection Object
|