Func SelectElement2( CATSafeArrayVariant iFilterType,
CATBSTR iMessage,
boolean iObjectSelectionBeforeCommandUsePossibility) As CATBSTR
Runs an interactive selection command.
Role: SelectElement2 asks the end user to select a feature (in the geometry or in the specification tree). During the selection, when end user will move the mouse above a feature which maps the given filter, the mouse pointer will be the "hand" cursor, and when end user will move the mouse above a feature which does not map the given filter, the mouse pointer will be the "no entry" cursor.
If iObjectSelectionBeforeCommandUsePossibility is equal to False:
The end user is asked to interactively select an appropriate element. When this is done, the Selection object is cleared, and filled with the selected element.
If iObjectSelectionBeforeCommandUsePossibility is equal to True:
SelectElement2 determines whether the automation objects specified in SelectedElement.Value, for the SelectedElement objects contained in the current selection, or one of the parents of the automation objects (see AnyObject.Parent) is an appropriate element:
If it is the case, no interaction is asked to the end user, the Selection object is cleared, and filled with the appropriate element.
Otherwise, the Selection object is cleared, and the end user is asked to interactively select an appropriate element. When this is done, the selection is filled with the selected element.
Note: During the selection scan to find an automation object, a "Product" string constant specified in iFilterType will imply that SelectElement2 will also look at the possible automation object specified in SelectedElement.LeafProduct .
After a call to SelectElement2, if the return value equals to "Normal", a call to the Count2 method will return one, and a call to Item2(1) will return the selected element.
Note: If the scripting language is Visual Basic for Applications or Visual Basic 6 Development Studio, then, you have to know that the use of an interactive selection method such as this one from a form (dialog box) method requires some constraints regarding the content of an average form method.
If your macro possess a form method which calls the SelectElement2 method, then, the content of an average form method of your macro must begin by a test, which checks that no form method is currently being executed and, otherwise, go out of the method. This constraint enable to prevent that, during the execution of the SelectElement2 method from a form method, when CATIA asks the end user to select a feature:
the users select a dialog object of a form (CATIA going on asking the end user to select a feature)
this selection trigger the corresponding form method
this run CATIA automation objects methods, CATIA going on asking the end user to select a feature
which would lead to unpredictable results.
The code will be the following way:
- macro module main variables:
Dim AFormMethodIsBeingExecuted As Boolean
- form method calling SelectElement2:
Private Sub FormPossessingOneMethodCallingSelectElement2_Click()
Dim InputObjectType(0), Status
AFormMethodIsBeingExecuted = True
InputObjectType(0)="TriDimFeatEdge"
Status=Selection.SelectElement2(InputObjectType,"Select an edge",false)
AFormMethodIsBeingExecuted = False
End Sub
- average form method:
Private Sub AverageForm_Click()
If (AFormMethodIsBeingExecuted) Then Exit Sub
. . .
' content of the form method itself
. . .
End Sub
Parameters:
iFilterType
An array of strings constants defining the automation object types with which the selection will be filtered. During the selection, when the end user will move the mouse (above the geometry or the specification tree), if the feature under the mouse does not map iFilterType, the cursor will be the "no entry" cursor.
The resulting filter is a logical OR of the supplied strings constants. For instance if the array contains two elements "Point" and "Line", when the end user will move the mouse above the geometry, if there is a feature under a mouse, which is a
HybridShapePointCoord object (you have to know that the Point object is a parent object of the HybridShapePointCoord object ), then, the cursor will be a "hand" cursor. At the opposite, if there is a feature under a mouse, which is neither a Point nor a Line, the cursor will be a "no entry" cursor.
Beside the automation object names, the CATSelectionFilter value names are supported.
iMessage
A string which instructs the user what to select. This string is displayed in the message area located at the left of the power input area.
iObjectSelectionBeforeCommandUsePossibility
Enables the script to support the possibility, for the user, to select a required object before running the script.
If the scripter:
writes a script calling SelectElement2, giving as iFilterType parameter an array containing one string: "Pad"
for the first call to SelectElement2 made by the script, the iObjectSelectionBeforeCommandUsePossibility is set to True
the scripter associates the script to an Icon. He will proceed as following:
in the Tools menu, select the Customize item. A window appears.
select the Commands Tab. The window contains two lists.
in the list on the left, select the Macros value
select the "Show Properties" push button
select the button on the right of the Icon label. A window containing a list of icons appears
select an Icon
select the Close button. The window containing the icon list disappears
in the list on the right, push the key 1 of the mouse, the cursor beeing on the macro to associate to an Icon. Then drag to a desired Toolbar. The Icon has been added to the Toolbar.
Then the user will be able to implement the following scenario:
select a Pad
select the Icon mentioned above. This runs the script.
During the execution of the script, the script will detect that the selected Pad is required as input, and the first call to SelectElement2 will not ask to the user to interactively select a Pad: the Pad selected before the script execution will be taken.
Note:Regarding the features selected by the user (a Pad in the example above), all the automation objects specified in SelectedElement.Value for the current selection SelectedElement objects must be used: if an automation object specified in SelectedElement.Value is not asked by the input filter, the SelectElement2 method will ask the user to interactively select an appropriate element.
A False value for the iObjectSelectionBeforeCommandUsePossibility parameter may be used although the selection is not empty before entering the method. This enables that, during the selection, the selected elements remain highlighted.
Caution: After a call to SelectElement2 , the iObjectSelectionBeforeCommandUsePossibility parameter being set to False, the elements which were selected before the call to SelectElement2 are not any more in the selection (unless the user selected one of them!). Consequently, such a use of the False value for the iObjectSelectionBeforeCommandUsePossibility parameter requires the following code:
save the selection content in save variables
call the SelectElement2 method, the iObjectSelectionBeforeCommandUsePossibility parameter being set to False
copy the selected element to a dedicated variable
merge the selected element with the save variables, and put the result in the selection. This mean:
if the selected element does not belong to the save variables, add the save variables to the selection
otherwise, remove the selected element from the save variables, clear the selection and then, add the save variables to the selection
oOutputState
The state of the selection command once SelectElement2 returns. It can be either "Normal" (the selection has succeeded), "Cancel" (the user wants to cancel the VB command, which must exit immediately), "Undo" or "Redo".
Note:The "Cancel" value is returned if one of the following cases occured:
an external command has been selected
the ESCAPE key has been selected
another window has been selected, the window document beeing another document than the current document
Caution:All scripts should exit (after the necessary cleanings) when the "Cancel" value is returned.
If the script does not exit (beside the cleanings) when the "Cancel" value is returned, but calls another interactive method such as SelectElement2 , and, during execution, the user select an external command (which triggers the return of the "Cancel" value), then, the execution of the other interactive method will display an error message. |