Tips and Techniques
Tip for Writing SMARTEAM Script
by Aliaksei Rudzko, Software Development Engineer, EADS Matra Datavision
In a regular SMARTEAM script on any event, you need to get the currently selected object. Usually, this object may be obtained from a records list converted from the first parameter of the script. It looks like this:
Dim MySession As ISmSession
Dim FirstRec As Object 'ISmRecordList
Dim MyObject As ISmObject
'Get session
Set MySession = SCREXT_ObjectForInterface(ApplHndl)
'Convert first parameter to ISmRecordList
CONV_RecListToComRecordList FirstPar,FirstRec
'Get the object
Set MyObject = MySession.ObjectStore.ObjectFromData(FirstRec.GetRecord(0)).Clone
The example above works fine until the user picks an object from the "Links" window. In this case, the Record List returned will contain composite information about the parent object, child object, and link between them. Neither of the records contain headers "OBJECT_ID" or "CLASS_ID." In fact, the headers in this case will be "N.OBJECT_ID" and "N.CLASS_ID", where N is a ROLE of the object in a parent-child relation. So, your script should look different:
Dim MySession As ISmSession
Dim FirstRec As Object 'ISmRecordList
Dim MyObject As ISmObject
Dim classId As Integer, objId As Long
Dim i As Integer
Dim role As String
'Get session
Set MySession = SCREXT_ObjectForInterface(ApplHndl)
'Convert first parameter to ISmRecordList
CONV_RecListToComRecordList FirstPar,FirstRec
classId = 0
objId = 0
role = "Not important"
If FirstRec.RecordCount = 0 Then
'Show error message here
Exit Function
End If
'Let's find the Class ID in headers
For i = 0 To FirstRec.HeaderCount - 1
If FirstRec.Headers.Item(i).Name Like "*.CLASS_ID" _
Or FirstRec.Headers.Item(i).Name = "CLASS_ID" Then
If Not (FirstRec.Headers.Item(i).Name = FirstRec.ValueByIndex(i, 0) & ".CLASS_ID") _
Then
classId = FirstRec.ValueByIndex(i, 0)
If Not (FirstRec.Headers.Item(i).Name = "CLASS_ID") Then
'Here is where we know the role of this object
role = Left(FirstRec.Headers.Item(i).Name, _
Len(FirstRec.Headers.Item(i).Name) - 9)
End If
End If
End If
Next i
'Now Object ID
For i = 0 To FirstRec.HeaderCount - 1
If FirstRec.Headers.Item(i).Name Like "*.OBJECT_ID" Or _
FirstRec.Headers.Item(i).Name = "OBJECT_ID" Then
If FirstRec.Headers.Item(i).Name = role & ".OBJECT_ID" Or _
FirstRec.Headers.Item(i).Name = "OBJECT_ID" Then
objId = FirstRec.ValueByIndex(i, 0)
End If
End If
Next i
If classId <> 0 And objId <> 0 Then
Set MyObject = MySession.ObjectStore.RetrieveObject(classId, objId)
End If
The Hints, Tips, and Tools page of the CATIA Interoperability Project Office
Visit www-5.ibm.com/de/caeserv/cicoc/ci_h+t.htm for a variety of short cuts and suggestions on how to best perform several functions. A recent addition is titled "Select a box for plotting a drawing area." At www-5.ibm.com/de/caeserv/cicoc/tips/boxplot.htm, you'll see how the Tools/Image functionality of CATIA V5 can be used to select a plot area to give out a Quick Plot.
Visit this site often to see how the latest hints and tips can be used to help you get the most out of your CATIA installation
|