c4d.BaseSelect

This class is used to keep track of point and polygon selections. Each method will raise an exception when a host object is established, but not alive anymore.

class c4d. BaseSelect

Members

BaseSelect. __init__ ( )

Initializes a new base selection.

Return type: c4d.BaseSelect
Returns: The new base selection.
BaseSelect. GetCount ( )

Get the number of selected elements.

Return type: int
Returns: The number of selected elements.
BaseSelect. GetSegments ( )

Get the number of segments that contain elements. For example: the selections 0..4, 6..7, 9..12 would be three segments. This method would return 3 and GetCount() would return 11.

Return type: int
Returns: The number of selected segments.
BaseSelect. IsSelected ( num )

Get the selection state of an element.

To efficiently go through selections use the following code:

bs = op.GetPointS()
sel = bs.GetAll(op.GetPointCount())
for index, selected in enumerate(sel):
  if not selected: continue
  print "Index", index, "is selected"
							

This is faster than:

bs = op.GetPointS()
for index in xrange(op.GetPointCount()):
  if bs.IsSelected(index):
    print "Index", index, "is selected"
							
Parameters: num ( int ) – The element index to select.
Return type: bool
Returns: True if the element was already selected.
BaseSelect. Select ( num )

Selects an element.

Parameters: num ( int ) – The element index to select.
Return type: bool
Returns: True if the element was already selected.
BaseSelect. SelectAll ( max [ , min=0 , deselectAll=True ] )

Selects all elements within the given range.

Note

All previous selections are cleared.

Warning

min and max parameters are swapped compared to the C++ API version and min gets a default value of 0 .

Here is an example showing how to select all the edges of a PolygonObject :

import c4d
from c4d import utils
def main():
  nbr = utils.Neighbor()
  nbr.Init(op) # Initialize neighbor with a polygon object
  edges = c4d.BaseSelect()
  edges.SelectAll(nbr.GetEdgeCount()-1) # Select all edges in the range [0, nbr.GetEdgeCount()]
  op.SetSelectedEdges(nbr, edges, c4d.EDGESELECTIONTYPE_SELECTION) # Select edges from our edges selection
  c4d.EventAdd() # Update Cinema 4D
if __name__ == '__main__':
  main()
							
Parameters:
  • max ( int ) – The last element in the range to select.
  • min ( int ) – The first element in the range to select. Default to 0 .
  • deselectAll ( bool ) –

    New in version R17.048.

    Deselects all previously selected elements before creating the new selection (equivalent to SELECTION_NEW ).

Return type:

bool

Returns:

Success of selecting the elements.

BaseSelect. Deselect ( num )

Deselects an element.

Parameters: num ( int ) – The element index to deselect.
Return type: bool
Returns: True if the element was already deselected.
BaseSelect. DeselectAll ( )

Deselect all elements.

Return type: bool
Returns: Success of deselecting all elements.
BaseSelect. Toggle ( num )

Toggles the selection state of an element.

Parameters: num ( int ) – The index of the element to toggle.
Return type: bool
Returns: Success of changing the selection state of the element.
BaseSelect. ToggleAll ( min [ , max ] )

Toggle the selection state of all elements in the given range.

Parameters:
  • min ( int ) – The first element to toggle.
  • max ( int ) – The last element to toggle in the range.
Return type:

bool

Returns:

Success of changing the selection state.

BaseSelect. GetRange ( seg , max )

New in version R19.

Returns the selected elements contained in a segment.

Parameters:
  • seg ( int ) – The segment to get the elements for: 0 <= seg < GetSegments()
  • max ( int ) – The maximum value for the returned elements numbers. The method makes sure they are < max .
Return type:

tuple(int,int)

Returns:

The index of the first and last selected elements in the given segment. None if the function failed.

BaseSelect. Merge ( src )

Selects all elements that are selected in src .

Parameters: src ( c4d.BaseSelect ) – The source selection object.
Return type: bool
Returns: True if successful, otherwise False .
BaseSelect. DeselectFrom ( src )

Deselects all elements that are selected in src .

Note

For C++ developers: This function is redirected to Bool Deselect(const BaseSelect *src)

Parameters: src ( c4d.BaseSelect ) – The source selection object.
Return type: bool
Returns: True if successful, otherwise False .
BaseSelect. Cross ( src )

New in version R19.

Intersects all elements in src .

Parameters: src ( c4d.BaseSelect ) – The source selection object.
Return type: bool
Returns: True if successful, otherwise False .
BaseSelect. GetClone ( )

Make a duplicate of this selection object with its elements.

Return type: c4d.BaseSelect
Returns: The clone object.
BaseSelect. GetDirty ( )

Returns the dirty counter of the selection. This counter is increased every time a function is called that changes the selection.

Return type: int
Returns: Dirty counter.
BaseSelect. CopyTo ( dest )

Copy the selection elements in this selection object to another BaseSelect.

Parameters: dest ( c4d.BaseSelect ) – The destination selections object.
Return type: bool
Returns: Success of copying the selection elements.
BaseSelect. SetAll ( states )

Set all selected elements from a list. The elements in the list are interpreted as boolean: 0 means the element is unselected , and 1 means it is selected .

Note

The old selection will be completely overridden.

Parameters: states ( list of int ) – A list of elements to select.
Return type: bool
Returns: Success of selecting the elements.
BaseSelect. GetAll ( max )

Returns all selected elements in a list.

Parameters: max ( int ) – The maximum number of elements to place into the array.
Return type: list of int
Returns: The list
BaseSelect. HostAlive ( )

Returns if the host object is still alive.

Return type: int
Returns: 2 if the instance has no host object. Returns 1 if the host object is alive if set and returns 0 if the object is not alive.
BaseSelect. Write ( hf )

Saves the selection to a file.

Parameters: hf ( c4d.storage.HyperFile ) – The hyperfile to write to.
BaseSelect. Read ( hf )

Reads a selection from a file.

Parameters: hf ( c4d.storage.HyperFile ) – The hyperfile to read from.
Return type: bool
Returns: True if successful, otherwise False.
BaseSelect. FindSegment ( num )

New in version R19.

Returns which segment contains the element num .

Parameters: num ( int ) – The index of the element.
Return type: int
Returns: The found segment index. -1 if no segment was found.
BaseSelect. GetLastElement ( )

Returns the last element.

Return type: int
Returns: Last element.

Table Of Contents