c4d.BaseSelect

class 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.

Methods Signatures

BaseSelect.__init__(self)

Initializes a new base selection.

BaseSelect.GetCount(self)

Get the number of selected elements.

BaseSelect.GetSegments(self)

Get the number of segments that contain elements.

BaseSelect.IsSelected(self, num)

Get the selection state of an element.

BaseSelect.Select(self, num)

Selects an element.

BaseSelect.SelectAll(self, max[, min, ...])

Selects all elements within the given range.

BaseSelect.Deselect(self, num)

Deselects an element.

BaseSelect.DeselectAll(self)

Deselect all elements.

BaseSelect.Toggle(self, num)

Toggles the selection state of an element.

BaseSelect.ToggleAll(self, min, max)

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

BaseSelect.GetRange(self, seg, max)

Returns the selected elements contained in a segment.

BaseSelect.Merge(self, src)

Selects all elements that are selected in src.

BaseSelect.DeselectFrom(self, src)

Deselects all elements that are selected in src.

BaseSelect.Cross(self, src)

Intersects all elements in src.

BaseSelect.GetClone(self)

Make a duplicate of this selection object with its elements.

BaseSelect.GetDirty(self)

Returns the dirty counter of the selection.

BaseSelect.CopyTo(self, dest)

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

BaseSelect.SetAll(self, states)

Set all selected elements from a list.

BaseSelect.GetAll(self, max)

Returns all selected elements in a list.

BaseSelect.HostAlive(self)

Returns if the host object is still alive.

BaseSelect.Write(self, hf)

Saves the selection to a file.

BaseSelect.Read(self, hf)

Reads a selection from a file.

BaseSelect.FindSegment(self, num)

Returns which segment contains the element num.

BaseSelect.GetLastElement(self)

Returns the last element.

Methods Documentation

BaseSelect.__init__(self)

Initializes a new base selection.

Return type

c4d.BaseSelect

Returns

The new base selection.

BaseSelect.GetCount(self)

Get the number of selected elements.

Return type

int

Returns

The number of selected elements.

BaseSelect.GetSegments(self)
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(self, 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(f"Index {index} is selected")

This is faster than.

bs = op.GetPointS()
for index in range(op.GetPointCount()):
    if bs.IsSelected(index):
        print(f"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(self, 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(self, 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

def main():
    nbr = c4d.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(self, 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(self)

Deselect all elements.

Return type

bool

Returns

Success of deselecting all elements.

BaseSelect.Toggle(self, 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(self, 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(self, seg, max)
Returns the selected elements contained in a segment.

New in version R19.

Parameters
Return type

tuple(int,int)

Returns

The index of the first and last selected elements in the given segment.
If the segment has a length of one, the same if will be set for the first and last entry in the tuple.
None if the function failed.

BaseSelect.Merge(self, 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(self, 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(self, src)

Intersects all elements in src.

New in version R19.

Parameters

src (c4d.BaseSelect) – The source selection object.

Return type

bool

Returns

True if successful, otherwise False.

BaseSelect.GetClone(self)

Make a duplicate of this selection object with its elements.

Return type

c4d.BaseSelect

Returns

The clone object.

BaseSelect.GetDirty(self)
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(self, 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(self, 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[int]) – A list of elements to select.

Return type

bool

Returns

Success of selecting the elements.

BaseSelect.GetAll(self, max)

Returns all selected elements in a list.

Parameters

max (int) – The maximum number of elements to place into the array.

Return type

List[int]

Returns

The list

BaseSelect.HostAlive(self)

Returns if the host object is still alive.

Return type

int

Returns

  • 2 if the instance has no host object.

  • 1 if the host object is alive if set.

  • 0 if the object is not alive.

BaseSelect.Write(self, hf)

Saves the selection to a file.

Parameters

hf (c4d.storage.HyperFile) – The hyperfile to write to.

BaseSelect.Read(self, 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(self, num)

Returns which segment contains the element num.

New in version R19.

Parameters

num (int) – The index of the element.

Return type

int

Returns

The found segment index. -1 if no segment was found.

BaseSelect.GetLastElement(self)

Returns the last element.

Return type

int

Returns

Last element.