knowledge advisor journaling guide use casesdunet.nicolas.free.fr/catiav5/kwrjg.pdf · welcome to...

46
Knowledge Advisor Journaling Guide Preface Getting Started Object Library Use Cases Glossary © Dassault Systèmes 1994-2000. All rights reserved.

Upload: buitram

Post on 23-May-2018

228 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Knowledge AdvisorJournaling Guide

Preface

Getting Started Object Library

Use Cases

Glossary

  © Dassault Systèmes 1994-2000.

All rights reserved.

Page 2: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

PrefaceWelcome to CATIA Knowledgeware automation,  a fast and easy way to write macros andcreate simple applications to be plugged to CATIA.  Whether you are an experiencedprofessional or a brand new to programming languages, CATIA knowledgeware provides youwith a set of tools to simplify, automate and improve your daily life as a CATIA end-user.

This preface gives you some information to brush-up on the concepts used in Visual Basic orVBScript and introduce you to the knowledgeware automation objects. If you are an absolutebeginner in programming languages,  it is much better to go to the http://www.microsoft.comsite,  then refer to the CATIA Infrastructure Journaling Guide.

Page 3: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

RoadMap This guide provides the basis for understanding how to create macros using knowledgewarefeatures. These knowledgeware features are supplied in the Infrastructure product (parameters,formulas and design tables) as well as in the Knowledge Advisor product (rules and checks).

To keep up with the material presented in this guide, it is better if you have a background inscript languages. However, the Use Cases provided as samples are fully commented andshould help you understand how to proceed to write simple macros as well as fully-fledgedmacros.

If you are a beginnerDon't skip the Getting Started if you are a beginner. It is a  knowledgeware-orientedexample described in the form of two interactive tasks. You just record a macro, take alook at the code generated,  modify it then replay it. It is very basic.If you already get by in Script languagesIf you already dabble in script languages, you can get straight to the Object Library or tothe Use Cases.

Most knowledge applications rely on the Infrastructure and Part Design products. Forinformation refer to the CATIA Infrastructure and CATIA Part Design Journaling Guides.

Page 4: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Automation in a Nutshell CATIA is an OLE Automation server for Windows NT which allows you to record and replaymacros for both Windows NT and UNIX. 

The macros recorded from the Tools->Macro menu are generated in a syntax very close to theVisual Basic language. Statements such Dim... As ... which are not supported in VBScript aresupported by the CATIA macro language so that a macro recorded on Windows NT can bereplayed on UNIX or the reverse.

Automation is a feature of the Microsoft ® Component Object Model (COM), anindustry-standard technology that applications use to expose their objects to developmenttools, macro languages, and other applications that support Automation. For example,  CATIAknowledware exposes a parameter, a formula, a rule or a check, each as a different type ofobject. A word processor exposes objects such as an application, a document, a paragraph, asentence, a bookmark, or a selection.

When an application supports Automation, the objects the application exposes can beaccessed by Visual Basic. To manipulate these objects, you have to invoke methods on theobject or get / set the object's properties.

To 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 theirproperties, and methods supported by an application are usually defined in theapplication's object library.

Properties and MethodsAn object represents an element of an application, such as a worksheet, a cell, a chart, a form,or a report. In Visual Basic or VBScript code, you must identify an object before you can applyone of the object’s methods or change the value of one of its properties.

A property is an attribute of an object that defines one of the object's characteristics, such assize, color, or screen location, or an aspect of its behavior, such as whether it is enabled orvisible. To change the characteristics of an object, you change the values of its properties.

To set the value of a property, follow the reference to an object with a period, the propertyname, an equal sign (=), and the new property value. For example, the following statementmodifies the minimum tolerance value of a Length object by setting the MinimumToleranceproperty.length0.MinimumTolerance = 1

Not all properties can be set. There are some that are read-only.

You can retrieve information about an object by returning the value of one of its properties. The

Page 5: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

