The following example supposes a
Part or a
Product is opened. It asks the end user to select a
Shape in the current window. It then sends message boxes containing the names of the automation objects contained in the specification tree path corresponding to the shape selected, and, regarding the
automation objects which are products (only products which are components), a message box containing the
abcissa of the translation of the product compared to its reference product.
Dim Status,Feature,LeafProduct,LeafProductProcessed,InputObjectType(0)
Dim Document,Selection,AutomationTreeNodeOrProduct,Position,AxisComponentsArray(11)
Set Document = CATIA.ActiveDocument : Set Selection = Document.Selection
'We propose to the user that he select a feature
InputObjectType(0)="AnyObject"
Status=Selection.SelectElement2(InputObjectType,"Select a feature",true)
if (Status = "Cancel") then Exit Sub
Set Feature = Selection.Item(1).Value
Set LeafProduct = Selection.Item(1).LeafProduct
LeafProductProcessed = true
if (LeafProduct.Name<>"InvalidLeafProduct") then LeafProductProcessed = false
Set AutomationTreeNodeOrProduct = Feature
do while (TypeName(AutomationTreeNodeOrProduct)<>"Application")
' We send a message box, if AutomationTreeNodeOrProduct is not nor a Shapes object neither a PartDocument object
if ((TypeName(AutomationTreeNodeOrProduct)<>"Shapes") And _
(TypeName(AutomationTreeNodeOrProduct)<>"Bodies") And _
(TypeName(AutomationTreeNodeOrProduct)<>"PartDocument") And _
(TypeName(AutomationTreeNodeOrProduct)<>"Products") And _
(TypeName(AutomationTreeNodeOrProduct)<>"ProductDocument")) then
msgbox AutomationTreeNodeOrProduct.Name
if (TypeName(AutomationTreeNodeOrProduct)="Product") then
' We display a message box containing the abcissa of the translation, except in the case of the
' root product
if (TypeName(AutomationTreeNodeOrProduct.Parent.Parent)<>"Application") then
Set Position = AutomationTreeNodeOrProduct.Position
Call Position.GetComponents(AxisComponentsArray)
msgbox AxisComponentsArray(9)
end if
end if
end if
' We determine the next automation tree node or product
Set AutomationTreeNodeOrProduct = AutomationTreeNodeOrProduct.Parent
if ((TypeName(AutomationTreeNodeOrProduct)="Application") And (Not LeafProductProcessed)) then
' The specification tree path corresponding to the selection contains at least one product, which the current
' loop as not yet processed. It means that the parent in the specification tree of the feature corresponding
' to the last message box sent is LeafProduct
Set AutomationTreeNodeOrProduct = LeafProduct
LeafProductProcessed = true
end if
loop
If you run the preceeding piece of script, the current document beeing a product with the following specification
tree:
+--------+
!Product3!
+----+---+
!
+- Product2 (Product2.1) 'translation value: 10
! !
! +- Product1 (Product1.1) 'translation value: 20
! !
! +- Part1 (Part1.1)
! !
! +- Part1
! !
! +- PartBody
! !
! +- Pad.1
+- Part2 (Part2.1)
and you select Pad.1, the message boxes displayed will be:
Pad.1
PartBody
Part1
Part1.1
Product1.1
20
Product2.1
10
Product3