选择元素
SelectedElement (Object)
IUnknown |
+---IDispatch |
+---CATBaseUnknown |
+---CATBaseDispatch |
+---AnyObject |
+---SelectedElement
file:///F:\\catiav5r16doc_en\\English\\online\\CAAScdBase\\CAAScdAutomationHome.htm
Represents an element contained by a Selection object.
This object is an object contained by a Selection object. The Selection object contains SelectedElement objects, which are accessed through the Selection.Count2 and Selection.Item2 methods.
Property Index
Document
Returns the document to which the selected element belongs.
LeafProduct
Returns the leaf product corresponding to the selection in the specification tree.
Reference
Returns a Reference version of the Value property.
Type
Returns the string constant which describes the selected element Automation type.
Value
Returns the actual selected automation object.
Method Index
GetCoordinates
Returns the coordinates of the pick point.
Properties
o Property Document( ) As CATIADocument (Read Only)
Returns the document to which the selected element belongs.
o Property LeafProduct( ) As CATIABase (Read Only)
Returns the leaf product corresponding to the selection in the specification tree.
Role: Returns the leaf Product (component, corresponding for example to \in the specification tree). The AnyObject returned is a Product if a product appears in the specification tree, in the path corresponding to the current selection, and a fake AnyObject whose AnyObject.Name
property equals to \
Cumulated with the use of the AnyObject.Parent property (which enables to navigate into the object structure), the current property enables the scripter to obtain the path, in the specification tree, corresponding to the selection. Example:
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)=\
Status=Selection.SelectElement2(InputObjectType,\ if (Status = \ Set Feature = Selection.Item(1).Value
Set LeafProduct = Selection.Item(1).LeafProduct LeafProductProcessed = true
if (LeafProduct.Name<>\ Set AutomationTreeNodeOrProduct = Feature
do while (TypeName(AutomationTreeNodeOrProduct)<>\
' We send a message box, if AutomationTreeNodeOrProduct is not nor a Shapes object neither a PartDocument object
if ((TypeName(AutomationTreeNodeOrProduct)<>\ (TypeName(AutomationTreeNodeOrProduct)<>\ (TypeName(AutomationTreeNodeOrProduct)<>\ (TypeName(AutomationTreeNodeOrProduct)<>\
(TypeName(AutomationTreeNodeOrProduct)<>\ msgbox AutomationTreeNodeOrProduct.Name
if (TypeName(AutomationTreeNodeOrProduct)=\
' We display a message box containing the abcissa of the translation, except in the case of the ' root product
if (TypeName(AutomationTreeNodeOrProduct.Parent.Parent)<>\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)=\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
o Property Reference( ) As CATIAReference (Read Only)
Returns a Reference version of the Value property. Role: Returns a Reference version of Value .
o Property Type( ) As CATBSTR (Read Only)
Returns the string constant which describes the selected element Automation type. This type is returned by the Value property, and may be, for instance \ or \.
Caution: This property gives the leaf automation type of the object, in the inheritance hierarchy. Nevertheless,
after
a
call
to
Selection.SelectElement2 , Selection.SelectElement3 ,
Selection.SelectElement4 , Selection.IndicateOrSelectElement2D or
Selection.IndicateOrSelectElement3D , this property gives the input filter string constant relative to the
effective selection (more precisely the first filter string constant delivered through the iFilterType parameter, for which the current automation object fullfills the string constant). This string constant may be an automation object name corresponding to the iFilterType parameter with which
Selection.SelectElement2 has previously been called, or even a CATSelectionFilter value name.
Example:
Suppose you run the following piece of script:
Set Selection = CATIA.ActiveDocument.Selection
' We propose to the user that he select a Prism or a Hole
ReDim InputObjectType(1) : InputObjectType(0)=\ Status=Selection.SelectElement2(InputObjectType,\ if (Status = \ AutomationType = Selection.Item(1).Type
If the user selects a Pad, the script AutomationType variable will contain \ and not \. Consequently, in most cases, use the VBScript TypeName function instead of this property.
o Property Value( CA) As TBaseDispatch (Read Only)
Returns the actual selected automation object.
Methods
o Sub GetCoordinates( CA TSafeArrayVariant ioPoint)
Returns the coordinates of the pick point. Parameters:
oPoint
The coordinates of the pick point, i.e. the hit between the geometric object and the cursor. The length of this parameter will be 3, except if the document is a
DrawingDocument
Example:
This example retrieves the coordinates of the pick point in the array myArray:
Dim oSelElem As SelectedElement
Set oSelElem = CATIA.ActiveDocument.Selection.Item(1) ReDim myArray(2)
oSelElem.GetCoordinates myArray
选择方法 Selection (Object)
IUnknown |
+---IDispatch |
+---CATBaseUnknown |
+---CATBaseDispatch |
+---AnyObject |
+---Selection
file:///F:\\catiav5r16doc_en\\English\\online\\CAAScdBase\\CAAScdAutomationHome.htm
Represents the selection.
The Selection object contains the features the end user selected, usually with the mouse, and which are candidates as subjects for the next action.
A feature possess parent objects in the specification tree (hierarchy). For example, the Pad below possess parent objects in the specification tree:
+--------+ !Product3! +--------+ !
+- Product2 (Product2.1) ! !