following statement uses a message box to display the maximum tolerance of a Lengthparameter:MsgBox(length0.MaximumTolerance)

A method is an action that an object can perform. The following statement uses the Renamemethod to rename a parameter object:parameter.Rename("String1")

CollectionsA collection is an object that contains several other objects, usually, but not always, of thesame type. In Microsoft Excel, for example, the Workbooks object contains all the openWorkbook objects. In Visual Basic, the Forms collection contains all the Form objects in anapplication. In CATIA knowledgeware the Relations object contains all the knowledgewarefeatures of relation type (formulas, rules, checks and design tables).

A collection is always denoted as a plural name to help easily recognize a collection amongother objects. The collection index begins at 1, and not 0. Usually, an object in the collection isreached using its index, but it can also be reached using the name you assign to it.  Thefollowing statement uses the item method of the Collection object to retrieve theKwrMacro0\Volume.1 parameter from its name, myPar1 being a Parameters object.myPar1.item("KwrMacro0\Volume.1")

CATIA collections are described by the Collection object. Refer to the 'CATIA InfrastructureJournaling Guide' for more information.

Page 6: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

CATIA Knowledgeware AutomationObjectsThe CATIA knowledgeware automation objects are described in the figure below.

PrinciplesTo Create: The knowledgeware features are all created from the collection which refersto 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 methodon 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 Modify: To manipulate a knowledgeware object, you just have to use the methodsand properties of the relevant object.

Click any of the links todisplay the related object description

                       

    

                      To create a parameter           Parameters  collection           To manipulate a parameter           Parameter object

To Create a Formula  Relations collectionTo manipulate a formula  Formula Object  

 

To create a Rule  Relations collectionTo manipulate a Rule  Program Object 

Page 7: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

To Create a Check  Relations collectionTo manipulate a Check  Check Object

To create a Design Table      Relations collection      To manipulate a Design Table      DesignTable object

 

Page 8: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Getting StartedBeginners in CATIA Automation can create useful applications by learning just a few of thekeywords. If you don't know anything about script languages, just carry out the scenario below. It doesn't  really teach you how to program but it is intended to give you a feeling for what amacro looks like.

To 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 booksabout 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.

Page 9: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

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 part parameters should be specified as follows:Pad First Limit: 100mmPad Second Limit: 0mmHole Type: '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.

Page 10: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Press Start. From now on, all the interactions will be recorded in the macroyou have just specified.

Start of interaction recording

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 name,value or formula'.

b.

In 'Edit name, value or formula',  replace the Length.1 name withReference_Length and assign the 70mm value to this parameter.Then 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.

Page 11: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

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 of interaction 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.

Page 12: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Editing 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 thestandard tool bar or by using any available editor. A VBScript procedure similar to the one below isdisplayed (comments have been added and some variables created):Language="VBSCRIPT"

Sub CATMain()

' Declare the Length0 variable as a Dimension typeDim Length0 As Dimension

' Retrieve the root of your active document' and access the 'Parameters' featureSet Doc1 = CATIA.ActiveDocument.PartSet Par1 = Doc1.Parameters

' Create a Dimension type parameter,' rename it' and modify its valueSet Length0 = Par1.CreateDimension("Length.1", "LENGTH", 0.000000) Length0.Rename "RefLength"Length0.Value = 70.000000

' Retrieve the PartBody featureDim Body1 As AnyObjectSet Body1 = Doc1.Bodies.Item("PartBody")

' Retrieve the Pad.1 featureDim Pad2 As AnyObjectSet 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 formulaDim Formula3 As FormulaSet Rel1 = Doc1.RelationsSet Di1 = Pad2.FirstLimit.DimensionSet Formula3 = Rel1.CreateFormula("Formula.1","", Di1, "RefLength") Formula3.Modify "RefLength / 10"

' Update the documentCATIA.ActiveDocument.Part.Update

End Sub

2.

In the VBScript source above, modify the Formula.1 name and add a new formula defining the Pad3.

