Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. dskeith
    • Profile
    • Following 0
    • Followers 0
    • Topics 9
    • Posts 22
    • Best 3
    • Controversial 0
    • Groups 0

    dskeith

    @dskeith

    Freelance Plugin Developer

    3
    Reputation
    209
    Profile views
    22
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Website www.donovankeith.com Location Los Angeles, CA

    dskeith Unfollow Follow

    Best posts made by dskeith

    • RE: R20 Script State Function
      1. Only passing True, False and c4d.CMD_ENABLED|c4d.CMD_VALUE will effect the icon state correct? it can't be done outside of the state() function?

      Yes. You may be able to perform calculations elsewhere and store a state value in the document's container that you access in the state() method, but I don't believe you can change the state elsewhere.

      1. I noticed when I put a print function inside of the state() function it seemed to loop endlessly? if I use this code:

      Yes, it's "looping" every time the Cinema 4D interface updates/redraws.

      Background

      The state() function is seemingly run every time Cinema 4D's interface is redrawn. It's really there for determining whether a command that requires an object be selected is enabled or not. As it's run so frequently, any code you put in there could slow down all of C4D, so ensure that your state check is actually important, and if so, do your check as quickly as possible.

      Example

      For example, a script that prints the name of the selected object should only be enabled when an object is selected.

      """Name-en-US: Echo Name
      Description-en-US: Opens a message dialog with the name of the selected object.
      """
      
      import c4d
      from c4d import gui
      
      def state():
          """Gray out icon if no objects are selected, or more than one object is selected.
          """
      
          # `op` is a variable provided by C4D that represents the selected object.
          # I'm not certain, but I think this is faster than call doc.GetActiveObject()
          # but it will return `False` if more than one object is selected.
          if op is not None:
              return c4d.CMD_ENABLED
          
          else:
              return False
      
      def main():
          """Open a dialog with the selected object's name.
          """
          
          if op is None:
              return
      
          active_obj_name = op.GetName()
          gui.MessageDialog("You selected: " + active_obj_name)
      
      if __name__=='__main__':
          main()
      

      References

      • Python API Docs: c4d.plugins.CommandData.GetState
      • C++ API Docs: Command Data Class
      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • c4dpy.exe and VS Code on Windows?

      Hi,

      Has anyone had any luck getting R21's c4dpy.exe to work with the current release of VS Code? I've followed the installation instructions but I'm consistently prompted to "Select Python Interpreter", even though I've set "python.pythonPath": "C:/Program Files/Maxon Cinema 4D R21/c4dpy.exe" in the VS Code application and workspace settings.

      I've been able to get it running in PyCharm, but VS Code doesn't seem to recognize c4dpy.exe as a valid python interpreter.

      Any suggestions or insights would be greatly appreciated.
      Thanks,

      Donovan

      posted in Cinema 4D SDK python windows r21
      dskeithD
      dskeith
    • RE: Copying All Compatible Properties from One Object to Another?

      Realizing I never responded to this Thank you @m_magalhaes, @mikegold10, and @PluginStudent.

      I ended up manually making a list of the parameters I wanted to copy and iterating through all of them. Not ideal, but at least glad to know there wasn't an automated method I was missing.

      posted in Cinema 4D SDK
      dskeithD
      dskeith

    Latest posts made by dskeith

    • RE: Node Editor API - View Bounds, Node Positions, Node Sizes

      Not the answer I was hoping for, but helpful nonetheless! Thank you.

      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • RE: Node Editor API - Active Node Editor Graph?

      Gotcha. So, at least for now, we can't develop tools/commands for manipulating nodes in the "active" node editor. Thanks for the thorough response! The GetSceneNodesGraph method is really useful, might be worth adding it into the API as a convenience function. Same for a GetActiveMaterialNodeGraph() or something similar for materials.

      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • Node Editor API - View Bounds, Node Positions, Node Sizes

      I'm looking to create some node alignment scripts (Align Vertical, Align Horizontal), and to do that, I believe I'll need the following information:

      Get Methods

      • Current Node Editor + View Context (asked in a separate post)
      • Selected Nodes within the Currently Active Node Editor + Context
      • Node Position (Along with information on where the axis is relative to the node)
      • Node Width/Height (So that I can calculate bounds and add even gaps between nodes)
      • Node Editor Bounds (What's visible min/max)
      • Grid spacing + positioning
      • Nearest Grid Point (for snapping to grid if Snap to Grid is on/active)

      Set Methods

      • Node position (ideally w/ option to snap to the nearest grid point)
      • Node Editor Bounds / Zoom + Pos

      Question

      Which (if any) of the above methods currently exist?

      I'll edit this post if my own research turns up anything useful.

      Related

      • Node Editor API - Active Node Editor Graph? | PluginCafé
      posted in Cinema 4D SDK s26 python
      dskeithD
      dskeith
    • RE: Node Editor API - Active Node Editor Graph?

      Realizing there are even more considerations:

      1. Is there a concept of "sub-graphs"? For example, if the user has navigated inside of a group in the Node Editor, and they run "Select Node Parents" it will also select parents outside of the currently visible group. Whereas, they probably only want to select the parents visible within their current context.
      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • RE: Node Editor API - Active Node Editor Graph?

      Now that I'm realizing you can have multiple open Node Editors, some w/ locking, some without, I can imagine this being a similar challenge to the "Which timeline is active?" problem.

      How to Get the Selected Keyframes in Active Timeline/FCurve Manager | PluginCafé
      Get Active Timeline Request | PluginCafé

      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • RE: Node Editor API - Active Node Editor Graph?

      Here's the code working for materials. How would I expand it to also work with Scene Nodes and, ideally, to work with the currently active node editor?

      """Name-en-US: Select Node Children
      Description-en-US: Selects Child Nodes
      
      Copyright: MAXON Computer GmbH
      Author: Donovan Keith
      
      Adapted from a script by
      Copyright: MAXON Computer GmbH
      Author: Manuel Magalhaes
      
      Version: 0.1.0
      
      ## Changelog
      
      - v0.1.0: Initial Release
      
      """
      import c4d
      import maxon
      
      
      def main():
          c4d.GetActiveNodeSpaceId()
      
          # Get the Active Material
          # ISSUE: It's possible to have the node editor editing a material even if its not active/selected (Asset Mode, Lock mode, etc)
          mat = doc.GetActiveMaterial()
          if mat is None:
              raise ValueError("There is no selected BaseMaterial")
      
          # Retrieve the reference of the material as a node Material.
          nodeMaterial = mat.GetNodeMaterialReference()
          if nodeMaterial is None:
              raise ValueError("Can't retrieve nodeMaterial reference")
      
          # Retrieve the current node space Id
          nodespaceId = c4d.GetActiveNodeSpaceId()
      
          # Retrieve the graph corresponding to that nodeSpace.
          graph = nodeMaterial.GetGraph(nodespaceId)
          if graph is None:
              raise ValueError("Can't retrieve the graph of this nimbus ref")
      
          with graph.BeginTransaction() as transaction:
              selected_nodes = []
              maxon.GraphModelHelper.GetSelectedNodes(graph, maxon.NODE_KIND.NODE, selected_nodes)
      
              predecessors = []
              for node in selected_nodes:
                  maxon.GraphModelHelper.GetAllPredecessors(node, maxon.NODE_KIND.NODE, predecessors)
      
              for predecessor in predecessors:
                  maxon.GraphModelHelper.SelectNode(predecessor)
      
              transaction.Commit()
      
          # Pushes an update event to Cinema 4D
          c4d.EventAdd()
      
      
      if __name__ == "__main__":
          main()
      
      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • Node Editor API - Active Node Editor Graph?

      Hi,

      Is there a way to access the current/active graph in the Node Editor via the Python API? I'm trying to write some node layout helpers (Align Horizontal/Vertical) but I'm not finding the information I'm looking for.

      1. How can I get the current graph that's visible/active in the Node editor?
        • c4d.GetActiveNodeSpaceId() doesn't change when I switch from material nodes to scene nodes.
        • Even for a materials-only mode, the selection state of a material doesn't indicate which graph is currently selected.
        • How do we determine which of the open node editors is active (like in Edit Asset mode)?
      posted in Cinema 4D SDK python s26
      dskeithD
      dskeith
    • RE: Polygon Islands Convenience Method?

      Wow! What an incredible set of answers. You've each addressed a different thing I intended to do with these polygon groups once I had access to them.

      Thank you @ferdinand @m_adam and @pyr!

      posted in Cinema 4D SDK
      dskeithD
      dskeith
    • Polygon Islands Convenience Method?

      Hi!

      Is there an available convenience method for getting all polygon islands in a polygon object? It seems like one exists internally for things like the Texture > View > Multi-Color Islands option.

      2c161963-9b33-4c89-8763-d017ddae1ece-image.png

      Specifically, I'm looking for polygon islands/shells, but an additional command/option for UV Islands would be great too.

      If one doesn't exist, I'd like to request that one be added to the Python SDK.

      Thank you,

      Donovan

      posted in Cinema 4D SDK r23 python
      dskeithD
      dskeith
    • Left-Hand Local Coordinates to Right-Hand Local Coordinates?

      Hi,

      I'm trying to export object an animated hierarchy of objects from Cinema 4D's left coordinates (z+ = forward) with HPB rotations to Three.js's right-hand coordinates (z+ = backward) with XYZ rotations.

      Unfortunately, I'm a bit beyond my depth with the matrix math and conversions involved. I'd like to take my C4D local coords write them out as local coords in this other system.

      Any tips on how to approach this?
      Thanks

      Donovan

      PS: Looks like we need an S22 tag in the tags option.

      posted in General Talk python
      dskeithD
      dskeith