Professional Documents
Culture Documents
This article will show you how to use a scripting language to access CAA V5 automation objects to
capture your own know-how and to increase your productivity. You can customize V5 applications to
automate repetitive tasks, and to make it fit your own process.
The products that make up the CATIA and DELMIA applications share the same object model which can
be accessed, as well as their own objects, by scripts written in Visual Basic with Windows, and scripts
written in Basic Script for UNIX.
You can write your scripts from scratch, but you can also use the journalling facility from the
Macros ... command in the Tools menu that records end-user scenarios in scripts you can then use
as is or modify.
We put here a simple script example, to show what is scripting, which are the different things to do to
script, present briefly the scripting environment and dialog window, and what is journaling. This
example is divided into the following parts:
• 1-Recording the scenario, where we'll record the creation of a cylindric pad.
• 2-Modifying the generated macro, where we'll modify the generated macro to create five
similar pads
• 3-Replaying the modified macro
You will then find information about the scripting languages and environments, and some keys for you
if you are not familiar with writing macros in Invoking CATIA from a Scripting Language.
This scenario creates a circle in a sketch, and uses this sketch to create a cylindric pad.
4. In the File menu, click on New, or click on the icon, and double-click Part to create a new part. A
new part is created and a window for this part is opened.
Language="VBSCRIPT"
Sub CATMain()
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
arrayOfVariantOfDouble1(3) = 1.000000
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 1.000000
arrayOfVariantOfDouble1(8) = 0.000000
sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1
line2D1.ReportName = 1
line2D2.ReportName = 2
circle2D1.CenterPoint = point2D1
circle2D1.ReportName = 3
sketch1.CloseEdition
part1.Update
part1.Update
End Sub
We'll detail below, line by line, what has been recorded, following the interactive steps:
1. Startintg to record a macro creates the macro file and generates the first instruction stating
the scripting language used and the macro entry point, the CATMain sub:
Language="VBSCRIPT"
Sub CATMain()
2. Click on the New item of the File menu, or click on the icon , and double-click Part to
create a new part generates the following instructions:
3. Dim documents1 As Documents
4. Set documents1 = CATIA.Documents
5.
6. Dim partDocument1 As Document
7. Set partDocument1 = documents1.Add("Part")
A new document with the Part type is created. To do this, such a document is added to the
Documents collection of the CATIA application.
8. Select the xy plane and click on the sketcher icon to create a sketch:
9. Dim part1 As Part
10. Set part1 = partDocument1.Part
11.
12. Dim bodies1 As Bodies
13. Set bodies1 = part1.Bodies
14.
15. Dim body1 As Body
Set body1 = bodies1.Item("MechanicalTool.1")
Dim sketches1 As Sketches
Set sketches1 = body1.Sketches
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
arrayOfVariantOfDouble1(3) = 1.000000
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 1.000000
arrayOfVariantOfDouble1(8) = 0.000000
sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1
A Sketch object named Sketch1 is added to the Sketches collection using the reference1
Reference corresponding to the XY plane as a support. Using a reference allows to create a
sketch either on an element, as here the XY plane, or on a solid planar face that is not directly
accessible as a VB object.
The SetAbsoluteAxisData method is used to define the orientation of the sketch axis, that can
be on either side and can rotate inside of the support plane. A Factory2D object is created by
opening the sketch editor against the created sketch. This Factory2D object features methods
to create 2D objects.
line2D1.ReportName = 1
line2D2.ReportName = 2
When the sketch is created, an axis, that is the aggregation of a center point, and horizontal
line and vertical line (directions), is created.
The axis is retrieved in the GeometricElements collection of the Sketch object, the directions
are retrieved as objects aggregated by the axis. The two lines are here assigned an identifier
using their ReportName property that will be used by the 3D modeling services to retrieve
those elements inside of the sketch. They have no end-user meaning.
16. In the sketcher toolbar, select the circle icon and click twice to indicate successively the
center of the circle and a current point on the circle
17. Dim circle2D1 As Circle2D
18. Set circle2D1 = factory2D1.CreateClosedCircle(0.000000, 0.000000, 10.000000)
19.
20. Dim point2D1 As AnyObject
21. Set point2D1 = axis2D1.GetItem("Origin")
22.
23. circle2D1.CenterPoint = point2D1
24.
25. circle2D1.ReportName = 3
The CreateCloseCircle method of the Factory2D object is used to create the circle. It is first
created as centered at the point (0,0) with a radius of 10 mm. It is then constraint on the axis
center point using the CenterPoint property.
29. Select the pad icon to create a pad, and in the Pad Definition dialog box, choose a length
of 10 mm and click OK. The pad is created.
30. Dim shapeFactory1 As Factory
31. Set shapeFactory1 = part1.ShapeFactory
32.
33. Dim pad1 As Pad
34. Set pad1 = shapeFactory1.AddNewPad(sketch1, 20.000000)
35.
36. part1.Update
37.
The AddNewPad method of the ShapeFactory object is used to create the pad. It is created
using the sketch and the length of 20mm. The part is updated.
38. Click Stop Recording in the Stop Recording dialog box, or point to Stop Recording in the
Macro item of the Tools menu.
This closes the macro recording sequence and saves the macro in the selected file.
x=0
export CATMacroEditor=vi
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000 On Unix. This editor must be accessible
arrayOfVariantOfDouble1(1) = 0.000000 through the PATH environment variable.
arrayOfVariantOfDouble1(2) = 0.000000 Consult your administrator for more
arrayOfVariantOfDouble1(3) = 1.000000 information on how to proceed.
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 1.000000
arrayOfVariantOfDouble1(8) = 0.000000
For I = 1 To 5
Dim sketch1 As Sketch
Set sketch1 = sketches1.Add(refer1)
...
circle2D1.ReportName = 3
sketch1.CloseEdition
...
part1.Update
x = x + 25
Next
End Sub
In Short
This use case has shown how to record a macro, modify it and then launch its execution.
[Top]
References
[1
Adding a macro in a toolbar
]
[Top]
Access to the CATIA object model is provided using scripts in different ways depending on
the operating system and on the applications that can share their own objects with CATIA.
CATIA is an OLE Automation server for Windows NT and allows macro record and replay for
both Windows NT and UNIX. The following summarizes CATIA scripting capabilities.
The macros recorded from the Tools menu and the Record Macro dialog box use the Visual
Basic language, and not VBScript, to be compatible with Basic Script, allowing macro
portability between UNIX and Windows NT, that is a macro recorded on Windows NT can be
replayed on UNIX or the reverse. This means for example that Dim statements are recorded
to declare objects as returned values of properties or methods.
In-process access means that the script interpretation is performed in the same process as
CATIA. You usually run the macros from the Macros window triggered from the interactive
Tools->Macros command. In this case, the macro is processed by CATIA just like any other
command.
Out-process access means that you run the macro from another application running in
another process. In this case, the macro should first connect to CATIA to then access its
data. This connection starts CATIA if no CATIA process is being running.
You can find information about in-process and out-process access in:
In-process access means that the script interpretation is performed in the same process as
CATIA using the scripting engine(s) hosted by CATIA. You can run in-process macros with
UNIX and Windows. You have three means to run in-process macros:
1. You usually run the macros from the Macros window triggered from the interactive
Tools->Macros command. In this case, the macro is processed by CATIA just like
any other command.
2. You can start CATIA and request that a macro being executed as soon as CATIA is
started using the -macro option followed by the full path of the macro you want to
run:
3. You can start CATIA in batch to execute a macro using the -batch option followed by
the full path of the macro you want to run:
Out-process access means that you run the macro from another application running in
another process, such as from Visual Basic for Applications associated with products such as
Excel or Word, or from Microsoft Visual Basic 5 Development Studio. You can also use the
Windows Scripting Host to run VBScript or JScript macros by simply double clicking the
macro name from the Windows desktop or Explorer, or from the command console. You can
finally use VBScript or JScript macros embedded in html pages.
The macro should first connect to CATIA to then access its data. This connection starts CATIA
if no CATIA process is being running. The script is interpreted by the scripting engine hosted
by the application from which you start the macro.
• If CATIA is already running, the macro should simply connect to CATIA using the
GetObject method
• Dim CATIA As Object
Set CATIA = GetObject(, "CATIA.Application")
• If CATIA is not already running, the macro should start CATIA using the
CreateObject method
• Dim CATIA As Object
Set CATIA = CreateObject("CATIA.Application")
Another way is to use the Windows Scripting Host. This is a language-independent scripting
host which enables scripts written in different languages such as Visual Basic, JScript, and
Perl, to be run from the Windows desktop, the Windows Explorer, or the command console.
• With Visual Basic, your script should begin by the connection to CATIA, using either
CreateObject or GetObject, as follows:
• Dim CATIA
Set CATIA = WScript.CreateObject("CATIA.Application")
or
Dim CATIA
Set CATIA = WScript.GetObject("", "CATIA.Application")
• With JScript, your script should also begin by the connection to CATIA, using either
CreateObject or GetObject, as follows:
• var CATIA
CATIA = WScript.CreateObject("CATIA.Application")
or
var CATIA
CATIA = WScript.GetObject("","CATIA.Application")
Note that the GetObject method requires that its first argument be blank for both Basic
Script and JScript.
To run the macros from the Windows desktop, simply double click on the macro name.
These names are suffixed using vbs for Visual Basic, and with js for JScript.
To run the macros from the command console, use the cscript command as follows:
cscript e:\users\psr\Scripting\Sample\CATIA.js
You can also run macros embedded in a html page. These macros can be written in Visual
Basic and JScript. There are several ways of embedding a macro in a html page:
• The macro is written using the script tag and run when the page is loaded
• The macro is written using the script tag and is included or referenced by a form,
input, body, or a (anchor) tag.
• The macro is written using the a tag (anchor) and run as an hyperlink. This is possible
with JScript only.
Generate and helicoidal stair
Option Explicit
'------------------------------------------------------------------------
' COPYRIGTH DASSAULT SYSTEMES 2000
'------------------------------------------------------------------------
Dim Language as String
Language="VBScript"
' ***********************************************************************
' Purpose: Create an helicoidal Stair
' Assumtions:
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R6
' ***********************************************************************
' ------------------------------------------------------------------------
' VB Macro
'
' Object:
' Generate and helicoidal stair
' Input data
' Origin point and helix direction
' Starting point of helix and its pitch / height definition
' Height of each Step
'
' VB macro
' Initialize input data
' Compute number of required step for the helix height
' Loop on number of step and generate the geometry for each step in a HybridBody
'
' CATIA VB tools related to this sample
' Open a CATIA document and a CATPart
' Show/Noshow of wireframe and surfacic object
' Adding new Open-Body
' Create parameters and formula / Use it in geomety definition
' Catia methods required CATIAReference as input object / Generate reference for each input
geometry
' Create Generative Shape Design feature
' Update geometry / Note: done at the end in order to enhance creation performances
'
'------------------------------------------------------------------------
'------------------------------------------------------------------------
' Global Variables
' ---------------------------------------------------------
' Origin Points
Dim X0 As Double
Dim Y0 As Double
Dim Z0 As Double
'------------------------------------------------------------------------
' Main program
'------------------------------------------------------------------------
' Open a New Part
' Init global variable
' Generate geometry
' ------------------------------------------------------------------------
'
Sub CATMain()
' --------------------------------------------------------------
' Create a CATIA Part Docuument
' --------------------------------------------------------------
' Creating a Part Document
Dim PartDoc As Document
Set PartDoc = CATIA.Documents.Add ( "Part" )
' --------------------------------------------------------------
' Init global Values
' --------------------------------------------------------------
X0 = 0
Y0 = 0
Z0 = 0
X1 = 1000
Y1 = 0
Z1 = 0
A1 = 0
B1 = 0
C1 = 1
Pitch = 3600
Height = 3000
StepValue = 100
' --------------------------------------------------------------
' Declaring and setting working variables
' --------------------------------------------------------------
Dim iValide As Integer
HelixPitch = Pitch
HelixHeight = Height
HauteurMarche = StepValue
' --------------------------------------------------------------
' Setting knowledge objects and variables
' --------------------------------------------------------------
' Init working knowledge parameters
Dim parameters As Object
Set parameters = PartDoc.Part.parameters
' Working Parm object
Dim Parm As Object
' --------------------------------------------------------------
' Generating starting geometry (Reference points /Direction of helix /Helix)
' --------------------------------------------------------------
'
' Origin and Starting Point
Set Point1 = PartDoc.Part.HybridShapeFactory.AddNewPointCoord(X0, Y0, Z0)
myHBody.AppendHybridShape Point1
' Create formula defining Line offset value equal to helix height parameter
Set Formula = relations.CreateFormula("Formula.0", "", Line.EndOffset, "HelixHeight")
' Helix
Dim RefH1 As Object
Set RefH1 = PartDoc.Part.CreateReferenceFromObject(Line)
' --------------------------------------------------------------
' Generating Steps
' --------------------------------------------------------------
' --------------------------------------------------------------
' Loop on steps
' --------------------------------------------------------------
'
Dim CounterStep As Integer
For CounterStep = 1 To indice Step 1
' Line2
Set LinePt0Pt2 = PartDoc.Part.HybridShapeFactory.AddNewLinePtPt(Pt0, Pt2)
myHBody.AppendHybridShape LinePt0Pt2
Dim RefLinePt0Pt2 As Object
Set RefLinePt0Pt2 = PartDoc.Part.CreateReferenceFromObject(LinePt0Pt2)
'opposite-step surface
Dim Extrude As Object
Set Extrude = PartDoc.Part.HybridShapeFactory.AddNewExtrude(RefLinePt0Pt2, HauteurMarche,
0, Dir)
myHBody.AppendHybridShape Extrude
Set Formula = relations.CreateFormula("Formula.Step.2", "", Extrude.BeginOffset, "StepHeight")
Next
'Model update
' Note : Performed only at the end of geometry generation
PartDoc.Part.Update
End Sub
Note:
- The resulting document can be saved by setting the CAA_GSD_SAVE runtime
environment variable
- Moreover, if CAA_GSD_EXIT variable is setted, the macro exit from CATIA
CAAGsiCreatePtLnAndConvertToDatum is launched in CATIA [1]. No open document is
needed.
Opens the starting CATIA Part document and retieves OpenBody , the document
contains parameters in order to store the number of created iterations.
The VBScript macro use the "max" internal parameter to define the number of
iterations
' Array
' ----------------------------------------------------------
Dim TabExt ()
Dim TabMil ()
Dim TabLine()
Dim TabLineExpl()
Dim TabPtExpl()
ReDim TabExt(2*max)
ReDim TabMil(max)
ReDim TabLine(max)
ReDim TabLineExpl(max)
ReDim TabPtExpl(max)
Dim Pi As double
Dim R As double
Dim Omega As double
R = 50.0000
Pi = 3.14116
Omega= 2*Pi/max
Defines some parameters for creating point and line.
Note : In the sample lines form a sort of "hyperboloid" 3D form:
Extremities of lines are defines on two mathematical computed circles position of
point are taken a with 2*Pi/3 phase.
' ------------------------------------------------------
' GSD Geometrie Creation
' ------------------------------------------------------
Catia.SystemService.Print "(CAAGsiCreatePtLnAndConvertToDatum) Create Points and Lines "
'Draw line
Set reference1 = part1.CreateReferenceFromObject(TabExt(2*i-1))
Set reference2 = part1.CreateReferenceFromObject(TabExt(2*i))
Set TabLine(i) = hybridShapeFactory1.AddNewLinePtPt(reference1, reference2)
hybridBody1.AppendHybridShape TabLine(i)
part1.InWorkObject = TabLine(i)
next
part1.Update
Creates extremity points / lines / middle points of lines and keep in dedicated arrays
' Add OpenBodys for datum point and for datum line
Dim OpenBody1 As HybridBody
Dim OpenBody2 As HybridBody
Dim referencebody As Reference
hybridShapeFactory1.DeleteObjectForDatum reference5
hybridShapeFactory1.DeleteObjectForDatum reference5
next
part1.Update
Point datum and Line datum are stored respectively in an OpenBody for PointDatum
an one for LineDatum
' Rename
NewName ="PointDatum" & "." & i
Set referencedat1 = part1.CreateReferenceFromObject(TabPtExpl(i))
hybridShapeFactory1.ChangeFeatureName referencedat1 ,NewName
' -- Lines
' Change Color of Line
selection1.Clear()
selection1.Add(TabLineExpl(i))
Set VisPropSet1 = selection1.VisProperties
VisPropSet1.SetRealColor int(255*(i-1)/max), 255, int(255*(1-((i-1)/max)) ), 1
' Rename
NewName = "LineDatum" & "." & i
Set referencedat2 = part1.CreateReferenceFromObject(TabLineExpl(i))
hybridShapeFactory1.ChangeFeatureName referencedat2 ,NewName
next
Uses of visualisation method for setting color of an object (R,V,B) with each from 0 to
255
' Save
partDocument1.SaveAs sTmpPath & "\CAAGsiCreatePtLnAndConvertToDatum.CATPart"
' ---------------------------------------------------------------------------
' Close and Quit
' ---------------------------------------------------------------------------
partDocument1.Close
Catia.Quit
Note: The number of part update is optimized all along the VBScript macro
It allows to save performances in replaying macro
Option Explicit
' COPYRIGTH DASSAULT SYSTEMES 2000
Dim Language as String
Language="VBScript"
' ***********************************************************************
' Purpose: Create a Open Bodies
' Assumtions:
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R6
' ***********************************************************************
Sub CATMain()
End Sub
Create a Join surface
Option Explicit
' COPYRIGHT DASSAULT SYSTEMES 2000
Dim Language as String
Language="VBScript"
' ***********************************************************************
' Purpose: Create a Join surface
' Assumtions: .\samples\CAAGsiCreateJoinSurface.CATPart use as input geometry
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R6
' ***********************************************************************
Sub CATMain()
' Openning CATIA Part : CAAGsiCreateJoinSurface.CATPart
Dim sDocPath As String
sDocPath=CATIA.SystemService.Environ("CATDocView")
' Creating a Join (also named assemble) between Fill.1 and Extrude.1
Dim hybridShapeAssemble1 As HybridShapeAssemble
Set hybridShapeAssemble1 = hybridShapeFactory1.AddNewJoin(reference1, reference2)
End Sub
Generative Shape Design Creating an helicoidal Stair
This macro shows how to use Knowledge parameters and Generative Shape Design to
create repetitive geometry in a CATIA Macro:
The "Parm" and "Formula" objects are collections of knowledge parameters and
Formula.
The definition of knowledge parameters and their use in creating objects allows to
parameterize object creation.
That is a key point in using CATIA V5 objects.
For example, if the "StepHeight" is not correct in the resulting CATIA Part , it can be
interactively modified
and all the objects using "StepHeight" value are automatically updated.
For example, a formula can be associated with the Line object parameter in order to be
updated if the "HelixHeight" paramater is modified
The number of steps is directly related to the helix height and the step height.
The number of step and then of the objects created in the CATIA Part Document depend on
these two parameters
Generating Steps
' Create a new openbody
Set myHBody = PartDoc.Part.HybridBodies.Add()
'Point2 = Point Projected from the helix on the step ground plane
Dim Project1 As Object
Set Project1 = PartDoc.Part.HybridShapeFactory.AddNewProject(Pt3, RefPlane)
Project1.SolutionType = 0
Project1.Normal = True
myHBody.AppendHybridShape Project1
Set Pt2 = PartDoc.Part.CreateReferenceFromObject(Project1)
PartDoc.Part.HybridShapeFactory.GSMVisibility Pt2, 0
' Line2
Set LinePt0Pt2 = PartDoc.Part.HybridShapeFactory.AddNewLinePtPt(Pt0, Pt2)
myHBody.AppendHybridShape LinePt0Pt2
Dim RefLinePt0Pt2 As Object
Set RefLinePt0Pt2 = PartDoc.Part.CreateReferenceFromObject(LinePt0Pt2)
Note :The wireframe and shape design objects can be put in no-show using the specific
method of HybridShapeFactory: GSMVisibility
' End of loop - re-initializing the reference plane for the next step
' RefPlane = RefPlaneOffset
Set RefPlane = PartDoc.Part.CreateReferenceFromObject(PlaneOffset2)
Note: The update of the CATIA Part Document is done at the end for performances reason :
The generation of the geometry representation of the objects and their visualization is done
in one step
The reframing is done to view in the 3D window all objects created and updated once the
macro has been replayed
The macro opens a CATIA Part Document and creates a Join surface using pre-existing
geometry (Fill and Extrude).
CAAGsiCreateJoinSurface is launched in CATIA [1]. No open document is needed.
Opens the starting CATIA Part document that is used for creating new wireframe and
surface objects (In this test case a join).
Retrieving OpenBody
' Retrieving the active OpenBody
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = oPartDocument.Part.HybridBodies
Retrieves the OpenBody containing initial objects. It will be re-used for creating the
Join
The Fill and the Extrude surfaces used as input for the Join, are converted into
reference.
This operation is required in order to use the objects as input for the Join, all objects
used as input in IDL method interfaces are to be converted as references and passed
in creation methods .
' Creating a Join (also named assemble) between Fill.1 and Extrude.1
Dim hybridShapeAssemble1 As HybridShapeAssemble
Set hybridShapeAssemble1 = hybridShapeFactory1.AddNewJoin(reference1, reference2)
' Inserting the join in the current OpenBody
OpenBody1.AppendHybridShape hybridShapeAssemble1
Once created, the join has to be inserted in an OpenBody. In the test case, the
OpenBody containing the input geometry is re-used. .
Note : A new OpenBody should have been created in order to insert the join in a
separate OpenBody.
Language="VBSCRIPT"
Sub CATMain()
' Declarations
' ----------------------------------------------------------
Dim max as integer
max=20
Dim selection1
Dim parameters1 As Parameters
Dim intParam1 As Parameter
Dim parameters2 As Parameters
Dim realParam1 As Parameter
' Array
' ----------------------------------------------------------
Dim TabExt ()
Dim TabMil ()
Dim TabLine()
Dim TabLineExpl()
Dim TabPtExpl()
ReDim TabExt(2*max)
ReDim TabMil(max)
ReDim TabLine(max)
ReDim TabLineExpl(max)
ReDim TabPtExpl(max)
Dim Pi As double
Dim R As double
Dim Omega As double
R = 50.0000
Pi = 3.14116
Omega= 2*Pi/max
Dim i as integer
Dim angle As double
' ------------------------------------------------------
' GSD Geometrie Creation
' ------------------------------------------------------
Catia.SystemService.Print "(CAAGsiCreatePtLnAndConvertToDatum) Create Points and Lines "
'Draw line
Set reference1 = part1.CreateReferenceFromObject(TabExt(2*i-1))
Set reference2 = part1.CreateReferenceFromObject(TabExt(2*i))
Set TabLine(i) = hybridShapeFactory1.AddNewLinePtPt(reference1, reference2)
hybridBody1.AppendHybridShape TabLine(i)
part1.InWorkObject = TabLine(i)
next
part1.Update
' ------------------------------------------------------
' Convert to Datum
' ------------------------------------------------------
Catia.SystemService.Print "(CAAGsiCreatePtLnAndConvertToDatum) Convert to Datum "
' Add OpenBodys for datum point and for datum line
Dim OpenBody1 As HybridBody
Dim OpenBody2 As HybridBody
Dim referencebody As Reference
hybridShapeFactory1.DeleteObjectForDatum reference5
hybridShapeFactory1.DeleteObjectForDatum reference5
next
part1.Update
' ------------------------------------------------------
' Delete Useless points
' ------------------------------------------------------
for i=1 to max
selection1.Clear()
selection1.Add(TabExt(2*i-1))
selection1.Add(TabExt(2*i))
selection1.Delete
next
part1.Update
' ------------------------------------------------------
' Change graphic properties(color) and datum names
' ------------------------------------------------------
Catia.SystemService.Print "(CAAGsiCreatePtLnAndConvertToDatum) Update graphic properties
and names "
Dim referencedat1 As Reference
Dim referencedat2 As Reference
' Rename
NewName ="PointDatum" & "." & i
Set referencedat1 = part1.CreateReferenceFromObject(TabPtExpl(i))
hybridShapeFactory1.ChangeFeatureName referencedat1 ,NewName
' -- Lines
' Change Color of Line
selection1.Clear()
selection1.Add(TabLineExpl(i))
Set VisPropSet1 = selection1.VisProperties
VisPropSet1.SetRealColor int(255*(i-1)/max), 255, int(255*(1-((i-1)/max)) ), 1
' Rename
NewName = "LineDatum" & "." & i
Set referencedat2 = part1.CreateReferenceFromObject(TabLineExpl(i))
hybridShapeFactory1.ChangeFeatureName referencedat2 ,NewName
next
EnvSave = Catia.SystemService.Environ("CAA_GSD_SAVE")
Catia.SystemService.Print "EnvSave=" & EnvSave
If ( EnvSave <> "" ) Then
' ---------------------------------------------------------------------------
' Save As
' ---------------------------------------------------------------------------
' Save
Catia.SystemService.Print "(CAAGsiCreatePtLnAndConvertToDatum) SaveAs in :" & sTmpPath
& "\CAAGsiCreatePtLnAndConvertToDatum.CATPart"
partDocument1.SaveAs sTmpPath & "\CAAGsiCreatePtLnAndConvertToDatum.CATPart"
End If
EnvVar = Catia.SystemService.Environ("CAA_GSD_EXIT")
Catia.SystemService.Print "EnvVar=" & EnvVar
If ( EnvVar <> "" ) Then
' -------------------------------------------------------------
' Exit Catia
' -------------------------------------------------------------
Catia.SystemService.Print "Catia.Quit"
Catia.Quit
End If
End Sub
Language="VBSCRIPT"
Sub CATMain()
x=0
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
arrayOfVariantOfDouble1(3) = 1.000000
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 1.000000
arrayOfVariantOfDouble1(8) = 0.000000
For I = 1 To 5
sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1
line2D1.ReportName = 1
line2D2.ReportName = 2
circle2D1.ReportName = 3
sketch1.CloseEdition
part1.Update
part1.Update
x = x + 25
Next
End Sub
Create a text file, duplicate it and read the result.
Option Explicit
' COPYRIGTH DASSAULT SYSTEMES 2001
' ***********************************************************************
' Purpose: Create a text file, duplicate it and read the result.
' Assumtions:
' Author:
' Languages: VBScript BasicScript
' Locales: English
' CATIA Level: V5R6
' ***********************************************************************
Sub CATMain()
' ------------------------------------------
' Get the file system object
Dim oFileSys As FileSystem
Set oFileSys = CATIA.FileSystem
' ------------------------------------------
' Retrieve a folder for temporary files
Dim sTmpPath As String
sTmpPath=CATIA.SystemService.Environ("CATTemp")
If (Not oFileSys.FolderExists(sTmpPath)) Then
Err.Raise 9999,,"No Tmp Path Defined"
End If
' ------------------------------------------
' Delete possibly existing input and output files
Dim sFilOu As String ' Output file full path
sFilOu = sTmpPath & "/caatmpfilou.txt"
If (oFileSys.FileExists(sFilou)) Then
oFileSys.DeleteFile sFilOu
End If
' ---------------------------------------
' Create file FilIn
Dim oFilIn As File
Set oFilIn = oFileSys.CreateFile(sFilIn, FALSE)
Dim oStream As TextStream
Set oStream = oFilIn.OpenAsTextStream("ForWriting")
oStream.Write "<MESSAGE>" & sLF
oStream.Write "<VALUE>"
oStream.Write sMessage
oStream.Write "</VALUE>" & sLF
oStream.Write "</MESSAGE>" & sLF
oStream.Close
' ---------------------------------------
' Duplicate FilIn in FilOu
oFileSys.CopyFile sFilIn, sFilOu, FALSE
' ---------------------------------------
' Get the result from the output file
Dim oFilOu As File
Set oFilOu = oFileSys.GetFile(sFilOu)
Set oStream = oFilOu.OpenAsTextStream("ForReading")
oStream.Close
msgbox sMessage
End Sub
Open an Existing Document
Option Explicit
' COPYRIGHT DASSAULT SYSTEMES 2001
' *****************************************************************************
' Purpose: Open an Existing Document.
' Assumtions: Looks for CAAInfReadDocument.CATPart
' in the CATDocView
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R7
' *****************************************************************************
Sub CATMain()
' -----------------------------------------------------------------------------------------------
' Optional: allows to find the sample wherever it may be installed
Dim sDocPath As String
sDocPath=CATIA.SystemService.Environ("CATDocView")
If (Not CATIA.FileSystem.FolderExists(sDocPath)) Then
Err.Raise 9999,,"No Doc Path Defined"
End If
' ------------------------------------------------------------------------------------------------
'Open the document and add it as the last item of the collection of documents.
'Create and display a new window for the document.
'Activate the document and its window.
Dim iPartDoc As Document
Set iPartDoc = CATIA.Documents.Open(sDocPath & _
"\online\CAAScdInfUseCases\samples\CAAInfReadDocument.CATPart")
End Sub
Close a Document
Option Explicit
' COPYRIGHT DASSAULT SYSTEMES 2001
' *****************************************************************************
' Purpose: Close a Document.
' Assumtions: Looks for CAAInfReadDocument.CATPart
' in the CATDocView
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R7
' *****************************************************************************
Sub CATMain()
' -----------------------------------------------------------------------------------------------
' Optional: allows to find the sample wherever it may be installed
Dim sDocPath As String
sDocPath=CATIA.SystemService.Environ("CATDocView")
If (Not CATIA.FileSystem.FolderExists(sDocPath)) Then
Err.Raise 9999,,"No Doc Path Defined"
End If
' ------------------------------------------------------------------------------------------------
End Sub