Page 13: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

second limit:Language="VBSCRIPT"

Sub CATMain()Dim Length0 As DimensionSet Doc1 = CATIA.ActiveDocument.PartSet Par1 = Doc1.ParametersSet Length0 = Par1.CreateDimension("Length.1", "LENGTH", 0.000000)

Length0.Rename "RefLength"

Length0.Value = 70.000000Dim Body1 As AnyObjectSet Body1 = Doc1.Bodies.Item("PartBody")

Dim Pad2 As AnyObjectSet Pad2 = Body1.Shapes.Item("Pad.1")

Dim Formula3 As FormulaSet Rel1 = Doc1.RelationsSet Di1 = Pad2.FirstLimit.Dimension' Modify the formula creation - the same result is obtainedSet Formula3 = Rel1.CreateFormula("Formula.1","", Di1, "RefLength / 10")

' Rename Formula.1Formula3.Rename "F1"

' Add a new formulaDim Formula4 As FormulaSet Rel1 = Doc1.RelationsSet Di2 = Pad2.SecondLimit.DimensionSet 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.

Page 14: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

The Formula.1 has been renamed, the new formula F2 has been added to the document and thewhole document is updated.

Page 15: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Object LibraryHere 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

Page 16: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

  Objects such as Dimension, Formula and Rule are not described because they provideneither properties nor methods. They are manipulated by the properties and methods of theirparent object.

Page 17: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Parameter ObjectDerived Objects

DefinitionAs an end-user, you can add comments to a parameter and decide to hide a parameter from the specification view.

ReminderTo  hide a parameter or add a comment to a parameter,you just have to right-click the value field in anyparameter edition box, then select the Edit Comment... orHide command from the contextual menu.  

Parameters are described by the Parameter object which provides you with properties to determine whether a parameter ishidden or not and to retrieve the comment associated with the parameter.

Parameters with multiple-values cannot be managed in CATIA macros.

Properties

parameter.HiddenReturns True if the parameter is hidden, otherwise returns False.

parameter.CommentReturns the comment associated with the parameter.

Methods

parameter.Rename(newparameterName)

Renames the parameter.

ExampleSee Managing Hidden Parameters.

Page 18: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Parameter ObjectDerived Objects

IntParam ObjectBoolParam ObjectStrParam ObjectRealParam Object

 

 

Page 19: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

IntParam Object

DefinitionAn IntParam object describes a parameter whose value can only be an integer.

Properties

parameter.ValueReturns or sets the parameter value.

Page 20: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

BoolParam Object 

DefinitionA boolean is a parameter whose value can only be True or False.

Properties

parameter.ValueReturns or sets the value of a boolean parameter.

ExampleThe extract below creates the "Ischecked" parameter of boolean type.

' ...Dim BoolParam0 As BoolParamDim myDoc As Document Set myDoc = CATIA.ActiveDocument Dim myParamCol As Parameters Set myParamCol = myDoc.Part.Parameters

Set BoolParam0 = myParamCol.CreateBoolean("Boolean.1", True)

BoolParam0.Rename "IsChecked"

BoolParam0.Value = False' ...

 

Page 21: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

StrParam Object

DefinitionAn StrParam is an object which describes a string type parameter.

Properties

parameter.ValueReturns or sets the value of a string parameter.

Page 22: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

RealParam ObjectDerived Objects

DefinitionA RealParam object describes a parameter whose value can only be a real.

Properties

parameter.Value Returns or sets the value of the real parameter.

parameter.RangeMinReturns or sets the lower bound of a real parameter.

parameter.RangeMaxReturns or sets the upper bound of a real parameter.

ExampleThe extract below specifies a lower(minimum) bound of 10.0 and an upper(maximum) bound of 30.0.

...Dim RealParam0 As RealParam

Dim myDoc As Document Set myDoc = CATIA.ActiveDocument Dim myParamCol As Parameters Set myParamCol = myDoc.Part.Parameters Set RealParam0 = myParamCol.CreateReal("Real.1", 0.000000)

