Navigation

    • Register
    • Login
        No matches found
    • Search
    1. Home
    2. Hexbob6
    H

    Hexbob6

    @Hexbob6

    0
    Reputation
    4
    Posts
    116
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    Hexbob6 Follow

    Best posts made by Hexbob6

    This user hasn't posted anything yet.

    Latest posts made by Hexbob6

    RE: Best practices for a plugin containing multiple commands

    Wow, thank you both for such detailed and informative replies!

    First of all, apologies @ferdinand for the tag issues, I was consulting the guidelines whilst typing my question but managed to miss the OS tag. Not sure if it matters too much for python dev, but I am on a Windows machine. I did however notice that the tag list doesn't seem to be updated to include R25 just yet (the version I'm currently working with), so it may need adding by the team. It doesn't look like I'm able to edit my original post past a certain time, but if you have the ability feel free to update 🙂

    Useful to know about the distinction between CommandData.ExecuteOptionID() and CommandData.ExecuteSubID(). The cogwheel icon present on some of the in-built commands was something that I'd noticed previously and been curious as to the implementation of - assumed it was just some complex code magic that added an additional button to the menu UI, ha!

    I guess that you're probably right in that I shouldn't try to run before I can walk, and if there's no limit to the amount of plugin IDs permitted (makes sense if there are hundreds of thousands of them going spare! 😉 ), then the keep-it-simple approach of registering multiple IDs would probably be best at this stage. For future reference though, if it is functionally the same as registering multiple IDs, do you know of any resources showing the implementation of CommandData.ExecuteSubID(), besides the docs; is this something that could be a candidate for an additional example in the SDK plugins repo?

    @Cairyn thanks for offering a more general insight into the situational decisions behind why something might be the 'best' choice (or not a choice at all!). I'm a designer first and foremost with an interest in coding, rather than the other way around, so considering the UX of a potential plugin and how it could fit into my own workflow is something I'm keen not to ignore 🙂

    To be a little more specific about how the plugin will function: essentially it will be a set of commands allowing the user to rapidly navigate around the viewport in a way that's a bit more custom than the default 'front, back, left, right, etc' views, as well as the ability to toggle between perspective and parallel views, ideally while keeping the same projection matrix (the hard bit!). My intention is to bind these commands to separate shortcuts so that they're a 'function at your fingertips' 🙂 Actually I do have some additional questions about the ability to set keyboard shortcuts via a plugin, instead of the command manager, and how Cinema then deals with shortcut conflicts, but I think that's one for another thread!

    Definitely going to refer back to these suggestions as I continue my learning journey.

    Thank you both again!

    posted in Cinema 4D SDK •
    Best practices for a plugin containing multiple commands

    Hi there, I'm working on creating my first python plugin for c4d and wrapping my head around the intricacies of the api (so forgive me if my general knowledge is a bit lacklustre, and terminology a bit off 🙂 ).

    The plugin itself allows a custom way of navigating the editor/user selected camera based on custom created Command Data commands. For example, the user presses the 'A' key (arbitrary) to move the camera to one position, the 'B' key (also arbitrary) to move it to another, etc.

    I'm curious as to what the recommended best practices are for creating these custom commands as I couldn't find many examples of Command Data plugins that create multiple commands in the sdk or forum examples. The immediately obvious way is to create and register multiple c4d.plugins.CommandData classes within the main .pyp file, as follows:

    import c4d
    
    PLUGIN_ID_1 = 1000000 #Test ID
    PLUGIN_ID_2 = 1000001 #Test ID
    
    #Create first command example
    class ExampleCameraCommandA(c4d.plugins.CommandData):
    
        def Execute (self, doc):
            #Execute camera code here...
            return True
    
    #Create second command example
    class ExampleCameraCommandB(c4d.plugins.CommandData):
    
        def Execute (self, doc):
            #Execute camera code here...
            return True
    
    if __name__ == "__main__":
    
        #Registers first custom command
        c4d.plugins.RegisterCommandPlugin (
            id = PLUGIN_ID_1,
            str = "Example Command A",
            info = 0, #PLUGINFLAG_COMMAND_HOTKEY(?)
            help = "Moves camera to point A.",
            dat = ExampleCameraCommandA(),
            icon = None)
    
        #Registers second custom command
        c4d.plugins.RegisterCommandPlugin (
            id = PLUGIN_ID_2,
            str = "Example Command B",
            info = 0, #PLUGINFLAG_COMMAND_HOTKEY(?)
            help = "Moves camera to point B.",
            dat = ExampleCameraCommandB(),
            icon = None)
    
    

    Really my main issue with this, is that it seems a bit overkill to generate multiple pluginIDs for essentially one plugin (albeit one that will contain many custom commands) - is this really how it should be done?

    The only other point of potential interest that I could see in the docs were the CommandData.GetSubContainer(), CommandData.ExecuteSubID() and CommandData.ExecuteOptionID() methods, but couldn't find many examples of their use and implementation to learn from...

    Any light shed on this topic would be very much appreciated, thanks in advance! 🙂

    posted in Cinema 4D SDK •
    RE: Adding Multiple Keyboard Shortcuts within a Python Script

    Hi @m_adam , thank you for the detailed reply! You're right there are a couple of parts to my question, so it might be helpful if I give a simplified example of what I'm trying to do.

    Essentially, I want to create a script that allows me to switch between different camera views (top, right, left, etc) by pressing the number keys. Whilst it would be easy to create a number of '.py' files using c4d.CallCommand() and then assign them all manually in the 'Customise Commands' manager, I was hoping I'd be able to create a script that runs for the duration that Cinema is open and reads the user's keypresses, returning c4d.CallCommand() when specified keys are pressed.

    Based on the first part of your answer I'd assume I'd need something along the lines of this... but I can't seem to get it to work.

    import c4d
    
    def main():
    
        bc = c4d.BaseContainer()
    
            # If the '7' key is pressed, enter 'Top' View
            if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_7, bc):
                if bc[c4d.BFM_INPUT_VALUE] == 1:
                    c4d.CallCommand(12083)  # Enters 'Top' View
    
            # If the '3' key is pressed, enter 'Right' View
            elif c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_3, bc):
                if bc[c4d.BFM_INPUT_VALUE] == 1:
                     c4d.CallCommand(12080)  # Enters 'Right' View
    
    if __name__=='__main__':
        main()
    

    Any ideas? Thanks again, Maxime! 🙂

    posted in Cinema 4D SDK •
    Adding Multiple Keyboard Shortcuts within a Python Script

    I am new to Cinema, having come from a different 3D software, and have been playing around with the Python API to create various scripts replicating certain functionality in my original software. These scripts have been very simple, typically calling/toggling commands, and I have been binding them to different keyboard shortcuts using the 'Customise Commands' Manager.

    My problem is that there is a script I'd like to create that would ideally map different commands to individual key-presses from within the script. Short of creating multiple smaller scripts and binding each of them to individual keys, I was wondering if it was possible to assign shortcuts from within the script itself? Obviously (I'd assume?), this singular script would have to run at startup.

    For example:

    if  a_key is pressed:
        # do_something
    
    elif a_different_key is pressed:
        # do_something_else
    

    Any detailed answers would be appreciated as I'm still fairly new to Python.
    Thanks!

    posted in Cinema 4D SDK •