Selecting Different components but in Different modes

  • Here's a number of "loaded" questions, as I have a goal in mind:
    Is it possible to do the following things via a script, when we're in Polygon Component Mode:

    1. when the script is activated, although we are still in Polygon mode, can we see Edge selection highlights when the cursor is hovering over some edge
    2. by clicking on that edge, could we set the Modeling Axis to align to the Center of the edge, and the modeling Z Axis to align to that edge?
    3. After the Click (on the edge) can we exit the script and use that Axis as the modeling Axis?
      Would those be possible?

  • Hi,

    yes, that should be technically possible, but a "script" (assuming you are referring to a Script Manager script) is a rather awkward place to do this, because Script Manager scripts are blocking. What you would have to do would be:

    1. Get the active BaseDraw via c4d.document.BaseDocument.GetActiveBaseDraw
    2. Get active object of the document.
    3. Initialise a c4d.utils.ViewportSelect with 1. and 2.
    4. Contentiously poll the mouse for its screen position via c4d.gui.GetInputState
    5. Exit the loop in 4. once the user has chosen a position (via a LMB for example).
    6. Feed the result of 5. into your ViewportSelect.GetNearestEdge after converting it into viewport coordinates (the conversion part could be tricky).
    7. Unpack the edge index into its points/vertices via c4d.utils.Neighbor.
    8. Construct your modelling axis matrix in whatever fashion you want it to be constructed.
    9. Write the axis to the object defined in 2. with BaseObject.SetModelingAxis.

    But due to Script Manager scripts being blocking:

    1. The user could not interact with Cinema while your script is running.
    2. Which also means no viewport navigation and redraws.
    3. Which in turn also means no highlighting etc.

    You might get better results out of an Interaction Tag, but I have never used them, so I cannot say much about them. But with a ToolData plugin this should be fairly easy to implement.


  • thank you so much for the detailed reply, and helping me save a lot of time by not doing it that way after all :-)
    I am trying to come up with a "shortcut" method for something I'm doing a tutorial on.
    All the functionality is already possible inside C4D, but to set it up you need to do a bunch of things and set a bunch of settings.
    The "manual" way is:

    1. Use Axis Center to align and Center the Object Axis to the Selected Edge.
    2. Set the Modeling Axis to "Object"
    3. Change Component mode to Polygons
    4. Select your Polygons
    5. Use Quantizing to Move or Rotate the said Polygons.
      All this could be possible via a script, instead of doing Matrix math :-)
      Thank you very much again for your input!

  • Hi,

    you lost me a bit in your workflow description, sorry. I am not really a Cinema user (anymore). But if I understand you correctly, you basically only want to to swizzle the modelling axis, which is pretty easy (the hard part of your request was all the interaction stuff). Below is an example on how you could do that.

    For your exact use case you would have to select an edge and then execute the script, the modelling axis of the selected object will then be swizzled. By executing the script multiple times you can cycle through the three possible configurations. The script is neither bound to a specific document mode nor number of selected elements.


    """Script Manager script.
    Swizzles the modeling axis of the selected polygon object when run. As a
    side effect the active tool is changed to the LiveSelection tool and set
    into "Free" mode. You will have to pretty up the script yourself if you
    want a more streamlined experience.
    import c4d
    def swizzle_modelling_axis(doc, op):
        """Swizzles the modeling axis of the passed object.
            doc (c4d.documents.BaseDocument): The active document.
            op (c4d.PolygonObject): A node in the active document.
            TypeError: When op is not a PolygonObject.
        def swizzle_matrix(m):
            """Swizzles a matrix, pushing in numerical and looping order of 
            its components (e.g. v1, v2, v3 becomes v3, v1, v2).
            return c4d.Matrix(, v1=m.v3, v2=m.v1, v3=m.v2)
        # Sort out non-polygon-objects.
        if not isinstance(op, c4d.PolygonObject):
            msg = ("swizzle_modelling_axis() requires a polygon object. "
                  "Received: {type}.")
            raise TypeError(msg.format(type=type(op)))
        # We need the axis to be free in order to be able to modify the axis.
        # For that we select the live selection tool and set it to free mode.
        plugin = c4d.plugins.FindPlugin(c4d.ID_MODELING_LIVESELECTION, 
        if plugin is None:
            plugin[c4d.MDATA_AXIS_MODE] = c4d.MDATA_AXIS_MODE_FREE
        # Get the modeling axis, swizzle it and write it back.
        axis = swizzle_matrix(op.GetModelingAxis(doc))
    def main():
        """Entry point.
        swizzle_modelling_axis(doc, op)
    if __name__=='__main__':

  • Thank you very much.
    The "swizzling" can be achieved with the Axis Center:
    using these settings.
    BUT the code you posted is very valuable for me to evolve my spaghetti coding... copy from here, and paste there :-)

    Thanks Again!

  • Full disclosure, I just realized that in "Axis Modification" Tool, when in Polygon mode, if you hover over an edge and click, it places the Axis there...
    I guess most of what I was trying to do is already there...

    "The path to wisdom, is paved with errors..."
    [just made that up...] Noseman

  • Hi,

    I was not aware that Cinema can do this and I thought that was what you were going for, given your statement '[..] and the modeling Z Axis to align to that edge [...]'. Also: Swizzling is just computer graphics slang for creating a new vector or matrix by shuffling the components of an existing vector or matrix.

    Since I do not really understand what you are trying to do, I cannot really point you into the right direction. I can only point out that the 'matrix maths' that comes up with transforms in Computer Graphics is not all that scary. I made post here and recently here on the topic. Feel free to come back if you have any problems.


  • hi,

    @noseman said in Selecting Different components but in Different modes:

    Full disclosure, I just realized that in "Axis Modification" Tool, when in Polygon mode, if you hover over an edge and click, it places the Axis there...
    I guess most of what I was trying to do is already there...

    yes, the only thing that doesn't answer your question it that you want the Z axis to be align with the edge.
    The "L" shortcut come really useful if you keep that shortcut pressed while clicking on the polygon/edge/point you want to move to your axis. Than when you release the shortcut, is disable that command.

    Don't be afraid of math, it's like cos, sin, tan, for some artist out there, it's really useful and not so complicated. (sometimes it's just function that you need to apply, not to understand like going from local to global and global to local)


Log in to reply