Selection
This section describes how to use Interactive Selection in Creo Object TOOLKIT C++.
Interactive Selection
Methods Introduced:
When you call the method pfcBaseSession::Select, the Select dialog box appears in Creo Parametric user interface for selecting objects and returns a pfcSelections 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 pfcSelections sequence to the method. The returned pfcSelections sequence will contain the input sequence and any new objects.
The methods pfcSelectionOptions::Create and pfcSelectionOptions::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
pfcITEM_POINT
Datum axis
axis
pfcITEM_AXIS
Datum plane
datum
pfcITEM_SURFACE
Coordinate system datum
csys
pfcITEM_COORD_SYS
Feature
feature
pfcITEM_FEATURE
Edge (solid or datum surface)
edge
pfcITEM_EDGE
Edge (solid only)
sldedge
pfcITEM_EDGE
Edge (datum surface only)
qltedge
pfcITEM_EDGE
Datum curve
curve
pfcITEM_CURVE
Composite curve
comp_crv
pfcITEM_CURVE
Surface (solid or quilt)
surface
pfcITEM_SURFACE
Surface (solid)
sldface
pfcITEM_SURFACE
Surface (datum surface)
qltface
pfcITEM_SURFACE
Quilt
dtmqlt
pfcITEM_QUILT
Dimension
dimension
pfcITEM_DIMENSION
Reference dimension
ref_dim
pfcITEM_REF_DIMENSION
Integer parameter
ipar
pfcITEM_DIMENSION
Part
part
N/A
Part or subassembly
prt_or_asm
N/A
Assembly component model
component
N/A
Component or feature
membfeat
pfcITEM_FEATURE
Detail symbol
dtl_symbol
pfcITEM_DTL_SYM_INSTANCE
Note
any_note
pfcITEM_NOTE, pfcITEM_DTL_NOTE
Draft entity
draft_ent
pfcITEM_DTL_ENTITY
Table
dwg_table
pfcITEM_TABLE
Table cell
table_cell
pfcITEM_TABLE
Drawing view
dwg_view
N/A
Solid body
3d_body
pfcITEM_BODY
Datum Curve End
curve_end
pfcITEM_CRV_START or pfcITEM_CRV_END
When you specify the maximum number of selections, the argument to pfcSelectionOptions::SetMaxNumSels must be an Integer. The code will be as follows:
sel_options->setMaxNumSels (10);
The default value assigned when creating a SelectionOptions object is –1, which allows any number of selections by the user.
The method wfcWSelectionOptions::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 wfcWSelectionOptions::SetSelEnvOptions.
The method wfcWSelectionOptions::GetSelEnvOptions retrieves the selection attribute.
The method wfcSelectionEnvironmentOption::Create creates a data object of type wfcSelectionEnvironmentOption that contains information about the attributes for the interactive selection in Creo Parametric user interface. Use the method wfcSelectionEnvironmentOption::SetAttribute to set the selection attribute. The following attribute types are available:
•  wfcSELECT_DONE_REQUIRED—Specifies that user has to click OK in the Select dialog box to get the selected items.
•  wfcSELECT_BY_MENU_ALLOWED—Specifies that search tool is available in the method pfcBaseSession::Select when the attribute value is set to 1, which is the default value.
•  wfcSELECT_BY_BOX_ALLOWED—Specifies that user must draw a bounding box to get the items selected within the box.
•  wfcSELECT_ACTIVE_COMPONENT_IGNORE—Specifies that user can select items external to the activate component.
•  wfcSELECT_HIDE_SEL_DLG—Specifies that the Select dialog box must be hidden.
The method wfcSelectionEnvironmentOption::GetAttribute retrieves the selection attribute.
Use the method wfcSelectionEnvironmentOption::GetAttributeValue to get the integer value of the attributes set in the selection object.
The method wfcWSelection::Verify verifies if the content of the selection object is valid.
The method wfcWSelection::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 pfcSelection::GetSelModel or pfcSelection::GetSelItem.
•  For an assembly component use pfcSelection::GetPath.
•  For UV parameters of the selection point on a surface use pfcSelection::GetParams.
•  For the T parameter of the selection point on an edge or curve use pfcSelection::GetTParam.
•  For a three-dimensional point object that contains the selected point use pfcSelection::GetPoint.
•  For selection depth, in screen coordinates use pfcSelection::GetDepth.
•  For the selected drawing view, if the selection was from a drawing, use pfcSelection::GetSelView2D.
•  For the selected table cell, if the selection was from a table, use pfcSelection::GetSelTableCell.
•  For the selected table segment, if the selection was from a table, use pfcSelection::GetSelTableSegment.
•  For the selected drawing table cell, if the selection was a drawing table, use wfcWSelection::GetDrawingTable.
•  For the selected pipeline to get the pipeline feature, use wfcWSelection::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 pfcSelection::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::Repaint; it is not removed if you use pfcWindow::Refresh.
The method pfcSelection::UnHighlight removes the highlight.
The method pfcSelection::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 C++ 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 pfcCreateModelItemSelection creates a selection out of any model item object. It takes a pfcModelItem and optionally a pfcComponentPath object to identify which component in an assembly the Selection Object belongs to.
The method pfcCreateComponentSelection creates a selection out of any component in an assembly. It takes a pfcComponentPath object. For more information about pfcComponentPath objects, see the section Getting a Solid Object in Solid.
Use the method pfcCreateModelSelection to create a pfcSelection object, based on a pfcModel object.
Some Creo Object TOOLKIT C++ 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 pfcSelection::SetSelItem.
The selected component path using the method pfcSelection::SetPath.
The selected UV parameters using the method pfcSelection::SetParams.
The selected T parameter (for a curve or edge), using the method pfcSelection::SetTParam.
The selected XYZ point using the method pfcSelection::SetPoint.
The selected table cell using the method pfcSelection::SetSelTableCell.
The selected drawing view using the method pfcSelection::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 C++ allows access to the contents of the currently active selection buffer. The available functions 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::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 pfcSelectionBuffer::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 pfcSelectionBuffer::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 pfcSelectionBuffer::GetContents.
Use the method pfcSelectionBuffer::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 pfcSelectionBuffer::AddSelection to add an item to the current 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 wfcWSession::AddCollectionToSelectionBuffer to add collection to the current selection buffer.
The method wfcWSelection::GetCollection to get collection object that contains the items selected by the user.