 |
This macro shows you how to create a
component instance in a 2D viewer of a Schematic document. It also shows
how to create an instance and connect that to an existing one at the same
time. To create a Schematic component instance, its reference component
needs to be identified. This use case illustrates how to specify that
reference based on a Schematic component catalog.

In this use case, the "Blocking Valve" and the "Control Valve" component
references will be used. |
 |
CAASchPlaceComponent is launched in CATIA
[1]. No open document is needed. Special
environment must be available to successfully run this macro:
- RADE must be installed.
- CAASchPlatformModeler.edu must exist in CAADoc folder.
- Build CAASchAppBase.m and CAASchAppUtilities.m, located in
CAASchPlatformModeler.edu (RADE is required).
- Copy generated DLLs, CAASchAppBase.dll and
CAASchAppUtilities.m, respectively, to the run-time environment
folder "intel_a\code\bin."
- Copy CAASCHEDUApp.CATfct, located CAASchPlatformModeler.edu\CNext\resources\graphic,
to the run-time environment folder "intel_a\resources\graphic."
- Copy CAASchPlatformModeler.edu\CNext\code\dictionary\CAASchPlatformModeler.edu.dico
to the run-time environment folder "intel_a\code\dictionary."
CAASchPlaceComponent.CATScript
is located in the CAAScdSchUseCases module.
Execute macro (windows
only). |
 |
