|
This macro shows how to create wireframe and shape feature / convert to
datum of corresponding dimension / delete features /change
properties of features in a CATIA Part document.
The macro opens a CATIA Part Document CAAGsiStart.CATPart
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 includes five
steps:
- Opening the Part Document and Retrieving the
Current Open Body
- Creating Associative Points and Lines
- Converting Middle Points and Lines into Datum
- Deleting Useless Remaining Points
- Changing Graphic Properties (Color) and Datum Names
- Saving the Part Document and Exiting CATIA
Openning the Part Document and Retrieving the
Current Open Body
' Open CATIA Part : CAAGsiCreateJoinSurface.CATPart
Dim sDocPath As String
sDocPath=CATIA.SystemService.Environ("CATDocView")
Dim partDocument1 As Document
Set partDocument1 = documents1.Open(sDocPath & "\online\CAAScdGsiUseCases\samples\CAAGsiStart.CATPart")
Dim part1 As Part
Set part1 = partDocument1.Part
' Retrieving the active OpenBody
Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Open_body.1")
|
Opens the starting CATIA Part document and retieves OpenBody , the
document contains parameters in order to store the number of created
iterations.
Creating Associative Points and Lines
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)
|
Defines VBScript arrays for keeping generated hybridshapes objects in
order to access them in following steps
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 "
for i=1 to max
'Create two points
Angle = Omega * (i-1)
Set TabExt(2*i-1) = hybridShapeFactory1.AddNewPointCoord(R*cos(Angle), R*sin(Angle), 100.000000)
hybridBody1.AppendHybridShape TabExt(2*i-1)
part1.InWorkObject = TabExt(2*i-1)
Set TabExt(2*i) = hybridShapeFactory1.AddNewPointCoord(R*cos(Angle+2*Pi/2), R*sin(Angle+2*Pi/2), -100.000000)
hybridBody1.AppendHybridShape TabExt(2*i)
part1.InWorkObject = TabExt(2*i)
'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)
'Generate Intersection Point
Set reference3 = part1.CreateReferenceFromObject(TabLine(i))
Set originElements1 = part1.OriginElements
Set hybridShapePlaneExplicit1 = originElements1.PlaneXY
Set reference4 = part1.CreateReferenceFromObject(hybridShapePlaneExplicit1)
Set TabMil(i) = hybridShapeFactory1.AddNewIntersection(reference3, reference4)
hybridBody1.AppendHybridShape TabMil(i)
part1.InWorkObject = TabMil(i)
'Settings status parameter : Num_Of_Points_Created parameter
intParam1.Value = i
'Settings status parameter : Percentage_Completed parameter
realParam1.Value = i/max *100
next
part1.Update
|
Creates extremity points / lines / middle points of lines and keep in
dedicated arrays
Converting Middle Points and Lines into Datum
' ------------------------------------------------------
' Convert to Datum
' ------------------------------------------------------
' Add OpenBodys for datum point and for datum line
Dim OpenBody1 As HybridBody
Dim OpenBody2 As HybridBody
Dim referencebody As Reference
Set OpenBody1 = hybridBodies1.Add()
Set referencebody = part1.CreateReferenceFromObject(OpenBody1)
hybridShapeFactory1.ChangeFeatureName referencebody , "DatumPointBody"
Set OpenBody2 = hybridBodies1.Add()
Set referencebody = part1.CreateReferenceFromObject(OpenBody2)
hybridShapeFactory1.ChangeFeatureName referencebody , "DatumLineBody"
' Loop on element to convert
for i=1 to max
'Isolate Intersection point
Set reference5 = part1.CreateReferenceFromObject(TabMil(i))
Set TabPtExpl(i) = hybridShapeFactory1.AddNewPointDatum(reference5)
OpenBody1.AppendHybridShape TabPtExpl(i)
part1.InWorkObject = TabPtExpl(i)
hybridShapeFactory1.DeleteObjectForDatum reference5
'Isolate the line
Set reference5 = part1.CreateReferenceFromObject(TabLine(i))
Set TabLineExpl(i) = hybridShapeFactory1.AddNewLineDatum(reference5)
OpenBody2.AppendHybridShape TabLineExpl(i)
part1.InWorkObject = TabLineExpl(i)
hybridShapeFactory1.DeleteObjectForDatum reference5
next
part1.Update
|
Point datum and Line datum are stored respectively in an OpenBody for
PointDatum an one for LineDatum
Deleting Useless Remaining Points
' ------------------------------------------------------
' 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
|
Uses of selection mecanism in order to manage deletion.
All extremities of lines are removed.
Changing Graphic Properties (Color) and Datum
Names
' ------------------------------------------------------
' Change graphic properties(color) and datum names
' ------------------------------------------------------
Dim referencedat1 As Reference
Dim referencedat2 As Reference
' Loop on element to modify
for i=1 to max
' -- Points
' Change Color of Middle Point
selection1.Clear()
selection1.Add(TabPtExpl(i))
Set VisPropSet1 = selection1.VisProperties
VisPropSet1.SetRealColor 255, int(255*(i-1)/max), int(255*(1-((i-1)/max)) ), 1
' 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
Uses of ChangeFeatureName method implemented in HybridshapeFactory for
renaming Feature
Important note : The availability of this method is temporary proposed: a
more general way for renaming features will be provided in future
releases.
Saving the Part Document and Exiting CATIA
On Error Resume Next
CATIA.DisplayFileAlerts = False
' ---------------------------------------------------------------------------
' Save As
' ---------------------------------------------------------------------------
' Note : Optional - allows to specify where document should be saved
Dim sTmpPath As String
sTmpPath=CATIA.SystemService.Environ("CATTemp")
If (Not CATIA.FileSystem.FolderExists(sTmpPath)) Then
Err.Raise 9999,,"No Tmp Path Defined"
End If
' Save
partDocument1.SaveAs sTmpPath & "\CAAGsiCreatePtLnAndConvertToDatum.CATPart"
' ---------------------------------------------------------------------------
' Close and Quit
' ---------------------------------------------------------------------------
partDocument1.Close
Catia.Quit
|
Allow to store document in a user choosen directory and name
Note: The number of part update is optimized all along the VBScript
macro
It allows to save performances in replaying macro
|