Navigation

    • Register
    • Login
    • Search
    1. Home
    2. pim
    P

    pim

    @pim

    10
    Reputation
    277
    Posts
    360
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

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

    Best posts made by pim

    RE: Fit image to a plane maintaining the ratio of the image?

    Together with the help from the c4dlounge.eu forum the issues is solved.
    The main issue was I did not read the manual good enough.

    "Note that Size symbolizes the axis size and not the expansion of the object itself. For planar projections, the true dimension is the two/fold of the axis length."

    posted in Cinema 4D SDK •
    RE: DrawLine2D on top of everything else

    I did some more testing and I think I got it now.
    In MouseInput() get and set your coordinates.
    Then call c4d.DrawViews(). This will call Draw(), where you can (and should) do the drawing like bd.DrawLine2D().

    class PlaceTool(c4d.plugins.ToolData):       	
    
        v1 = c4d.Vector(0,0,0)
        v2 = c4d.Vector(0,0,0)
        
        def Draw(self, doc, data, bd, bh, bt, flags):	
            bd.SetPen(c4d.Vector(256,256,256))
            bd.DrawLine2D(self.v1, self.v2)
            return True
            
        def MouseInput(self, doc, data, bd, win, msg):
            self.v1 = c4d.Vector(0,0,0)
            self.v2 = c4d.Vector(msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y], 0)
            c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK)  #Added 
            return True
            
            
    
    posted in Cinema 4D SDK •
    RE: Insert object in Treeview

    Thanks, great explanation!
    One small issue. Delete doesn't work because objParent' is not defined.

    Traceback (most recent call last):
    File "scriptmanager", line 251, in DeletePressed
    NameError: global name 'objParent' is not defined
    

    Here the code that, I think, solves the issue:

        def DeletePressed(self, root, userdata):
            "Called when a delete event is received."
            for tex in reversed(list(TextureObjectIterator(self.listOfTexture))):
                if tex.IsSelected:
                    objParent = tex.GetParent()               # Added
                    listToRemove = objParent.GetChildren() if objParent is not None else self.listOfTexture
                    listToRemove.remove(tex)
    
    posted in Cinema 4D SDK •
    RE: Best plugin type for background (thread) processing?

    @heilei said in Best plugin type for background (thread) processing?:

    Py-TextureBaker

    That is a very good working example.
    I rebuild my plugin using py-texturebaker and now it is working!

    After some studying, I think @PluginStudent is fully correct when referring to the global scope.

    @PluginStudent said in Best plugin type for background (thread) processing?:

    Please read my post above and the C4DThread Manual carefully.

    You can start the thread in a CommandData plugin. But this plugin must not own the thread instance. The thread instance should be stored in the global scope.

    In the MessageData plugin, you should react to a core message sent from the thread. Nothing else; no creation or waiting.

    I guess it is working because in the dialog the thread class is initiated.
    textureBakerThread = None
    and further in the code it is referenced with self.textureBakerThread.

    I was using

            thread = UserThread()
            thread.Start()
    

    Everybody thanks for all the help.

    posted in Cinema 4D SDK •
    RE: Reading script file into memory

    @PluginStudent said in Reading script file into memory:

    You have to define the APIS in the projectdefinition.txt of your plugin.

    Not in the projectdefinition.txt of the solution.

    Great, tht solved it. Thanks!

    posted in Cinema 4D SDK •
    RE: Reading script file into memory

    To summarise, there are 2 projectdefinition.txt files.

    1. on main / sdk level, Define which project (plugins, etc.)
      Example:
    Platform=Win64;OSX
    Type=Solution
     
    // defines the level of rigour of the source processor's style check
    stylecheck.level=0
    
    Solution=\
    	plugins/cinema4dsdk;\
    	plugins/maxonsdk.module;\
    	plugins/commandline;\
        plugins/CommandLineRendering
    
    1. on plugin level, // Configuration of a custom solution in the projectdefinition.txt file
      Example:
    // Supported platforms
    Platform=Win64;OSX
    
    // Type of project
    Type=DLL
    
    // this plugin depends on these frameworks:
    APIS=\
      cinema.framework; \
      misc.framework; \
      image.framework; \
      core.framework; \
      python.framework
    
    // Enable some advanced classic API support; not needed for hybrid plugins
    C4D=true
    
    // Plug-in code-style check level
    stylecheck.level=0
    
    // Custom ID
    ModuleId=net.maxonexample.commandlinerender
    
    posted in Cinema 4D SDK •
    RE: Passing a variable to the python script

    Yes, I am referring to that page.
    I saw that statement, but I assumed it was the main definition for the python plugin.

      // set __name__ = __main__
      scope.Add("__name__"_s, maxon::Data("__main__"_s)) iferr_return;
    

    If I understand you correctly, I can add different parameters with different values.
    For example:

      // set __param1__ = "c:/temp"
      scope.Add("param1"_s, maxon::Data("c:/temp"_s)) iferr_return;
      scope.Add("param2"_s, maxon::Data(220)) iferr_return;
    posted in Cinema 4D SDK •
    RE: First time compiling of plugin with R21

    Yes, I must read the manuals more throroughly (RTFMS).
    Excuses: it is so much and I just wanted to compiler R20 in R21.
    But you are correct.

    BUT, adding iferr to the code worked, AND also solved the other issue.
    Everything is working now!

    Thanks!

    posted in Cinema 4D SDK •

    Latest posts made by pim

    RE: Setting Noise as the Shader in a Displacer

    Ok, I understand it now better, thanks.

    posted in Cinema 4D SDK •
    RE: Setting Noise as the Shader in a Displacer

    @pim
    I solved it.
    You must insert the shader into the document and then insert it in the displacer

    from typing import Optional
    import c4d
    
    doc: c4d.documents.BaseDocument  # The active document
    op: Optional[c4d.BaseObject]  # The active object, None if unselected
    
    def main() -> None:
    
        displacer = c4d.BaseObject(c4d.Odisplacer)
        doc.InsertObject(displacer)
        
        shd = c4d.BaseList2D(c4d.Xnoise)
        doc.InsertShader(shd)
        displacer[c4d.ID_MG_SHADER_SHADER] = shd
        
        #displacer.InsertShader(shd)
        c4d.EventAdd()
        
    if __name__ == '__main__':
        main()
    
    posted in Cinema 4D SDK •
    Setting Noise as the Shader in a Displacer

    I am trying to set the Shader field in the Displacemtn object to Noise. However, the filed is not filled.

    Here the code.
    What am I doing wrong?

    from typing import Optional
    import c4d
    
    doc: c4d.documents.BaseDocument  # The active document
    op: Optional[c4d.BaseObject]  # The active object, None if unselected
    
    def main() -> None:
    
        displacer = c4d.BaseObject(c4d.Odisplacer)
        doc.InsertObject(displacer)
        
        shd = c4d.BaseList2D(c4d.Xnoise)
        #displacer[c4d.ID_MG_SHADER_SHADER] = shd
        
        displacer.InsertShader(shd)
        c4d.EventAdd()
        
    if __name__ == '__main__':
        main()
        
    
    posted in Cinema 4D SDK •
    RE: Best way to detect an object has been deleted?

    Thanks again for the great explanation.
    I guess I will go for a different workflow then.

    posted in Cinema 4D SDK •
    RE: Best way to detect an object has been deleted?

    I am not sure what you mean with a Baselink?

    A Cloner, imo, does not notice when a child is added or deleted.

    I guess there is (somewhere) a message that signals a deletion?

    posted in Cinema 4D SDK •
    Best way to detect an object has been deleted?

    I have a plugin that created a Cloner and insert planes as children of that cloner. After that I update the Cloner Count.
    However, when the user deletes a plane ( a child of that cloner), the Cloner count must be updated.

    What is the best way to detect an object has been deleted and I can update the Cloner count?

    posted in Cinema 4D SDK •
    RE: Insert my own command in main render Tab

    I really do appreciate all your effort and I will take your warning seriously and create my own menu Tab.
    Thanks again.

    Regards,
    Pim

    posted in Cinema 4D SDK •
    RE: Insert my own command in main render Tab

    @ferdinand
    I run the script, but it hangs cinema 4d.
    After some debugging, I could see that the insertion point was found and that it was inserted in items.
    I am not sure what statement hangs cinema 4d.

    I am using R2023.2.1 on a Windows 10 Pro 22H2.
    d55cbe3b-bde3-460d-8c7f-d82e92fde5fc-image.png

    posted in Cinema 4D SDK •
    RE: Insert my own command in main render Tab

    @ferdinand
    Ok, I can now insert my command in the render Tab, but it is positioned at the end.
    This is, I guess, because I use InsData() instead of InsDataAfter()

    Refering to my first code, this was my thinking:
    When using InsDataAfter(), looking at the documentation, I thought that last(any) indicates the position after where to insert the command. That is why I used sub.

    So, how to indicate where to insert the command?

    BaseContainer.InsDataAfter(self, id, n, last)¶
    Inserts an arbitrary data at the specified id after last.
    
    Warning This function does not check if the ID already exists in the container!
    Parameters
    id (int) – The ID to insert at.
    n (any) – The data to insert.
    last (any) – The data to insert after.
    

    Working code that inserts the command at the end.

    from typing import Optional
    import c4d
    
    pluginId = "1052844"        # official plugin ID
    
    def main() -> None:
        MainMenu = c4d.gui.GetMenuResource("M_EDITOR")
    
        for bcMenuId, bcMenu in MainMenu:
            #print (bcMenu[c4d.MENURESOURCE_SUBTITLE])
            if bcMenu[c4d.MENURESOURCE_SUBTITLE] == "IDS_EDITOR_RENDER":
                for sub in bcMenu:
                    if (sub[1] == "IDM_RENDERAUSSCHNITT"):
                        print ("*** Insert after this ***")
                    
                        # Add my plugin
                        #bcMenu.InsDataAfter(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_5159", sub)
                        bcMenu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_" + pluginId)    
                        c4d.gui.UpdateMenus()             
            
    if __name__ == '__main__':
        main()
    
    posted in Cinema 4D SDK •
    Insert my own command in main render Tab

    I found where to insert my own command (plugin),
    but I get following message.

    Traceback (most recent call last):
      File "scriptmanager", line 22, in <module>
      File "scriptmanager", line 18, in main
    TypeError: argument 3 must be PyCapsule, not tuple
    

    Also I am not sure I insert my plugin correctly.
    I do not fully understand how to indicate my plugin; PLUGIN_CMD_5159, name or id?

    Here the code

    from typing import Optional
    import c4d
    
    doc: c4d.documents.BaseDocument  # The active document
    op: Optional[c4d.BaseObject]  # The active object, None if unselected
    
    def main() -> None:
        MainMenu = c4d.gui.GetMenuResource("M_EDITOR")
    
        for bcMenuId, bcMenu in MainMenu:
            #print (bcMenu[c4d.MENURESOURCE_SUBTITLE])
            if bcMenu[c4d.MENURESOURCE_SUBTITLE] == "IDS_EDITOR_RENDER":
                for sub in bcMenu:
                    if (sub[1] == "IDM_RENDERAUSSCHNITT"):
                        print ("*** Insert after this ***")
                    
                        # Add my plugin
                        bcMenu.InsDataAfter(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_5159", sub)   
                        c4d.gui.UpdateMenus()             
            
    if __name__ == '__main__':
        main()
    
    posted in Cinema 4D SDK •