RealParam0.Value = 12.500000RealParam0.RangeMin = 10.000000RealParam0.RangeMax = 30.000000

After the macro is finished running, edit the Real.1 parameter lower and upper bounds.

Page 23: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

 This is what you can see onscreen when you select the Range-> Edit... command:

Page 24: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Length Object

DefinitionA Length object describes a parameter whose value can only be a length. A length object derives fromthe Dimension object which itself derives from the RealParam object. A dimension object is created bythe CreateDimension method. To manipulate a Length object, you have to use the methods andproperties provided by the RealParam object.

Properties

parameter.MinimumTolerance Returns  the minimum tolerance of a Length object.

parameter.MaximumToleranceReturns the maximum tolerance of a Length object.

ExampleWhen applied to a CATPart document, the extract below creates the W=10mm and A=45deg dimensionparameters.

' ...Dim RealParam0 As RealParam

Dim myDoc As Document Set myDoc = CATIA.ActiveDocument Dim myParamCol As Parameters Set myParamCol = myDoc.Part.Parameters Set Length0 = myParamCol.CreateDimension("W","Length", 10.00) Set Angle0 = myParamCol.CreateDimension("A","Angle", 45)msgbox("Minimum Tolerance for Length " & Length0.MinimumTolerance)msgbox("Maximum Tolerance for Angle " & Angle0.MaximumTolerance)' ...

Check that the values displayed in the message boxes are the same as those specified in theTools->Options->Tolerance tab.

Page 25: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives
Page 26: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Angle Object 

DefinitionAn Angle object describes a parameter whose value can only be an angle. An angle object derives fromthe Dimension object which itself derives from the RealParam object. A dimension object is created bythe CreateDimension method. To manipulate an Angle object, you have to use the methods andproperties provided by the RealParam object.

Properties

parameter.MinimumTolerance Returns  the minimum tolerance of an Angle object.

parameter.MaximumToleranceReturns the maximum tolerance of an Angle object.

ExampleWhen applied to a CATPart document, the extract below creates the W=10mm and A=45deg dimensionparameters.

' ...Dim RealParam0 As RealParam

Dim myDoc As Document Set myDoc = CATIA.ActiveDocument Dim myParamCol As Parameters Set myParamCol = myDoc.Part.Parameters Set Length0 = myParamCol.CreateDimension("W","Length", 10.00) Set Angle0 = myParamCol.CreateDimension("A","Angle", 45)msgbox("Minimum Tolerance for Length " & Length0.MinimumTolerance)msgbox("Maximum Tolerance for Angle " & Angle0.MaximumTolerance)' ...

Check that the values displayed in the message boxes are the same as those specified in theTools->Options->Tolerance tab.

Page 27: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives
Page 28: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Relation Object

DefinitionThe Relation object provides you with properties and methods to access the knowledgeware relationdata. This object does not allow you to create a relation.

Properties

relation.ValueReturns the relation definition (the expression).

relation.CommentReturns the comment associated with the relation.

relation.ActivatedReturns True if the relation is activated, otherwise returns False.

relation.HiddenReturns True if the relation is hidden, otherwise returns False.

Methods

relation.Activate()

Makes a relation active.

relation.Deactivate()

Deactivates a relation.

relation.Rename(newName)

Replaces the relation name with the one specified in the argument.

relation.Modify(newRelation)

Replaces the relation with the one specified in the argument.

ExampleOpen the initial document of Recording and Replaying Macros and add two formulas constrainingVolume.1.  Formula.1 is initially deactivated.

1.

Page 29: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Run the macro below on this document

Language="VBSCRIPT"

Dim myDoc As Document Set myDoc = CATIA.ActiveDocument Dim myPar1 As Parameters Set myPar1 = myDoc.Part.Parameters Set myRel1 = myDoc.Part.Relations

