Catia Knowledge Advisor Journaling Guide
-
Upload
krokuss-emil -
Category
Documents
-
view
279 -
download
2
Transcript of Catia Knowledge Advisor Journaling Guide
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
1/46
Knowledge AdvisorJournaling Guide
Preface
Getting StartedObject Library
Use Cases
Glossary
Dassault Systmes 1994-2000.
All rights reserved.
http://e%7C/users/cre/adele/crecxr4/CATEnglish/commain.doc/src/spenot.htmhttp://e%7C/users/cre/adele/crecxr4/CATEnglish/commain.doc/src/conventions.htm -
7/30/2019 Catia Knowledge Advisor Journaling Guide
2/46
Preface
elcome to CATIA Knowledgeware automation, a fast and easy way to write macros andeate simple applications to be plugged to CATIA. Whether you are an experiencedofessional or a brand new to programming languages, CATIA knowledgeware provides yoth a set of tools to simplify, automate and improve your daily life as a CATIA end-user.
his preface gives you some information to brush-up on the concepts used in Visual Basic oBScript and introduce you to the knowledgeware automation objects. If you are an absoluteginner in programming languages, it is much better to go to the http://www.microsoft.comte, then refer to the CATIA Infrastructure Journaling Guide.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
3/46
RoadMap
his guide provides the basis for understanding how to create macros using knowledgewareatures. These knowledgeware features are supplied in the Infrastructure product (paramermulas and design tables) as well as in the Knowledge Advisor product (rules and checks
o keep up with the material presented in this guide, it is better if you have a background in
cript languages. However, the Use Cases provided as samples are fully commented andhould help you understand how to proceed to write simple macros as well as fully-fledgedacros.
If you are a beginner
Don't skip the Getting Started if you are a beginner. It is a knowledgeware-oriented
example described in the form of two interactive tasks. You just record a macro, takelook at the code generated, modify it then replay it. It is very basic.If you already get by in Script languages
If you already dabble in script languages, you can get straight to the Object Library o
the Use Cases.
ost knowledge applications rely on the Infrastructure and Part Design products. Forformation refer to the CATIA Infrastructure and CATIA Part Design Journaling Guides.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
4/46
Automation in a Nutshell
ATIA is an OLE Automation server for Windows NT which allows you to record and replayacros for both Windows NT and UNIX.
he macros recorded from the Tools->Macro menu are generated in a syntax very close to sual Basic language. Statements such Dim... As ... which are not supported in VBScript a
upported by the CATIA macro language so that a macro recorded on Windows NT can beplayed on UNIX or the reverse.
utomation is a feature of the Microsoft Component Object Model (COM), andustry-standard technology that applications use to expose their objects to developmentols, macro languages, and other applications that support Automation. For example, CAT
nowledware exposes a parameter, a formula, a rule or a check, each as a different type ofbject. A word processor exposes objects such as an application, a document, a paragraphentence, a bookmark, or a selection.
hen an application supports Automation, the objects the application exposes can beccessed by Visual Basic. To manipulate these objects, you have to invoke methods on thebject or get / set the object's properties.
o create an Automation application, you need know about:
the macro language itself (VBScript or Visual Basic for example)the properties and methods supported by the application objects. The objects with thproperties, and methods supported by an application are usually defined in theapplication's object library.
Properties and Methods
n object represents an element of an application, such as a worksheet, a cell, a chart, a foa report. In Visual Basic or VBScript code, you must identify an object before you can ap
ne of the objects methods or change the value of one of its properties.
property is an attribute of an object that defines one of the object's characteristics, such aze, color, or screen location, or an aspect of its behavior, such as whether it is enabled orsible. To change the characteristics of an object, you change the values of its properties.
o set the value of a property, follow the reference to an object with a period, the propertyame, an equal sign (=), and the new property value. For example, the following statementodifies the minimum tolerance value of a Length object by setting the MinimumToleranceoperty.
ength0.MinimumTolerance = 1
ot all properties can be set. There are some that are read-only.
ou can retrieve information about an object by returning the value of one of its properties.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
5/46
llowing statement uses a message box to display the maximum tolerance of a Lengtharameter:
sgBox(length0.MaximumTolerance)
method is an action that an object can perform. The following statement uses the Renamethod to rename a parameter object:
arameter.Rename("String1")
Collections
collection is an object that contains several other objects, usually, but not always, of theame type. In Microsoft Excel, for example, the Workbooks object contains all the openorkbook objects. In Visual Basic, the Forms collection contains all the Form objects in an
pplication. In CATIA knowledgeware the Relations object contains all the knowledgewareatures of relation type (formulas, rules, checks and design tables).
collection is always denoted as a plural name to help easily recognize a collection among
her objects. The collection index begins at 1, and not 0. Usually, an object in the collectionached using its index, but it can also be reached using the name you assign to it. Thellowing statement uses the item method of the Collection object to retrieve thewrMacro0\Volume.1 parameter from its name, myPar1 being a Parameters object.
yPar1.item("KwrMacro0\Volume.1")
ATIA collections are described by the Collection object. Refer to the 'CATIA Infrastructureournaling Guide'for more information.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
6/46
CATIA Knowledgeware AutomationObjects
he CATIA knowledgeware automation objects are described in the figure below.
r inciples
To Create:The knowledgeware features are all created from the collection which refto their type. For example, to create a relation in a part type feature, you must firstretrieve the collection object containing the part relations by using the Relations methon the Part object. To create a parameter in a part, you must retrieve the collectionobject containing the part parameters by using the Parameters method on the Partobject.To Modi fy:To manipulate a knowledgeware object, you just have to use the methodand properties of the relevant object.
Click any of the links todisplay therelated object description
To create a parameter Parameters collection
To manipulate a parameter Parameterobject
To Create a Formula Relations collection
To manipulate a formula Formula Object
To create a Rule Relations collection
To manipulate a Rule Program Object
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
7/46
To Create a Check Relations collection
To manipulate a Check Check Object
To create a Design Table Relations collection
To manipulate a Design Table DesignTable object
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
8/46
Getting Started
eginners in CATIA Automation can create useful applications by learning just a few of theeywords. If you don't know anything about script languages, just carry out the scenario beldoesn't really teach you how to program but it is intended to give you a feeling for what aacro looks like.
o really get started programming:
take a look at any book dealing with the subject. 'Step by Step' books available fromMicrosoft Press can be recommended but your corner bookshop is probably full of booabout Visual Basic for beginners.
1.
don't hesitate to search for information on specialized Internet sites2.
then refer to the CATIA Infrastructure Journaling Guide.3.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
9/46
Recording and Replaying a Macro
Explains how to record and replay a macro which:
creates a new parameter,renames and valuates this parameter
and creates a formula constraining one of the document geometricparameter.
Create a hollow cylinder similar to the one below and save this initialdocument under the KwrMacro0.CATPart name.
The partparameters should be specified as follows:
Pad First Limit: 100mm
Pad Second Limit: 0mm
HoleType: 'Simple'
Hole Extension: 'Up To Last'
Hole Diameter: 50mm
1.
Select the Tools->Macro->Start Recording... command from the standardtool bar. The Record Macro dialog box is displayed.2.
Select External File in the 'Macro in' list, then specify a path in the 'MacroName' field (for example: e:\users\...\KwrMacro.CATScript).
3.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
10/46
Press Start. From now on, all the interactions will be recorded in the macroyou have just specified.
Start of interact ion record ing
Click the icon..
In the "Formulas" dialog box, select the Length item with 'SingleValue' in the 'New Parameter of type' list, then click 'New Parameterof type'. A new parameter with Length.1 name appears in 'Edit namevalue or formula'.
b.
In 'Edit name, value or formula', replace the Length.1 name withReference_Length and assign the 70mm value to this parameteThen click Apply.
c.
In the parameter list select the PartBody\Pad.1|FirstLimit\Lengthparameter. Click Add Formula and enter the formula below in theformula editor:Reference_Length / 10.
d.
Click OK.This is what you should see onscreen:e.
4.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
11/46
Select the Tools->Macro->Stop Recording command from thestandard tool bar. This closes the KwrMacro.CATScript file whichrecords all the interactions described above.
f.
End o f interact ion recording
Close your document but don't save the modifications under the initialdocument name.
5.
Re-open your initial document (KwrMacro0.CATPart)6.
Select the Tools->Macro->Macros... command from the standard tool bar.7.
In the Macro dialog box, select the macro you have just recorded(KwrMacro.CATScript) and click Run to replay all the interactions recordedin the macro.
8.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
12/46
diting and Modifying a Macro
Gives you some basics about how to edit and modify a macro.
Re-open the initial KwrMacro0.CATPart document.1.
Edit the KwrMacro.CATScript file either by selecting the Tools->Macro->Edit... command from t
standard tool bar or by using any available editor. A VBScript procedure similar to the one belowdisplayed (comments have been added and some variables created):
Language="VBSCRIPT"
Sub CATMain()
' Declare the Length0 variable as a Dimension type
Dim Length0 As Dimension
' Retrieve the root of your active document
' and access the 'Parameters' feature
Set Doc1 = CATIA.ActiveDocument.PartSet Par1 = Doc1.Parameters
' Create a Dimension type parameter,
' rename it
' and modify its value
Set Length0 = Par1.CreateDimension("Length.1", "LENGTH", 0.000000)
Length0.Rename "RefLength"
Length0.Value = 70.000000
' Retrieve the PartBody feature
Dim Body1 As AnyObject
Set Body1 = Doc1.Bodies.Item("PartBody")
' Retrieve the Pad.1 feature
Dim Pad2 As AnyObject
Set Pad2 = Body1.Shapes.Item("Pad.1")
' Constrain the Pad.1 First Limit with the Formula.1 relation
' 1 - Declare the Formula3 variable as a Formula type
' 2 - Get the Relations feature of the active document
' 3 - Get the Pad.1 First Limit
' 4 - Create the formula below:
' PartBody\Pad.1|FirstLimit\Length=RefLength/10 formula
Dim Formula3 As FormulaSet Rel1 = Doc1.Relations
Set Di1 = Pad2.FirstLimit.Dimension
Set Formula3 = Rel1.CreateFormula("Formula.1","", Di1, "RefLength")
Formula3.Modify "RefLength / 10"
' Update the document
CATIA.ActiveDocument.Part.Update
End Sub
2.
In the VBScript source above, modify the Formula.1 name and add a new formula defining the P3.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
13/46
second limit:
Language="VBSCRIPT"
Sub CATMain()
Dim Length0 As Dimension
Set Doc1 = CATIA.ActiveDocument.Part
Set Par1 = Doc1.Parameters
Set Length0 = Par1.CreateDimension("Length.1", "LENGTH", 0.000000)
Length0.Rename "RefLength"
Length0.Value = 70.000000
Dim Body1 As AnyObject
Set Body1 = Doc1.Bodies.Item("PartBody")
Dim Pad2 As AnyObject
Set Pad2 = Body1.Shapes.Item("Pad.1")
Dim Formula3 As Formula
Set Rel1 = Doc1.Relations
Set Di1 = Pad2.FirstLimit.Dimension
' Modify the formula creation - the same result is obtained
Set Formula3 = Rel1.CreateFormula("Formula.1","", Di1, "RefLength / 10"
' Rename Formula.1
Formula3.Rename "F1"
' Add a new formula
Dim Formula4 As Formula
Set Rel1 = Doc1.Relations
Set Di2 = Pad2.SecondLimit.Dimension
Set Formula4 = Rel1.CreateFormula("Formula.2","", Di2, "RefLength * 10"
' Rename the new formulaFormula4.Rename "F2"
CATIA.ActiveDocument.Part.Update
End Sub
Save this macro under the KwrMacro1.CATScript name.4.
Run the KwrMacro1.CATScript new macro on your initial document. This is what you can seeonscreen:
5.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
14/46
The Formula.1 has been renamed, the new formula F2 has been added to the document and th
whole document is updated.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
15/46
Object Library
ere is the hierarchy of knowledgeware automation objects.
IUnknown
|
+---CATBaseUnknown|
+---CATBaseDispatch
|
+---AnyObject
| |
| +-----Parameter
| | |
| | +---------IntParam
| | |
| | +---------BoolParam
| | |
| | +---------RealParam
| | |
| | +---------StrParam
| | |
| | +---------Dimension
| | |
| | +--------Length
| | |
| | +--------Angle
| |
| +-----Relation
| |
| +---Formula
| |
| +---Rule
| |
| +---Check| |
| +---DesignTable
|
+-------Collection
|
+---Relations
|
+---Parameter
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
16/46
Objects such as Dimension, Formula and Rule are not described because they provideither properties nor methods. They are manipulated by the properties and methods of thearent object.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
17/46
Parameter Object
rived Objects
efinition
an end-user, you can add comments to a parameter and decide to hide a parameter from the specification view.
eminder
o hide a parameter or add a comment to a parameter,
u just have to right-click the value field in any
rameter edition box, then select the Edit Comment... orde command from the contextual menu.
rameters are described by the Parameter object which provides you with properties to determine whether a parame
dden or not and to retrieve the comment associated with the parameter.
rameters with multiple-values cannot be managed in CATIA macros.
roperties
rameter.Hidden
Returns True if the parameter is hidden, otherwise returns False.
rameter.Comment
Returns the comment associated with the parameter.
ethods
rameter.Rename(newparameterName)
Renames the parameter.
xample
e Managing Hidden Parameters.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
18/46
Parameter Object
erived Objects
tParamObject
oolParamObject
rParamObjectealParamObject
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
19/46
ntParam Object
Definition
n IntParam object describes a parameter whose value can only be an integer.
roperties
arameter.Value
Returns or sets the parameter value.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
20/46
BoolParam Object
efinition
boolean is a parameter whose value can only be True or False.
operties
rameter.Value
Returns or sets the value of a boolean parameter.
xample
e extract below creates the "Ischecked" parameter of boolean type.
...
m BoolParam0 As BoolParam
m myDoc As Document
t myDoc = CATIA.ActiveDocumentm myParamCol As Parameters
t myParamCol = myDoc.Part.Parameters
t BoolParam0 = myParamCol.CreateBoolean("Boolean.1", True)
olParam0.Rename "IsChecked"
olParam0.Value = False
...
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
21/46
StrParam Object
Definition
n StrParam is an object which describes a string type parameter.
roperties
arameter.Value
Returns or sets the value of a string parameter.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
22/46
RealParam Object
erived Objects
Definition
RealParam object describes a parameter whose value can only be a real.
roperties
rameter.Value
Returns or sets the value of the real parameter.
rameter.RangeMin
Returns or sets the lower bound of a real parameter.
rameter.RangeMaxReturns or sets the upper bound of a real parameter.
Example
he extract below specifies a lower(minimum) bound of 10.0 and an upper(maximum) bound of 30.0.
.
im RealParam0 As RealParam
im myDoc As Documentet myDoc = CATIA.ActiveDocument
im myParamCol As Parameters
et myParamCol = myDoc.Part.Parameters
et RealParam0 = myParamCol.CreateReal("Real.1", 0.000000)
ealParam0.Value = 12.500000
ealParam0.RangeMin = 10.000000
ealParam0.RangeMax = 30.000000
fter the macro is finished running, edit the Real.1 parameter lower and upper bounds.
http://e%7C/users/cre/adele/crecxr4/KwrEnglish/kwrjg.doc/src/basjgRealParamD.htmhttp://e%7C/users/cre/adele/crecxr4/KwrEnglish/kwrjg.doc/src/basjgRealParamD.htm -
7/30/2019 Catia Knowledge Advisor Journaling Guide
23/46
his is what you can see onscreen when you select the Range-> Edit... command:
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
24/46
Length Object
Definition
Length object describes a parameter whose value can only be a length. A length object derives frome Dimension object which itself derives from the RealParam object. A dimension object is created
e CreateDimension method. To manipulate a Length object, you have to use the methods and
operties provided by the RealParam object.
roperties
arameter.MinimumTolerance
Returns the minimum tolerance of a Length object.
arameter.MaximumTolerance
Returns the maximum tolerance of a Length object.
Example
hen applied to a CATPart document, the extract below creates the W=10mm and A=45deg dimens
rameters.
...
im RealParam0 As RealParam
im myDoc As Document
et myDoc = CATIA.ActiveDocument
im myParamCol As Parameters
et myParamCol = myDoc.Part.Parameters
et Length0 = myParamCol.CreateDimension("W","Length", 10.00)
et Angle0 = myParamCol.CreateDimension("A","Angle", 45)
sgbox("Minimum Tolerance for Length " & Length0.MinimumTolerance)
sgbox("Maximum Tolerance for Angle " & Angle0.MaximumTolerance)
...heck that the values displayed in the message boxes are the same as those specified in the
ools->Options->Tolerance tab.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
25/46
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
26/46
Angle Object
Definition
nAngle object describes a parameter whose value can only be an angle. An angle object derives fro
e Dimension object which itself derives from the RealParam object. A dimension object is created
e CreateDimension method. To manipulate an Angle object, you have to use the methods and
operties provided by the RealParam object.
roperties
arameter.MinimumTolerance
Returns the minimum tolerance of an Angle object.
arameter.MaximumTolerance
Returns the maximum tolerance of an Angle object.
Example
hen applied to a CATPart document, the extract below creates the W=10mm and A=45deg dimens
rameters.
...
im RealParam0 As RealParam
im myDoc As Document
et myDoc = CATIA.ActiveDocument
im myParamCol As Parameters
et myParamCol = myDoc.Part.Parameters
et Length0 = myParamCol.CreateDimension("W","Length", 10.00)
et Angle0 = myParamCol.CreateDimension("A","Angle", 45)
sgbox("Minimum Tolerance for Length " & Length0.MinimumTolerance)
sgbox("Maximum Tolerance for Angle " & Angle0.MaximumTolerance)...
heck that the values displayed in the message boxes are the same as those specified in the
ools->Options->Tolerance tab.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
27/46
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
28/46
Relation Object
Definition
he Relation object provides you with properties and methods to access the knowledgeware relationta. This object does not allow you to create a relation.
roperties
lation.Value
Returns the relation definition (the expression).
lation.Comment
Returns the comment associated with the relation.
lation.ActivatedReturns True if the relation is activated, otherwise returns False.
lation.Hidden
Returns True if the relation is hidden, otherwise returns False.
Methods
lation.Activate()
Makes a relation active.
lation.Deactivate()
Deactivates a relation.
lation.Rename(newName)
Replaces the relation name with the one specified in the argument.
lation.Modify(newRelation)
Replaces the relation with the one specified in the argument.
ExampleOpen the initial document ofRecording and Replaying Macros and add two formulas constrain
Volume.1. Formula.1 is initially deactivated.
1.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
29/46
Run the macro below on this document
Language="VBSCRIPT"
Dim myDoc As DocumentSet myDoc = CATIA.ActiveDocument
Dim myPar1 As Parameters
Set myPar1 = myDoc.Part.Parameters
Set myRel1 = myDoc.Part.Relations
Dim For0 As AnyObject
Set For0 = myRel1.Item("Formula.1")
Dim For1 As AnyObject
Set For1 = myRel1.Item("Formula.2")
' Display the Formula.1 expression
MsgBox(For0.Value)
' Deactivate Formula.2 and activate Formula.1
For1.Deactivate
For0.Activate
' Modify Formula.1
For0.Modify("R1*10m*0.5m")
' Rename the formulas
For0.Rename("F1")
For1.Rename("F2")
CATIA.ActiveDocument.Part.Update
This is what you can see onscreen.
2.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
30/46
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
31/46
heck Object
efinition
heck object inherits the properties and methods of the Relation object. In addition, the severity property allows you to determine w
heck has been declared ofsilent, warning or information type.
manipulate checks, you must have the Knowledge Advisor product installed.
operties
ck.Severity
Returns or sets the severity of the check. The check validity is an integer whose value is 1 for Silent, 2 for Information, 3 for
Warning.
xample
nguage="VBSCRIPT"
m Check0 As Checkm myDoc As Document
t myDoc = CATIA.ActiveDocument
t myRel1 = myDoc.Part.Relations
t Check0 = CmyRel1.CreateCheck( "Check.1",_
heck.1 is not valid",_
artBody\Pad.1\FirstLimit\Length > 50mm" )
eck0.Rename "Check.1"
eck0.Severity = 2
u can run this macro on any part provided it has a FirstLimit\Length parameter.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
32/46
Design Table Object
Definition
he Design object provides you with properties and methods to access design table data. This object ot allow you to create a design table.
roperties
signtable.CopyMode
Returns the value of the "Duplicate data in CATIA model" check box of the design table dialo
box. Returns True if the design table data have been duplicated in the CATIA document.
Otherwise, returns False.
signtable.Configuration
Returns or sets the active configuration number.
signtable.ConfigurationsNb
Returns the number of configurations in the design table.
Methods
signtable.AddAssociation(param, sheetColumnName)
Associates the parameter specified in the first argument with the column whose name is specif
in the second argument.signtable.RemoveAssociation(sheetColumnName)
Removes the association created with the column whose name is specified in the argument.
signtable.AddNewRow()
Adds a new row in the design table. The new row contains the active parameter values. If you
deactivate the design table, modify the document parameters, then add a new row, the values
contained in the new row will be those you have just modified in the document and not those o
the last selected configuration.
Example
ee Managing Design Tables, Rules and Checks.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
33/46
Relations Collection
Definition
he Relations collection object provides you with methods to create and manage all type of relationshe knowledgeware relations are:
the formulasq
the rulesq
the checksq
and the design tables.q
roperties
he object has no properties but inherits the Collection object properties.
Methods
lations.CreateFormula(formulaName, comment, parameter, expression)
Creates a formula. The parameter to be constrained by the formula is specified as the third
argument.
lations.CreateProgram(ruleName, comment, ruleBody)
Creates a rule.
lations.CreateCheck(checkName, comment, checkBody)
Creates a check.
lations.CreateDesignTable(designtableName, comment, copyMode, ExcelSheetFilePath)
Creates a design table.
lations.Item(relationRank)
Returns the relation specified in the argument.
lations.Remove(relationName)
Removes the relation specified in the argument.
Example
ee Creating and Manipulating Parameters and Formulas and Managing Design Tables, Rules and
hecks.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
34/46
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
35/46
Parameters Collection
Definition
he Parameters collection object provides you with methods to create parameters.
roperties
he object has no properties but inherits the Collection object properties.
Methods
arameters.CreateString(parameterName,parameterValue)
Returns a string parameter with the name and value as specified in the arguments.
arameters.CreateReal(parameterName,parameterValue)
Returns a real parameter.
arameters.CreateInteger(parameterName,parameterValue)
Returns an integer.
arameters.CreateBoolean(parameterName,parameterValue)
Returns a boolean.
arameters.CreateDimension(parameterName,parameterType,parameterValue)
Returns a dimension type parameter with the name, type and value as specified in the argumenarameters.Item(parameterRank)
Returns the parameter specified in the argument.
arameters.Remove(parameterName)
Removes the parameter specified in the argument.
Example
ee Creating and Manipulating Parameters and Formulas.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
36/46
Use Cases
his guide provides three fully-fledged samples to help you begin learning CATIA automatioinciples. Each sample is broken into steps, and complete code is supplied for each step. T
omments in the first part explain how to run the macro.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
37/46
**********************************************************
MANAGING HIDDEN PARAMETERS
Macro delivered: KwrMacParameters.CATScript
**********************************************************
Abstract:
--------
This macro:
1 - scans the list of parameters of a CATPart document
2 - determines whether a parameter is hidden
3 - displays the list of hidden parameters
along with their values and comments
4 - asks you to modify the status (Hidden->Show) of the parameters
and to re-run to macro.
Running the macro
-----------------
It is better to run this macro on the KwrMacroHiddenParam.CATPart document whic
delivered as a CATIA Infrastructure sample. This document contains hidden
rameters.
However, you can run this macro on any CATPart document
b CATMain()
Retrieve your active document - CATIA is your application
You get the active document by using the ActiveDocument property
on your application object
Dim myDoc As Document
Set myDoc = CATIA.ActiveDocument
Check whether the document is a CATPart
Analyse the pathname of the document
If the extension .CATPart is not found, a message is displayed
but you exit the procedure
InStrRev is a standard VB function
Dim strPartName, strCATPartstrPartName = myDoc.Name
if (InStrRev(strPartName,".CATPart",-1) = 0)_
then MsgBox("Your document should be a .CATPart") : Exit Sub
Retrieve the collection object which contains
all the document parameters
Dim myParamCol As Parameters
Set myParamCol = myDoc.Part.Parameters
Declare the variables to be used in the message box
which displays the hidden parameters
Dim strRel0 As String
Dim strRel1 As String
Dim strRel2 As String
Dim HiddenNumber As Integer
strRel0 = "Name Value Comments"
strRel1 = "Here is the list of hidden parameters" & vbCrLf & strRel0
Scan the paraneter list,
test whether the value returned by the Hidden property is "True"
Count the number of hidden parameters
For Each myPar in myParamCol
if (myPar.Hidden = "True")_
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
38/46
then strRel1 = strRel1 & vbCrLf & myPar.Name & " " & myPar.Value &_
" " & "'" & myPar.Comment & "'" : HiddenNumber = HiddenNumber + 1 : myPar.Va
"true"
Next
Display the list of hidden parameters.
The parameter names, values and comments
are displayed in a message box.
Ask you to modify interactively the status of the
parameters and to re-run the macro.
strRel2 = "NOW, SHOW THE HIDDEN PARAMETERS" &_vbCrLf & vbCrLf & "IN THE f(x) DIALOG BOX," &_
vbCrLf & " 1 ) RIGHT-CLICK THE PARAMETER VALUE FIELD " &_
vbCrLf & " 2 ) SELECT THE SHOW COMMAND FROM THE CONTEXTUAL MENU" &_
vbCrLf & vbCrLf & "THEN RE-RUN THE MACRO "
If (HiddenNumber > 0) Then MsgBox(strRel1) : MsgBox(strRel2) : Exit Sub
MsgBox "There are no hidden parameters in this document"
d Sub
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
39/46
*************************************************
CREATING AND MANIPULATING PARAMETERS AND FORMULAS
Macro delivered: KwrMacParmAndForm.CATScript
*************************************************
Abstract:
--------
This macro explains how to:
1 - retrieve the Relations and Parameters objects
2 - create String, Integer and Length type parameters3 - create formulas and display their list in a message box.
Running the macro
-----------------
You can run this macro on the KwrMacro0.CATPart document which is
delivered as a CATIA Infrastructure sample, but this macro operates
on any CATPart document
b CATMain()
Retrieve your active document - CATIA is your application
You get the active document by using the ActiveDocument property
on your application object
im myDoc As Document
et myDoc = CATIA.ActiveDocument
Check whether the document is a CATPart
Analyse the pathname of the document
If the extension .CATPart is not found, a message is displayed
but you exit the procedure
InStrRev is a standard VB function
im strPartName, strCATPart, myPos
trPartName = myDoc.Namef (InStrRev(strPartName,".CATPart",-1) = 0)_
then MsgBox("Your document should be a .CATPart") : Exit Sub
Retrieve the collection object which contains
all the document relations
myDoc.Part is satisfied as the document extension
has been checked
Note: Statements below could not be applied to a CATProduct
im myRelCol As Relations
et myRelCol = myDoc.Part.Relations
or Each myRel in myRelColmyRelCol.Remove myRel.Name
ext
Retrieve the collection object which contains
all the document parameters
im myParamCol As Parameters
et myParamCol = myDoc.Part.Parameters
Just to be clean before creating parameters
Scan the collection of parameters and remove parameters
with name "ProjectId"
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
40/46
or "ProjectKey"
or "StringLength"
or "SphereRadius"
or "SphereVolume"
or Each myPar in myParamCol
if myPar.Name = "ProjectId"_
or myPar.Name = "ProjectKey"_
or myPar.Name = "StringLength"_
or myPar.Name = "SphereRadius"_or myPar.Name = "SphereVolume"_
then myParamCol.Remove myPar.Name
ext
Create the ProjectId parameter
This parameter is a string type parameter
Its initial value is CATLifKnowledgeAdvisor
im myString1 As Parameter
et myString1 = myParamCol.CreateString("ProjectId","CATLifKnowledgeAdvisor")
Create the ProjectKey parameter
This parameter is a string type parameterIts initial value is a blank string
im myString2 As Parameter
et myString2 = myParamCol.CreateString("ProjectKey","")
Create an integer type parameter
Its name is Stringlength - its initial value is 0
im myStringLength As Parameter
et myStringLength = myParamCol.CreateInteger("StringLength",0)
Create a Length type parameter
Its initial name is blank
Its initial value is 0
It is renamed and assigned a value after creation
Note that units are specified in internal units
i.e the units used by the geometric modeler (mm for Length)
im mySphereRadius As Parameter
et mySphereRadius = myParamCol.CreateDimension("","LENGTH", 0)
ySphereRadius.Rename "SphereRadius"
ySphereRadius.Value = 50
Display the minum tolerance for "SphereRadius"
sgbox("Minimum Tolerance for the LENGTH parameter " &
SphereRadius.MinimumTolerance)
Create a Volume type parameter
Its name is SphereVolume
Its initial value is 0 m3
im mySphereVol As Parameter
et mySphereVol = myParamCol.CreateDimension("SphereVolume","VOLUME",0)
Create a formula which specifies that the ProjectKey parameter value
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
41/46
equals the three first characters of ProjectId
To do so we use the CreateFormula method of the "Relations" collection
object - the constrained parameter is passed as the third argument of the
method - The formula expression is passed as the fourth argument.
Note that the Extract function is provided by the Knowledge Advisor
string function dictionary
im Formula1 As Formula
et Formula1 = myRelCol.CreateFormula("Formula1", "", myString2,_
"ProjectId.Extract(0,3)" )
Create a formula which also applies to the ProjectKey parameterThis formula will be created as inactive
im Formula2 As Formula
et Formula2 = myRelCol.CreateFormula("Formula2", "", myString2,_
"ProjectId.Extract(4,3)" )
Create a formula which applies to the StringLength parameter
The formula expression passed as the fourth argument
uses the Length function which is provided with the string functions of the
Knowledge Advisor dictionary
im Formula3 As Formulaet Formula3 = myRelCol.CreateFormula("Formula3", "", myStringLength,_
"ProjectId.Length()" )
Create a formula which applies to the SphereVolume parameter
It just calculates the volume from the radius
im Formula4 As Formula
et Formula4 = myRelCol.CreateFormula("Formula4", "", mySphereVol,_
"(4/3)*PI*SphereRadius**3")
Display the list of relations
The formula names and expressions are displayed in a message box
im strRel As String
trRel = "Here is the list of relations" & vbCrLf
or i = 1 to myRelCol.Count
strRel = strRel & vbCrLf & myRelCol.Item(i).Name & " " & myRelCol.Item(i).V
ext
sgBox(strRel)
d Sub
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
42/46
************************************************************************
MANAGING DESIGN TABLES, RULES AND CHECKS
************************************************************************
Abstract
---------
This macro which illustrates how to create and manage a design table
1 - Checks whether a file which is used as an argument in
the CreateDesignTable method exists
2 - Creates a design table from an existing Excel file
3 - Creates two associations
4 - Applies a new configuration to the document
5 - Creates a rule
6 - Creates a check
Running the macro
------------------
Run this macro on the KwrMacro0.CATPart document which is delivered
as an Infrastructure sample.
This macro uses as an input data the KwrMacTable.xls file which is delivered
as an Infrastructure sample
You must replace the value of the pathNameDT variable with the path
of the file where this Excel table has been unloaded.
To run this macro under UNIX, replace the Excel file with a .txt file.
b CATMain()
Retrieve your active document - CATIA is your application
You get the active document by using the ActiveDocument property
on your application object
im myDoc As Document
et myDoc = CATIA.ActiveDocument
Check whether the document is a CATPart
Analyse the pathname of the document
If the extension .CATPart is not found, a message is displayed
but you exit the procedure
InStrRev is a standard VB function
im strPartName, strCATPart
trPartName = myDoc.Name
f (InStrRev(strPartName,".CATPart",-1) = 0)_
hen MsgBox("Your document should be a .CATPart") : Exit Sub
Retrieve the collection object which contains
all the document relations
myDoc.Part is satisfied as the document extension
has been checked
im myRelCol As Relations
et myRelCol = myDoc.Part.Relations
Just to be clean before creating relationms
Scan the collection of relations and remove the relations
with name "DesignTable.1"
or "Rule.1"
or "Check.1"
or Each myRel in myRelCol
if myRel.Name = "DesignTable.1"_
or myRel.Name = "Rule.1"_
or myRel.Name = "Check.1"_
then myRelCol.Remove myRel.Name
ext
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
43/46
Check whether the design table file exists
otherwise exit the procedure
im fso
et fso = CreateObject("Scripting.FileSystemObject")
athNameDT = "e:/users/cre/adele/KwrMacTable.xls"
f (fso.FileExists(pathNameDT) = False)_
hen MsgBox (pathNameDT & " doesn't exist") : Exit Sub
Create the "DesignTable.1" design table
im Des0 As DesignTable
et Des0 = myRelCol.CreateDesignTable("DesignTable.1","",_False,_
pathnameDT)
Retrieve the collection object which contains
all the part bodies
im myBodCol As Bodies
et myBodCol = myDoc.Part.Bodies
Scan the Bodies collection to determine
whether a PartBody feature exists otherwise
exit the procedure
or Each myBod in myBodCol
if myBod.Name = "PartBody" then PartBodyExists = "True"
ext
f (PartBodyExists "True") then MsgBox("No PartBody") : Exit Sub
Retrieve the "PartBody" iten from the Bodies collection
im Body1 As AnyObject
et Body1 = CATIA.ActiveDocument.Part.Bodies.Item("PartBody")
Check there is at least one shape in the Part
im myShaCol As Shapes
et myShaCol = Body1.Shapes
f (myShaCol.Count = 0) then msgbox("No shapes in your part") : Exit Sub
Retrieve the Pad.1 object
im Pad2 As AnyObjectet Pad2 = Body1.Shapes.Item("Pad.1")
Creates two associations
es0.AddAssociation Pad2.FirstLimit.Dimension, "A"
es0.AddAssociation Pad2.SecondLimit.Dimension, "B"
Apply the third configuration of the design table
to your document
es0.Configuration = 3
Add a new row
A new row is added to the design table each time the
macro is replayed on the document
A limit of 10 rows is specifiedf (Des0.ConfigurationsNb < 11) Then Des0.AddNewRow()
Create the rule below:
if PartBody\Hole.1\Diameter > 10mm
Message (""The hole diameter is # "", PartBody\Hole.1\Diameter)"
im Rule0 As Rule
et Rule0 = myRelCol.CreateProgram("Rule.1",_
", "" +_
hr(10) + "if PartBody\Hole.1\Diameter > 10mm" + chr(10) +_
Message (""The hole diameter is # "", PartBody\Hole.1\Diameter)" )
Create the check below:
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
44/46
PartBody\Pad.1\FirstLimit\Length > 100mm
im Check1 As Check
et Check1 = myRelCol.CreateCheck ( "Check.1", "Increase the pad thickness",_
/* Check created by CRE 03/16/00 */" + chr(10) + "PartBody\Pad.1\FirstLimit\Len
100mm" )
Update the document
TIA.ActiveDocument.Part.Update
d Sub
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
45/46
Glossary
A
utomation
A technology that applications use to expose their objects to development tools, macr
languages, and other applications that support Automation.
C
ollection
An object that contains zero or more objects of the same type. In CATIA knowledgewaapplications, the Parameters and Relations collections provide you with all the requirecreation methods.
-process macro
A macro which is interpreted in the same process as CATIA using the scripting enginehosted by CATIA. An in-process macro is run from the Tools->Macros command andprocessed by CATIA just like any other command.
Macro
A set of instructions recorded and saved under a .CATScript file. When the macro is rCATIA carries out the instructions of the macro.
ethod
An operation that acts on an object.
O
ut-process macro
A macro which is run from another application running in another process. In this casthe macro should first connect to CATIA to then access its data. This connection startsCATIA if no CATIA process is being running. The script is interpreted by the scriptingengine hosted by the application from which you start the macro.
-
7/30/2019 Catia Knowledge Advisor Journaling Guide
46/46
P
operty
A named attribute of an object. Properties define object characteristics such as size,color, and screen location, or the state of an object, such as enabled or disabled.