This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.utils.ViewportSelect - a viewport helper class

This class is used to extract information from a viewport about which objects and object elements are visible at which pixels. It is used internally for stuff like highlighting and modeling.

class c4d.utils.ViewportSelect

Methods

ViewportSelect.__init__()
Return type:ViewportSelect
Returns:A new viewport select object.
ViewportSelect.Init(w, h, bd, ops, mode, onlyvisible, flags)

Initializes the viewport information for multiple objects. This has to be done before the pixel information can be retrieved. You have to retrieve the width and height of the viewport manually:

frame = bd.GetFrame()
left = frame["left"]
right = frame["right"]
width = frame["width"]
height = frame["height"]

width = right - left + 1
height = bottom - top +1
Parameters:
  • w (int) – Width of the viewport in pixels.
  • h (int) – Height of the viewport in pixels.
  • bd (BaseDraw) – The viewport base draw.
  • ops (list of BaseObject c4d.BaseObject>) – A list with objects to get the information for.
  • mode (int) –

    Editor mode:

    Mpoints Point edit mode.
    Medges Edge edit mode.
    Mpolygons Polygon edit mode.
    Mpolyedgepoint Combined poly/edge/point mode. Must only be used in ViewportSelect.
  • onlyvisible (bool) – If this is True only visible elements are included.
  • flags (int) –

    Flags:

    VIEWPORT_USE_HN Use HyperNURBS.
    VIEWPORT_USE_DEFORMERS Use deformers.
    VIEWPORT_IGNORE_HIDDEN_SEL Ignore hidden selection.
ViewportSelect.GetPixelInfoPoint(x, y)

Retrieves point information at the pixel position (x, y):

infopoint = viewportselect.GetPixelInfoPoint(x, y)
if not infopoint:
    return

i = infopoint["i"] #int
z = infopoint["z"] #float
op = infopoint["op"] #c4dBaseObject
Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to ViewportSelect.Init.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where y is the width given to ViewportSelect.Init.
Return type:

dict

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetPixelInfoPolygon(x, y)

Retrieves polygon information at the pixel position (x, y):

infopoint = viewportselect.GetPixelInfoPoint(x, y)
if not infopoint:
    return

i = infopoint["i"] #int
z = infopoint["z"] #float
op = infopoint["op"] #c4dBaseObject
Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to ViewportSelect.Init.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where y is the width given to ViewportSelect.Init.
Return type:

dict

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.GetPixelInfoEdge(x, y)

Retrieves edge information at the pixel positio (x, y):

infopoint = viewportselect.GetPixelInfoPoint(x, y)
if not infopoint:
    return

i = infopoint["i"] #int
z = infopoint["z"] #float
op = infopoint["op"] #c4dBaseObject
Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to ViewportSelect.Init.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where y is the width given to ViewportSelect.Init.
Return type:

dict

Returns:

The retrieved pixel information or None if no information could be retrieved.

ViewportSelect.ShowHotspot(bw, x, y)

Draws an XOR circle to the view bw at the pixel position (x, y). The radius is set by ViewportSelect.SetBrushRadius.

Parameters:
  • bw (EditorWindow) – The editor window to draw to.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to ViewportSelect.Init.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where w is the width given to ViewportSelect.Init.
ViewportSelect.SetBrushRadius(r)

Sets the radius for ViewportSelect.Init.

Parameter:r (float) – The new radius in pixels.
ViewportSelect.ClearPixelInfo(x, y, mask)

Deletes the pixel information at (x ,*y*) according to mask.

This is used for example in the live edge selection with “tolerant” deactivated to find out how many pixels of a certain edge was selected. If an edge is determined under the cursor, the pixel counter is decremented and the edge information is deleted afterwards.

Parameters:
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to ViewportSelect.Init.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where w is the width given to ViewportSelect.Init.
  • mask (int) –

    A bitfield of what to clear:

    VIEWPORT_CLEAR_POINT Clear points.
    VIEWPORT_CLEAR_POLYGON Clear polygons.
    VIEWPORT_CLEAR_EDGE Clear edges.
ViewportSelect.PickObject(bd, doc, x, y, rad, allowOpenGL)

Deletes the pixel information at (x ,*y*) according to mask.

This is used for example in the live edge selection with “tolerant” deactivated to find out how many pixels of a certain edge was selected. If an edge is determined under the cursor, the pixel counter is decremented and the edge information is deleted afterwards.

Parameters:
  • bd (BaseDraw) – The viewport base draw.
  • doc (BaseDocument) – Document.
  • x (int) – An X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to ViewportSelect.Init.
  • y (int) – An Y coordinate within the viewport. Must be 0 <= y < h, where w is the width given to ViewportSelect.Init.
  • rad (int) – A radius for the search in pixels.
  • allowOpenGL (bool) – Allow OpenGL.
Return type:

list

Returns:

Object list to fill or None on failure.

Table Of Contents

This Page