Dim For0 As AnyObjectSet For0 = myRel1.Item("Formula.1") Dim For1 As AnyObjectSet For1 = myRel1.Item("Formula.2")

' Display the Formula.1 expressionMsgBox(For0.Value)

' Deactivate Formula.2 and activate Formula.1For1.DeactivateFor0.Activate

' Modify Formula.1For0.Modify("R1*10m*0.5m")

' Rename the formulasFor0.Rename("F1")For1.Rename("F2")

CATIA.ActiveDocument.Part.Update

This is what you can see onscreen.

2.

Page 30: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

 

Page 31: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Check Object

DefinitionA check object inherits the properties and methods of the Relation object. In addition, the severity property allows you to determine whethera check has been declared of silent, warning or  information type.

To manipulate checks, you must have the Knowledge Advisor product installed.

Properties

check.SeverityReturns or sets the severity of the check. The check validity is an integer whose value is 1 for Silent, 2 for Information, 3 forWarning.

ExampleLanguage="VBSCRIPT"

Dim Check0 As CheckDim myDoc As DocumentSet myDoc = CATIA.ActiveDocumentSet myRel1 = myDoc.Part.RelationsSet Check0 = CmyRel1.CreateCheck( "Check.1",_"Check.1 is not valid",_"PartBody\Pad.1\FirstLimit\Length > 50mm" )

Check0.Rename "Check.1"

Check0.Severity = 2

 

You can run this macro on any part provided it has a FirstLimit\Length parameter.

Page 32: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Design Table Object

DefinitionThe Design object provides you with properties and methods to access design table data. This object doesnot allow you to create a design table.

Properties

designtable.CopyModeReturns the value of the "Duplicate data in CATIA model" check box of the design table dialogbox. Returns True if the design table data have been duplicated in the CATIA document.Otherwise, returns False. 

designtable.ConfigurationReturns or sets the active configuration number.

designtable.ConfigurationsNbReturns the number of configurations in the design table.

Methods

designtable.AddAssociation(param, sheetColumnName)

Associates the parameter specified in the first argument with the column whose name is specifiedin the second argument.

designtable.RemoveAssociation(sheetColumnName)

Removes the association created with the column whose name is specified in the argument.

designtable.AddNewRow()

Adds a new row in the design table. The new row contains the active parameter values. If youdeactivate the design table, modify the document parameters, then add a new row, the valuescontained in the new row will be those you have just modified in the document and not those ofthe last selected configuration.

ExampleSee Managing Design Tables, Rules and Checks.

Page 33: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Relations Collection

DefinitionThe Relations collection object provides you with methods to create and manage all type of relations.The knowledgeware relations are:

the formulas●

the rules ●

the checks●

and the design tables.●

Properties

The object has no properties but inherits the Collection object properties.

Methods

relations.CreateFormula(formulaName, comment, parameter, expression)

Creates a formula. The parameter to be constrained by the formula is specified as the thirdargument.

relations.CreateProgram(ruleName, comment, ruleBody)

Creates a rule.

relations.CreateCheck(checkName, comment, checkBody)

Creates a check.

relations.CreateDesignTable(designtableName, comment, copyMode, ExcelSheetFilePath)

Creates a design table.

relations.Item(relationRank)

Returns the relation specified in the argument.

relations.Remove(relationName)

Removes the relation specified in the argument. 

ExampleSee Creating and Manipulating Parameters and Formulas and Managing Design Tables, Rules andChecks.

 

Page 34: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

 

Page 35: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Parameters Collection

DefinitionThe Parameters collection object provides you with methods to create parameters. 

Properties

The object has no properties but inherits the Collection object properties.

Methods

parameters.CreateString(parameterName,parameterValue)

Returns a string parameter with the name and value as specified in the arguments.

parameters.CreateReal(parameterName,parameterValue)

Returns a real parameter.

parameters.CreateInteger(parameterName,parameterValue)

Returns an integer.

parameters.CreateBoolean(parameterName,parameterValue)