CAASchPlaceComponent includes the
following steps:
- Prolog
- Place a
Schematic component instance in free space (not connected to any other
object).
- Place a
Schematic component instance and connect it to instance created in
previous step.
Prolog
The macro first loads two documents: CAASCH_Sample.catalog and
CAASCH_RouteForPlacement2.CATProduct.
...
' -------------------------------------------------------------------------
' Open the schematic document
Dim sCtlgFilePath
sCtlgFilePath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _
"online\CAAScdSchUseCases\samples\CAASCH_Sample.catalog")
Dim objSchCtlgDoc As Document
Set objSchCtlgDoc = CATIA.Documents.Open(sCtlgFilePath)
' Open main schematic P&ID design document (for new component instances created here)
Dim sFilePath
sFilePath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _
"online\CAAScdSchUseCases\samples\CAASCH_RouteForPlacement2.CATProduct")
Dim objSchDoc As Document
Set objSchDoc = CATIA.Documents.Open(sFilePath)
...
|
Next, the macro acquires the schematic root object from the document.
The schematic root is the top node of the object instance tree in a
schematic document.
...
' Find the top node of the schematic object tree - schematic root.
Dim objPrdRoot As Product
Dim objSchRoot As SchematicRoot
If ( Not ( objSchDoc Is Nothing ) ) Then
Set objPrdRoot = objSchDoc.Product
If ( Not ( objPrdRoot Is Nothing ) ) Then
Set objSchRoot = objPrdRoot.GetTechnologicalObject("SchematicRoot")
End If
End If
... |
Place a
Schematic component instance in free space (not connected to any other
object).
The SchematicRoot interface provides the GetCompSymbolFromCatalog method
to retrieve the graphical representation of a specific Schematic component
reference by name. In this case, the "Blocking Valve" is chosen. Based on
this graphical representation, the macro calls the GetSchObjOwner to obtain
the Schematic component reference.
...
'-----------------------------------------------------------------------
' Get the first symbol from component catalog.
'-----------------------------------------------------------------------
Set objSchGRRCtlg = objSchRoot.GetCompSymbolFromCatalog ("Blocking Valve",objSchCtlgDoc)
...
'---------------------------------------------------------------------
' Get the owner of the first symbol. That is a reference component
' in the catalog.
'---------------------------------------------------------------------
Set objSchCntblRef = objSchGRRCtlg.GetSchObjOwner
... |
Method PlaceInSpace is then called to create a new instance of the
"Blocking Valve" reference component in the design document. Note that the
placement position and orientation are defined by a 6-words double-array
(db6Array) which is an input to the method.
'--------------------------------------------------------------------------
' Component instance (to be created below) orientation matrix.
' x-axis = (1.0,0.0)
' y-axis = (0.0,1.0)
' origin = (100.0,300.0)
'--------------------------------------------------------------------------
Dim db6Array(6) As CATSafeArrayVariant
db6Array(0)=1.0
db6Array(1)=0.0
db6Array(2)=0.0
db6Array(3)=1.0
db6Array(4)=145.0
db6Array(5)=130.0
'-------------------------------------------------------------------
' Place an instance of the catalog reference in an empty space in
' the design document
' Note that the target document is an input to PlaceInSpace
'-------------------------------------------------------------------
Set objSchComp2Ref = objSchRoot.GetInterface ("CATIASchComponent2",objSchCntblRef)
If ( Not ( objSchComp2Ref Is Nothing ) ) Then
...
objSchComp2Ref.PlaceInSpace objSchGRRCtlg,db6Array,objSchDoc,objSchCompInstA
...
End If
End If
End If
... |
Place a
Schematic component instance and connect it to instance created in previous
step
As in previous step, the macro find the reference component from the
catalog by the name of the graphical representation of the component. In
this case, the name is "Control Valve"
...
Set objSchGRRCVCtlg = objSchRoot.GetCompSymbolFromCatalog ("Control Valve",objSchCtlgDoc)
...
'---------------------------------------------------------------------
' Get the owner of the second symbol. That is a reference component
' in the catalog.
'---------------------------------------------------------------------
Set objSchCntblCVRef = objSchGRRCVCtlg.GetSchObjOwner
... |
Unlike previous step, instead of specifying a placement position, the
macro obtains the SchComponent interface from the "Blocking Valve"
component instance (created in previous step) and creates an Control Valve
component instance by calling the PlaceOnComponentWithInfo method of the
interface.
In the comment section of the following code segments, instance A refers
to "Blocking Valve" instance that was created in previous step and instance
B refers to "Control Valve" instance the macro is about to create.
...
'----------------------------------------------------------------
' 1- QueryConnectAbility.
' Ask the reference
of the new instance B for information
' to use in
compatibility checking. The objCompRefPlaceInfo
' is an output and
should be used as a "black box".
' It is the input to
the next call.
'
' 2- IsTargetOKForPlace
' Check whether A is
compatible to B in making a connection.
' A is the first
instance, it is the "target".
' objCompatInfo is
an output and should be used as
' a "black box". It
is an input to the next call.
'
' 3- GetBestFitPlaceInfo
' Input the
placement location, close to the x-y location of
' the connector of
objSchCompInstA (A) that you want to connect
' B to.
' objFinalPlaceInfo
is an output and should be used as
' a "black box". It
is an input to the next call.
'
' 4- PlaceOnComponentWithInfo
' Place a new
instance with the black box info.
'
'----------------------------------------------------------------
' -- step 1
Set objCompRefPlaceInfo = objSchCompCVRef.QueryConnectAbility _
(objSchGRRCVCtlg)
' -- step 2
objSchCompatInstA.IsTargetOKForPlace objSchGRRCompInstA, _
objCompRefPlaceInfo, objCompatInfo, bYesCompat
Dim db2Pt(2) As CATSafeArrayVariant
'-- 6.50 is the relative x coordinate of the
right connector
'-- from the symbol origin of the "Blocking
Valve" instance.
db2Pt(0) = 145.0 + 6.50
db2Pt(1) = 130.0
If ( bYesCompat ) Then
...
bFindAllSolutions = false
' -- step 3
objSchCompatInstA.GetBestFitPlaceInfo db2Pt, objCompatInfo, _
objFinalPlaceInfo, bFindAllSolutions
If ( Not ( objFinalPlaceInfo is Nothing ) )
Then
' -- step 4
Set objSchCompInstB = objSchCompCVRef.PlaceOnComponentWithInfo _
(objFinalPlaceInfo)
... |
|