Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
edited by [ @ferdinand ]:
How can I set the selection state the underlying c4d.BaseSelectof a c4d.SelectionTag?
c4d.BaseSelect
c4d.SelectionTag
@LingZA said:
For an exmaple like op.MakeTag(c4d.Tedgeselection).
BaseSelect1.CopyTo(BaseSelect2) BaseSelect2 is of selection tag.
Hello @lingza,
Thank you for reaching out to us. Please read our forum guidelines.
I did restore and consolidate your postings for you in this case. I also provided a small example snippet which provides an answer, even though you have a solution of your own.
Cheers, Ferdinand
"""Provides an example for writing the selection state of a point selection tag. The script will get an existing or create a new point selection tag for the selected object and write a random point selection into that tag. """ from typing import Optional import c4d import random doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def main() -> None: """ """ # Ensure the active object can carry a point selection tag in a meaningful way; is a point # object that has at least one vertex. if not isinstance(op, c4d.PointObject) and op.GetPointCount() > 0: raise RuntimeError("Please select a polygon or spline object that does contain vertcies.") # Get the first existing point selection tag on the object or create a new one. tag = op.GetTag(c4d.Tpointselection) if not isinstance(tag, c4d.SelectionTag): tag = op.MakeTag(c4d.Tpointselection) # Get the number of vertices in the object, the selection from the tag, and build a generator # for a random set of vertex indices. pointCount = op.GetPointCount() selection = tag.GetBaseSelect() selectionCount = max(1, int(pointCount / 4)) indeciesToSelect = random.choices(range(pointCount), k=selectionCount) # Deselect all items in the selection first and then select all new indices which should be # selected. selection.DeselectAll() for index in indeciesToSelect: selection.Select(index) # Push an update event to Cinema 4D. The selection tag will now contain the new selection which has # been defined for #selection. c4d.EventAdd() if __name__ == '__main__': main()
Hello @LingZA,
without any further questions or other postings, we will consider this topic as solved and flag it as such by Friday, 17/06/2022.
Thank you for your understanding, Ferdinand