Returns a boolean.

parameters.CreateDimension(parameterName,parameterType,parameterValue)

Returns a dimension type parameter with the name, type and value as specified in the arguments.

parameters.Item(parameterRank)

Returns the parameter specified in the argument.

parameters.Remove(parameterName)

Removes the parameter specified in the argument. 

ExampleSee Creating and Manipulating Parameters and Formulas.

Page 36: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Use CasesThis guide provides three fully-fledged samples to help you begin learning CATIA automationprinciples. Each sample is broken into steps, and complete code is supplied for each step. Thecomments in the first part explain how to run the macro.

Page 37: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' **********************************************************' 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 which is' delivered as a CATIA Infrastructure sample. This document contains hiddenparameters.' However, you can run this macro on any CATPart document

Sub 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, strCATPart strPartName = 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")_

Page 38: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

then strRel1 = strRel1 & vbCrLf & myPar.Name & " " & myPar.Value &_ " " & "'" & myPar.Comment & "'" : HiddenNumber = HiddenNumber + 1 : myPar.Value= "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"

End Sub

Page 39: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' *************************************************' 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 parameters' 3 - 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

Sub 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, strCATPart, myPos strPartName = 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 relations' myDoc.Part is satisfied as the document extension ' has been checked' Note: Statements below could not be applied to a CATProduct

Dim myRelCol As Relations Set myRelCol = myDoc.Part.Relations For Each myRel in myRelCol myRelCol.Remove myRel.Name Next

' Retrieve the collection object which contains' all the document parameters

Dim myParamCol As Parameters Set myParamCol = myDoc.Part.Parameters

' Just to be clean before creating parameters' Scan the collection of parameters and remove parameters' with name "ProjectId"

Page 40: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' or "ProjectKey"' or "StringLength"' or "SphereRadius"' or "SphereVolume"

For 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 Next

' Create the ProjectId parameter ' This parameter is a string type parameter ' Its initial value is CATLifKnowledgeAdvisor

Dim myString1 As Parameter Set myString1 = myParamCol.CreateString("ProjectId","CATLifKnowledgeAdvisor")

' Create the ProjectKey parameter ' This parameter is a string type parameter' Its initial value is a blank string

Dim myString2 As Parameter Set myString2 = myParamCol.CreateString("ProjectKey","")

' Create an integer type parameter' Its name is Stringlength - its initial value is 0

Dim myStringLength As Parameter Set 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)

Dim mySphereRadius As Parameter Set mySphereRadius = myParamCol.CreateDimension("","LENGTH", 0) mySphereRadius.Rename "SphereRadius" mySphereRadius.Value = 50

' Display the minum tolerance for "SphereRadius"

msgbox("Minimum Tolerance for the LENGTH parameter " &mySphereRadius.MinimumTolerance)

' Create a Volume type parameter ' Its name is SphereVolume' Its initial value is 0 m3

Dim mySphereVol As Parameter Set mySphereVol = myParamCol.CreateDimension("SphereVolume","VOLUME",0)

' Create a formula which specifies that the ProjectKey parameter value

Page 41: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' 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

Dim Formula1 As Formula Set Formula1 = myRelCol.CreateFormula("Formula1", "", myString2,_ "ProjectId.Extract(0,3)" )

' Create a formula which also applies to the ProjectKey parameter' This formula will be created as inactive

Dim Formula2 As Formula Set 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

Dim Formula3 As Formula Set Formula3 = myRelCol.CreateFormula("Formula3", "", myStringLength,_ "ProjectId.Length()" )

' Create a formula which applies to the SphereVolume parameter' It just calculates the volume from the radius

Dim Formula4 As Formula Set 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

Dim strRel As String strRel = "Here is the list of relations" & vbCrLf For i = 1 to myRelCol.Count strRel = strRel & vbCrLf & myRelCol.Item(i).Name & " " & myRelCol.Item(i).Value Next MsgBox(strRel)

