Title: Parametric Modeling
1Parametric Modeling
2Recording Macros
3(No Transcript)
4(No Transcript)
5(No Transcript)
6(No Transcript)
7(No Transcript)
8(No Transcript)
9(No Transcript)
10(No Transcript)
11Recorded Macros in VBA IDE
12Sub CATMain() Dim documents1 As Documents Set
documents1 CATIA.Documents Dim partDocument1
As PartDocument Set partDocument1
documents1.Add("Part") Dim part1 As Part Set
part1 partDocument1.Part Dim
hybridShapeFactory1 As HybridShapeFactory Set
hybridShapeFactory1 part1.HybridShapeFactory Di
m hybridShapePointCoord1 As HybridShapePointCoord
Set hybridShapePointCoord1 hybridShapeFactory1.A
ddNewPointCoord(100, 100, 100)
13Dim axisSystems1 As AxisSystems Set axisSystems1
part1.AxisSystems Dim axisSystem1 As
AxisSystem Set axisSystem1 axisSystems1.Item("Ab
solute Axis System") Dim reference1 As
Reference Set reference1 part1.CreateReferenceFr
omObject(axisSystem1) hybridShapePointCoord1.RefA
xisSystem reference1 Dim hybridBodies1 As
HybridBodies Set hybridBodies1
part1.HybridBodies Dim hybridBody1 As
HybridBody Set hybridBody1 hybridBodies1.Item("G
eometrical Set.1") hybridBody1.AppendHybridShape
hybridShapePointCoord1 part1.InWorkObject
hybridShapePointCoord1 part1.Update
14Dim reference2 As Reference Set reference2
part1.CreateReferenceFromObject(hybridShapePointCo
ord1) Dim hybridShapeDirection1 As
HybridShapeDirection Set hybridShapeDirection1
hybridShapeFactory1.AddNewDirectionByCoord(0,
1, 0) Dim hybridShapeLinePtDir1 As
HybridShapeLinePtDir Set hybridShapeLinePtDir1
hybridShapeFactory1.AddNewLinePtDir(reference2,
hybridShapeDirection1, 0, 20,
False) hybridBody1.AppendHybridShape
hybridShapeLinePtDir1 part1.InWorkObject
hybridShapeLinePtDir1 part1.Update End Sub
15(No Transcript)
16Sub CATMain()
- Main Subroutine in VBA for DP
- Functions and Procedures
- Subroutine
- maintain and write programs by segregating
related code into smaller, manageable sections - reduce the number of lines of code
- Sub . . . End Sub Construct
- Function . . . End Function
17Sub . . . End Sub
- construct is used to define a subroutine that
is, a procedure that performs some operation but
does not return a value to its calling program.
Sub cmdButton1_OnClick MsgBox(Hello) End Sub
18Subroutine names
- The name can contain any alphabetical or numeric
characters and the underscore character. - The name must start with a letter, not a numeric
character or underscore, and it cannot contain
embedded spaces. - The name cannot contain any spaces. Use the
underscore character to separate words to make
them easier to read. - The name cannot be a VBScript reserved word, such
as a VBScript statement. - Examples
- Sub 123MySub( ) ' Illegal
- Sub My Sub Routine( ) ' Illegal
- Sub MySub123( ) ' Legal
- Sub MySubRoutine( ) ' Legal
19Function . . . End
- construct is used to define a subroutine that
is, a procedure that performs some operation and
return a value to its calling program.
Function CubeIt(x) CubeIt x3 End Function
20Sub and Function
- To pass arguments to a Sub with Visual Basic
Script, do not use parentheses as follows - Object.Sub arg1, arg2, arg3
- But use parentheses with a Function
- Dim ReturnedObject As AnyObject
- Set ReturnedObject
- Object.Function (arg1, arg2, arg3)
21Declaring Variable and Constants
- VBA allows the implicit declaration of variables
- Recommends to use Dim
- Dim Variable_Name As Datatype
22Data Types in VBA
- Boolean
- Byte
- Integer
- Long
- Single
- Double
- Date/Time
- Currency
- String
- Object
- User Defined type
- Variant
23Set Statement
- Assigns an object reference to a variable or
property.
Set documents1 CATIA.Documents
24Set Statement
- You must use Set only if the returned value is an
object, but not if it is a character string or a
number. Nevertheless, character string and number
defined as CATIA literals are objects and Set
must be used if a Function returns a literal
object. - Finally, you don't have to use Set if you store
your return value in a Property - myObject.aggregatedObject Object.Function
(arg1, arg2, arg3) - because there is no actual aggregatedObject
variable, a property is a syntactical shortcut
for accessor methods, here get_aggregatedObject
and set_aggregatedObject, allowing to present
those methods as an attribute of the object. The
previous syntax is so equivalent to - myObject.set_aggregatedObject( Object.Function
(arg1, arg2, arg3) ) - and no Set is required.
25Class
- Template for an object.
- Class...End Class construct
- Variable
- Properties
- Method
- Event
26Object Oriented Programming
- OOP is all about programming using something
called an object - OOP consists of designing a bunch of classes most
of which will be used as templates to make
objects - The objects will be used to hold data and will be
initialized with constructors and perform useful
functions by being asked to run their methods
From CS1322 lecture slide
27What is an object?
- A chunk of memory which contains some data and
methods which can operate on the data. - Something that when created may have had special
code run to initialize it. - Something which has additional behavior defined
by methods which can - Be passed data via parameters
- Perform calculations/operations which may
- Change some of its data
- Perform some desired operation
- Return the value of some of its data
- Return the results of calculations using both
data passed in and data contained in the object
From CS1322 lecture slide
28How do we define different types of objects?
- For each different type of object we write a
class. - New classes may be based on existing classes to
allow code reuse - A class serves as a blueprint or template
defining how all objects made from this class
operate and what data they hold. - One class may be used to make one or many objects
From CS1322 lecture slide
29Classes and Objects
Class It describes the form of an object. It is
a template or blueprint. It specifies data
representation, behavior, and inheritance (via
variables, methods and parents)
Object It is an instance of a class. It has a
unique copy of every non-static variable.
(i.e., the instance variables but not
the class variables (those labeled with
static).
Difference between a class and an object of
that class is analogous to the difference
between a type and a variable of that type.
Naming Conventions Classes Identifiers begin
with cap letters for each word in
the identifier, e.g., class GraduateStudent Objec
ts Identifiers begins with lower case letter,
then caps for other words in
identifier, e.g.,
graduateStudentPresident
From CS1322 lecture slide
303 key features
- Abstract data types
- Encapsulation of data and behavior
- Classes as templates used to produce 1 or more
instances or objects - Inheritance
- Provides for code-reuse
- Polymorphism/Dynamic Binding
- Different objects in the same family may have
identically named methods - The language takes care of sorting out the
correct method to invoke for us
From CS1322 lecture slide
31Class Construct
- Class...End Class
- Class classname
- Class definition
- End Class
- Instantiation an object of a class
- Set objc new classname
32Class Variables
- Class has variables
- Dim varName1 , varName2...
- Private varName1 , varName2...
- Public varName1 , varName2...
- Dim, Public
- Open to outside
- Private
- Closed to outside
33Class Properties
- Access wrapper for private variables
- Property Get
- Property Let value
- Property Set reference
34Class Properties
- Class Computer
- Private modStrType
- Private oOS
- Public Property Let ComputerType(strType)
- modStrType strType
- End Property
- Public Property Get ComputerType( )
- ComputerType modStrType
- End Property
- Public Property Set OperatingSystem(oObj)
- Set oOS oObj
- End Property
- Public Property Get OperatingSystem( )
- Set OperatingSystem oOS
- End Property
- End Class
35Class Method
- Functions or subroutines in a class
- Class LaptopComputer
- Private modOwner
- Public Property Let CompOwner(strOwner)
- modOwner strOwner
- End Property
- Public Property Get CompOwner( )
- CompOwner modOwner
- End Property
- Public Function GetOwner( )
- GetOwner modOwner
- End Function
- End Class
36Class Event
- Two events are automatically associated with
every class you create - Class_Initialize
- is fired whenever you instantiate an object based
on this class - Class_Terminate
- is called when the script engine determines that
there are no remaining references on an object
37Classes in the code
Property
Dim documents1 As Documents Set documents1
CATIA.Documents Dim partDocument1 As
PartDocument Set partDocument1
documents1.Add("Part")
Method
38(No Transcript)
39Digital Project Classes
- Application
- Documents
- PartDocuments
- Part
- HybridShapeFactory
- HybridBodies
- HybridBody
- Referecence
- ..
- And more
40Sub CATMain() Dim documents1 As Documents Set
documents1 CATIA.Documents Dim partDocument1
As PartDocument Set partDocument1
documents1.Add("Part") Dim part1 As Part Set
part1 partDocument1.Part Dim
hybridShapeFactory1 As HybridShapeFactory Set
hybridShapeFactory1 part1.HybridShapeFactory Di
m hybridShapePointCoord1 As HybridShapePointCoord
Set hybridShapePointCoord1 hybridShapeFactory1.A
ddNewPointCoord(100, 100, 100)
41Application
- The root object for all CATIA macros is
Application . This corresponds to the CATIA frame
window. The CATIA application is always named
CATIA for in-process access, and you should only
refer to it since it already exists when you run
an in-process macro.
Dim documents1 As Documents Set documents1
CATIA.Documents
42Documents Object
- A Collection of Document objects.
Dim documents1 As Documents Set documents1
CATIA.Documents
43PartDocument
- Role When a PartDocument object is created, a
Part object is also created. This Part object is
the root object of the Part structure. A
reference Product object is also created in each
PartDocument. It is used to access Publications,
PartNumber.
Dim partDocument1 As PartDocument Set
partDocument1 documents1.Add("Part")
44Part
- The root level object inside a PartDocument
object.Role It aggregates all the objects
making up the part document. It provides many
factories and collections. The collections list
only the direct children of the part.
Selection.Search allows to get all objects of one
type.
Dim part1 As Part Set part1 partDocument1.Part
45HybridShapeFactory
- Interface to create all kinds of HybridShape
objects that may be needed in wireframe and
surface design.
Dim hybridShapeFactory1 As HybridShapeFactory Set
hybridShapeFactory1 part1.HybridShapeFactory
46HybridShapePointCoord
- Point defined by coordinates.Role To access
data of the point feature created with its
cartesian coordinates.
Dim hybridShapePointCoord1 As HybridShapePointCoor
d Set hybridShapePointCoord1 hybridShapeFactory1
.AddNewPointCoord(100, 100, 100)
47AxisSystems
- A collection of all the AxisSystem objects
contained in the part.
Dim axisSystems1 As AxisSystems Set axisSystems1
part1.AxisSystems
48AxisSystem
- The object Axis System
- A axis system has got one origin point and three
orthogonal axes, crossing at the origin point.
Dim axisSystem1 As AxisSystem Set axisSystem1
axisSystems1.Item("Absolute Axis System")
49Reference
- Represents an object pointing to another object.
- This other object can be either a wireframe
GeometricElement object such as a plane or a
line, or a boundary representation object such as
a face, a vertex or an edge. It may be, in
particular, a Boundary object. References are
created using appropriate methods for parts. They
are then passed to an object to enable
associativity with the referenced object.
Dim reference1 As Reference Set reference1
part1.CreateReferenceFromObject(axisSystem1)
Dim reference2 As Reference Set reference2
part1.CreateReferenceFromObject(hybridShapePointCo
ord1)
50HybridBodies
- A collection of the HybridBody objects.
Dim hybridBodies1 As HybridBodies Set
hybridBodies1 part1.HybridBodies
51HybridBody
- The object is a hybrid body.
- The hybrid body manages a set of geometric
elements, a set of hybrid shapes, a set of bodies
and a set of hybrid bodies. It belongs to the
HybridBodies collection of a Part or _at_ref
CATIABody or HybridBody object.
Dim hybridBody1 As HybridBody Set hybridBody1
hybridBodies1.Item("Geometrical Set.1")
52HybridBody.AppendHybridShape
- Appends a hybrid shape to the hybrid body.
- Parameters
- iHybriShape
- The hybrid shape to append.
- Example
- This example appends the hybrid shape hybridShape
to the hybrid body hybridBody hybridBody.AppendHy
bridShape hybridShape
hybridBody1.AppendHybridShape hybridShapePointCoor
d1
hybridBody1.AppendHybridShape hybridShapeLinePtDir
1
53Debugging
54Statement
- A statement in a program is a basic sentence that
expresses a simple ideaits purpose is to give
the computer a basic instruction. Statements
define the types of data allowed, how data are to
be manipulated, and the ways that procedures and
functions work.
55IF Then Else Statement
- If condition Then statements Else elsestatements
- ' Or, you can use the block form syntax
- If condition Then
- statements
- ElseIf condition-n Then
- elseifstatements . . .
- Else elsestatements
- End If
- If A gt 10 Then A A 1 B B A C C B
- If A gt 10 Then
- A A 1
- B B A
- C C B
- End If
56Select Case Statement
- Select Case testexpression
- Case expressionlist-n
- statements-n . . .
- Case Else
- elsestatements-n
- End Select
- Dim Color, MyVar
- Sub ChangeBackground (Color)
- MyVar lcase (Color)
- Select Case MyVar
- Case "red" document.bgColor "red"
- Case "green" document.bgColor "green"
- Case "blue" document.bgColor "blue"
- Case Else MsgBox "pick another color"
- End Select
- End Sub
57For...Next Statement
- For counter start To end Step step
- statements
- Exit For
- statements Next
- For I 1 To 10
- For J 1 To 10
- For K 1 To 10
- . . .
- Next
- Next
- Next
58Do...Loop Statement
- Do While Until condition
- statements
- Exit Do
- statements
- Loop
- Do statements
- Exit Do
- statements
- Loop While Until condition
59Do...Loop Statement
- Do Until DefResp vbNo
- MyNum Int (6 Rnd 1)
- ' Generate a random integer between 1 and 6.
- DefResp MsgBox (MyNum " Do you want
another number?", vbYesNo) - Loop
- Dim Check, Counter
- Check True Counter 0 ' Initialize
variables. - Do ' Outer loop.
- Do While Counter lt 20 ' Inner loop.
- Counter Counter 1 ' Increment
Counter. - If Counter 10 Then ' If condition is
True... - Check False ' set value of flag
to False. - Exit Do ' Exit inner loop.
- End If
- Loop
- Loop Until Check False ' Exit outer loop
immediately.