Selection
This section describes how to use Interactive Selection in Creo Object TOOLKIT Java.
Interactive Selection
Methods Introduced:
When you call the method pfcSession.BaseSession.Select, the Select dialog box appears in Creo Parametric user interface for selecting objects and returns a pfcSelect.Selections sequence that contains the objects the user selected. Using the Options argument, you can control the type of object that can be selected and the maximum number of selections.
In addition, you can pass in a pfcSelect.Selections sequence to the method. The returned pfcSelect.Selections sequence will contain the input sequence and any new objects.
The method pfcSelect.pfcSelect.SelectionOptions_Create pfcSelect.SelectionOptions.SetOptionKeywords take a String argument made up of one or more of the identifiers listed in the table below, separated by commas.
For example, to allow the selection of features and axes, the arguments would be feature, axis.
Creo Parametric Database Item
String Identifier
ModelItemType
Datum point
point
ITEM_POINT
Datum axis
axis
ITEM_AXIS
Datum plane
datum
ITEM_SURFACE
Coordinate system datum
csys
ITEM_COORD_SYS
Feature
feature
ITEM_FEATURE
Edge (solid or datum surface)
edge
ITEM_EDGE
Edge (solid only)
sldedge
ITEM_EDGE
Edge (datum surface only)
qltedge
ITEM_EDGE
Datum curve
curve
ITEM_CURVE
Composite curve
comp_crv
ITEM_CURVE
Surface (solid or quilt)
surface
ITEM_SURFACE
Surface (solid)
sldface
ITEM_SURFACE
Surface (datum surface)
qltface
ITEM_SURFACE
Quilt
dtmqlt
ITEM_QUILT
Dimension
dimension
ITEM_DIMENSION
Reference dimension
ref_dim
ITEM_REF_DIMENSION
Integer parameter
ipar
ITEM_DIMENSION
Part
part
N/A
Part or subassembly
prt_or_asm
N/A
Assembly component model
component
N/A
Component or feature
membfeat
ITEM_FEATURE
Detail symbol
dtl_symbol
ITEM_DTL_SYM_INSTANCE
Note
any_note
ITEM_NOTE, ITEM_DTL_NOTE
Draft entity
draft_ent
ITEM_DTL_ENTITY
Table
dwg_table
ITEM_TABLE
Table cell
table_cell
ITEM_TABLE
Drawing view
dwg_view
N/A
Solid body
3d_body
ITEM_BODY
Datum Curve End
curve_end
ITEM_CRV_START or ITEM_CRV_END
When you specify the maximum number of selections, the argument to pfcSelect.SelectionOptions.SetMaxNumSels must be an Integer. The code will be as follows:
sel_options.setMaxNumSels (new Integer (10));
The default value assigned when creating a SelectionOptions object is –1, which allows any number of selections by the user.
The method wfcSelect.wfcSelect.WSelectionOptions_Create allows you to set options for selecting objects by specifying the selection attribute. The input arguments are:
•  OptionKeywords—Specifies the selection filter.
•  MaxNumSels—Specifies the maximum number of selections.
•  SelEnvOpts—Specifies the selection attribute set using the method wfcSelect.WSelectionOptions.SetSelEnvOptions.
The method wfcSelect.WSelectionOptions.GetSelEnvOptions retrieves the selection attribute.
The method wfcSelect.wfcSelect.SelectionEnvironmentOption_Create creates a data object of type SelectionEnvironmentOption that contains information about the attributes for the interactive selection in Creo Parametric user interface. Use the method wfcSelect.SelectionEnvironmentOption.SetAttribute to set the selection attribute. The following attribute types are available:
•  SELECT_DONE_REQUIRED—Specifies that user has to click OK in the Select dialog box to get the selected items.
•  SELECT_BY_MENU_ALLOWED—Specifies that search tool is available in the method pfcSession.BaseSession.Select when the attribute value is set to 1, which is the default value.
•  SELECT_BY_BOX_ALLOWED—Specifies that user must draw a bounding box to get the items selected within the box.
•  SELECT_ACTIVE_COMPONENT_IGNORE—Specifies that user can select items external to the activate component.
•  SELECT_HIDE_SEL_DLG—Specifies that the Select dialog box must be hidden.
The method wfcSelect.SelectionEnvironmentOption.GetAttribute retrieves the selection attribute.
Use the method wfcSelect.SelectionEnvironmentOption.SetAttributeValue to get the integer value of the attributes set in the selection object.
The method wfcSelect.WSelection.Verify verifies if the content of the selection object is valid.
The method wfcSelect.WSelection.GetWindow retrieves the window where the selection was made.
Accessing Selection Data
Methods Introduced:
These methods return objects and data that make up the selection object. Using the appropriate methods, you can access the following data:
•  For a selected model or model item use pfcSelect.Selection.GetSelModel or pfcSelect.Selection.GetSelItem.
•  For an assembly component use pfcSelect.Selection.GetPath.
•  For UV parameters of the selection point on a surface use pfcSelect.Selection.GetParams.
•  For the T parameter of the selection point on an edge or curve use pfcSelect.Selection.GetTParam.
•  For a three-dimensional point object that contains the selected point use pfcSelect.Selection.GetPoint.
•  For selection depth, in screen coordinates use pfcSelect.Selection.GetDepth.
•  For the selected drawing view, if the selection was from a drawing, use pfcSelect.Selection.GetSelView2D.
•  For the selected table cell, if the selection was from a table, use pfcSelect.Selection.GetSelTableCell.
•  For the selected table segment, if the selection was from a table, use pfcSelect.Selection.GetSelTableSegment.
•  For the selected drawing table cell, if the selection was a drawing table, use wfcSelect.WSelection.GetDrawingTable.
•  For the selected pipeline to get the pipeline feature, use wfcSelect.WSelection.GetPipelineFeature.
Controlling Selection Display
Methods Introduced:
These methods cause a specific selection to be highlighted or dimmed on the screen using the color specified as an argument.
The method pfcSelect.Selection.Highlight highlights the selection in the current window. This highlight is the same as the one used by Creo application when selecting an item—it just repaints the wire-frame display in the new color. The highlight is removed if you use the Repaint command or pfcWindow.Window.Repaint; it is not removed if you use pfcWindow.Window.Refresh.
The method pfcSelect.Selection.UnHighlight removes the highlight.
The method pfcSelect.Selection.Display causes a selected object to be displayed on the screen, even if it is suppressed or hidden.
Note
This is a one-time action and the next repaint will erase this display.
Programmatic Selection
Creo Object TOOLKIT Java provides methods whereby you can make your own Selection objects, without prompting the user. These Selections are required as inputs to some methods and can also be used to highlight certain objects on the screen.
Methods Introduced:
The method pfcSelect.pfcSelect.CreateModelItemSelection creates a selection out of any model item object. It takes a pfcModelItem.ModelItem and optionally a pfcAssembly.ComponentPath object to identify which component in an assembly the Selection Object belongs to.
The method pfcSelect.pfcSelect.CreateComponentSelection creates a selection out of any component in an assembly. It takes a pfcAssembly.ComponentPath object. For more information about pfcAssembly.ComponentPath objects, see the section Getting a Solid Object in Solid.
Use the method pfcSelect.pfcSelect.CreateModelSelection to create a pfcSelect.Selection object, based on a pfcModel.Model object.
The method pfcSelect.pfcSelect.CreateSelectionFromString creates a new selection object, based on a Web.Link style selection string specified as the input.
Some Creo Object TOOLKIT Java methods require more information to be set in the selection object. The methods allow you to set the following:
The selected item using the method pfcSelect.Selection.SetSelItem.
The selected component path using the method pfcSelect.Selection.SetPath.
The selected UV parameters using the method pfcSelect.Selection.SetParams.
The selected T parameter (for a curve or edge), using the method pfcSelect.Selection.SetTParam.
The selected XYZ point using the method pfcSelect.Selection.SetPoint.
The selected table cell using the method pfcSelect.Selection.SetSelTableCell.
The selected drawing view using the method pfcSelect.Selection.SetSelView2D.
Selection Buffer
Introduction to Selection Buffers
Selection is the process of choosing items on which you want to perform an operation. In Creo application, before a feature tool is invoked, the user can select items to be used in a given tool's collectors. Collectors are like storage bins of the references of selected items. The location where preselected items are stored is called the selection buffer.
Depending on the situation, different selection buffers may be active at any one time. In Part and Assembly mode, Creo offers the default selection buffer, the Edit selection buffer, and other more specialized buffers. Other Creo modes offer different selection buffers.
In the default Part and Assembly buffer there are two levels at which selection is done:
•  First Level Selection
Provides access to higher-level objects such as features or components. You can make a second level selection only after you select the higher-level object.
•  Second Level Selection
Provides access to geometric objects such as edges and faces.
Note
First-level and second-level objects are usually incompatible in the selection buffer.
Creo Object TOOLKIT Java allows access to the contents of the currently active selection buffer. The available methods allow your application to:
•  Get the contents of the active selection buffer.
•  Remove the contents of the active selection buffer.
•  Add to the contents of the active selection buffer.
Reading the Contents of the Selection Buffer
Methods Introduced:
The method pfcSession.Session.GetCurrentSelectionBuffer returns the selection buffer object for the current active model in session. The selection buffer contains the items preselected by the user to be used by the selection tool and popup menus.
Use the method pfcSelect.SelectionBuffer.GetContents to access the contents of the current selection buffer. The method returns independent copies of the selections in the selection buffer (if the buffer is cleared, this array is still valid).
Removing the Items of the Selection Buffer
Methods Introduced:
Use the method pfcSelect.SelectionBuffer.RemoveSelection to remove a specific selection from the selection buffer. The input argument is the IndexToRemove specifies the index where the item was found in the call to the method pfcSelect.SelectionBuffer.GetContents.
Use the method pfcSelect.SelectionBuffer.Clear to clear the currently active selection buffer of all contents. After the buffer is cleared, all contents are lost.
Adding Items to the Selection Buffer
Method Introduced:
Use the method pfcSelect.SelectionBuffer.AddSelection to add an item to the currently active selection buffer.
Note
The selected item must refer to an item that is in the current model such as its owner, component path or drawing view.
This method may fail due to any of the following reasons:
•  There is no current selection buffer active.
•  The selection does not refer to the current model.
•  The item is not currently displayed and so cannot be added to the buffer.
•  The selection cannot be added to the buffer in combination with one or more objects that are already in the buffer. For example: geometry and features cannot be selected in the default buffer at the same time.
Use the method wfcSession.WSession.AddCollectionToSelectionBuffer to add collection to the current selection buffer.
The method wfcSelect.WSelection.GetCollection to get collection object that contains the items selected by the user.