End Sub

Page 42: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' ************************************************************************' 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.

Sub 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, strCATPart strPartName = 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 relations ' myDoc.Part is satisfied as the document extension ' has been checked Dim myRelCol As Relations Set 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" For Each myRel in myRelCol if myRel.Name = "DesignTable.1"_ or myRel.Name = "Rule.1"_ or myRel.Name = "Check.1"_ then myRelCol.Remove myRel.Name Next

Page 43: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' Check whether the design table file exists ' otherwise exit the procedure Dim fso Set fso = CreateObject("Scripting.FileSystemObject") pathNameDT = "e:/users/cre/adele/KwrMacTable.xls" if (fso.FileExists(pathNameDT) = False)_ then MsgBox (pathNameDT & " doesn't exist") : Exit Sub

' Create the "DesignTable.1" design table Dim Des0 As DesignTable Set Des0 = myRelCol.CreateDesignTable("DesignTable.1","",_ False,_ pathnameDT) ' Retrieve the collection object which contains ' all the part bodies Dim myBodCol As Bodies Set myBodCol = myDoc.Part.Bodies

' Scan the Bodies collection to determine ' whether a PartBody feature exists otherwise ' exit the procedure For Each myBod in myBodCol if myBod.Name = "PartBody" then PartBodyExists = "True" Next if (PartBodyExists <> "True") then MsgBox("No PartBody") : Exit Sub

' Retrieve the "PartBody" iten from the Bodies collection Dim Body1 As AnyObject Set Body1 = CATIA.ActiveDocument.Part.Bodies.Item("PartBody")

' Check there is at least one shape in the Part Dim myShaCol As Shapes Set myShaCol = Body1.Shapes if (myShaCol.Count = 0) then msgbox("No shapes in your part") : Exit Sub

' Retrieve the Pad.1 object Dim Pad2 As AnyObject Set Pad2 = Body1.Shapes.Item("Pad.1")

' Creates two associations Des0.AddAssociation Pad2.FirstLimit.Dimension, "A" Des0.AddAssociation Pad2.SecondLimit.Dimension, "B"

' Apply the third configuration of the design table ' to your document Des0.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 specified If (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)" Dim Rule0 As Rule Set Rule0 = myRelCol.CreateProgram("Rule.1",_ "", "" +_ chr(10) + "if PartBody\Hole.1\Diameter > 10mm" + chr(10) +_ "Message (""The hole diameter is # "", PartBody\Hole.1\Diameter)" )

' Create the check below:

Page 44: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

' PartBody\Pad.1\FirstLimit\Length > 100mm Dim Check1 As Check Set Check1 = myRelCol.CreateCheck ( "Check.1", "Increase the pad thickness",_ "/* Check created by CRE 03/16/00 */" + chr(10) + "PartBody\Pad.1\FirstLimit\Length > 100mm" )

' Update the documentCATIA.ActiveDocument.Part.Update

End Sub

Page 45: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

GlossaryAautomation

A technology that applications use to expose their objects to development tools, macrolanguages, and other applications that support Automation.

Ccollection

An object that contains zero or more objects of the same type. In CATIA knowledgeware applications,  the Parameters and Relations collections provide you with all the requiredcreation methods. 

Iin-process macro

A macro which is interpreted in the same process as CATIA using the scripting engine(s)hosted by CATIA. An in-process macro is run from the Tools->Macros command andprocessed by CATIA just like any other command.

Mmacro

A set of instructions recorded and saved under a .CATScript file. When the macro is run,CATIA carries out the instructions of the macro.

 method

An operation that acts on an object.

Oout-process macro

A macro  which is run from another application running in another process. In this case,the 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.

Page 46: Knowledge Advisor Journaling Guide Use Casesdunet.nicolas.free.fr/CATIAV5/kwrjg.pdf · Welcome to CATIA Knowledgeware automation,€ a fast and easy way to ... This preface gives

Pproperty

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.