Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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. lasselauch
    • Profile
    • Following 2
    • Followers 2
    • Topics 25
    • Posts 101
    • Best 14
    • Controversial 0
    • Groups 0

    lasselauch

    @lasselauch

    20
    Reputation
    129
    Profile views
    101
    Posts
    2
    Followers
    2
    Following
    Joined Last Online
    Website www.lasselauch.com Location Hamburg, Germany Age 39

    lasselauch Unfollow Follow

    Best posts made by lasselauch

    • RE: Access Bake Objects (Timeline) or Bake Animation to Curves

      Hi @bentraje,

      The thread about baking curves is still the right way to go if you want to be exact and want to bake other properties than PSR.

      However, if you're just interested in baking only your PSR, you can use doc.Record(), this works on all selected Objects since R19. You can take a look at the following example for baking Cubes with a Vibrate-Tag for example...:

      import c4d
      
      #https://developers.maxon.net/docs/py/2023_2/modules/c4d.documents/BaseDocument/index.html?highlight=executepasses#BaseDocument.ExecutePasses
      def SetCurrentTime(currentTime, doc):
          doc.SetTime(currentTime)
          doc.ExecutePasses(None, True, True, False, 0)    
      
      def main():
          minTime = doc[c4d.DOCUMENT_MINTIME]
          maxTime = doc[c4d.DOCUMENT_MAXTIME]
          fps = doc.GetFps()
          
          if minTime != maxTime:
              currentTime = minTime
              while (currentTime <= maxTime): 
                  SetCurrentTime(currentTime, doc)
                  print "Baking: Frame: %s" %(currentTime.GetFrame(fps))
                  
                  #New since version R19.
                  #Records the active objects in the document.
                  doc.Record()
                  
                  currentTime += c4d.BaseTime(1, fps)
      
      if __name__=='__main__':
          main()
      

      Oh, and accessing the "Bake Objects..." Dialog via Python is not possible!

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Rename object by filename

      You just need to add a python tag to your object and paste the following code.

      Simple as that:

      import c4d
      
      def main():
          if not doc:
              return
          doc_name = doc.GetDocumentName()
      
          null = op.GetMain()
          if not null:
              return
      
          null.SetName(doc_name)
      

      Download here: null-docname.c4d

      Hope it helps.

      Cheers,
      Lasse

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Python Source Protector: Can it be called via CLI?

      @kbar said in Python Source Protector: Can it be called via CLI?:

      I am going to bump this also.This function should be able to be called by command line. I would like to do this via my build system. By calling the cinema4d.exe, or c4dpy, with the python plugin path.

      PPLLEEEAASSSEEEE!

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Different behaviour with Resource File? R20/R21

      Wow, after some investigating I noticed that apperently BitmapButtonCustomGui.SetImage changed in R21.

      https://developers.maxon.net/docs/py/2023_2/modules/c4d.gui/BaseCustomGui/BitmapButtonCustomGui/index.html?highlight=setimage#BitmapButtonCustomGui.SetImage

          def fillResetButtons(self, buttonid):
              button = self.FindCustomGui(buttonid, c4d.CUSTOMGUI_BITMAPBUTTON)
              icon = c4d.bitmaps.InitResourceBitmap(c4d.RESOURCEIMAGE_CLEARSELECTION)
              button.SetImage(icon, copybmp=True)
      

      I just had to set the copybmp to True which was False and seemed to worked fine in all other versions.

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Move Tag Position in the Stack?

      Hi @bentraje,

      I came across this problem some time ago.
      Have a look at: https://www.lasselauch.com/c4d-quicktip-shift-tags/

      2018-07-12_11-55-22.gif

      import c4d
       
      def main():
          doc.StartUndo()
          sel = doc.GetActiveTags()
       
          for tag in sel:
              obj = tag.GetMain()
              taglist = obj.GetTags()
       
              for i, t in enumerate(taglist):
                  if t in sel:
                      index = i+1
                      if index == len(taglist):
                          return
                      #print """Tag: %s || Index: %s""" % (t.GetName(), i)
                      doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
                      obj.InsertTag(t, taglist[index])
       
          doc.EndUndo()
          c4d.EventAdd()
       
      if __name__=='__main__':
          main()
      

      This was essentially my approach, it’s not bulletproof but it works if you want to send multiple tags from one index to the next.

      Cheers,
      Lasse

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Make Button Invisible And Still Occupies Space?

      Quick way could be:

      Setting GeDialog.Enable to False and depending on your Button changing the background color to transparent..?!

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Best plugin type for background (thread) processing?

      Yeah, I'm looking into this as well...

      Ideally I want to run different function with a decorator: @execute_on_own_thread which would be very convenient.

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Logging in Cinema 4D

      Hi @blastframe,

      I'm using it currently more or less like this:

      The StreamHandler will print the result to the Python-Console and the FileHandler will write to disk. However, I'm also keen to know how to create my own LoggerInterface via Python. A simple example on this would be really appreciated.

      import c4d
      import os
      import logging
      
      def get_logger():
          plugin_name = "YourAwesomePlugin"
      
          #Logger for printing to Python-Console
          formatter1 = logging.Formatter('YourAwesomePlugin: [%(asctime)s] : %(module)s[%(lineno)s] : [%(levelname)s] "%(message)s"')
          handler = logging.StreamHandler()
          handler.setFormatter(formatter1)
          logger = logging.Logger(plugin_name)
          logger.addHandler(handler)
      
          #Logger for *.log file
          formatter2 = logging.Formatter('[%(asctime)s] : %(module)s[%(lineno)s] : [%(levelname)s] "%(message)s"')
          logpath = os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP), "MyLog.log")
          filehandler = logging.FileHandler(logpath)
          filehandler.setFormatter(formatter2)
          logger.addHandler(filehandler)
      
          return logger
      
      def main():
          logger = get_logger()
          
          logger.debug('This is a debug message')
          logger.info('This is an info message')
          logger.warning('This is a warning message')
          logger.error('This is an error message')
          logger.critical('This is a critical message')
      
      if __name__=='__main__':
          main()
      

      Cheers,
      Lasse

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Python Source Protector: Can it be called via CLI?

      Just wanted to bump this old thread.

      Any updates on this? Would love to see this in conjunction with c4dpy!

      Thanks & Cheers,
      Lasse

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • Plugin not loaded in R23 on macOS

      Hello everyone,

      I'm currently having some issues with one of my plugins for R23.

      Sadly I can't reproduce the issue, but I have two customers that report the plugin can't be loaded within R23 and they are both on macOS.

      I've also provided them with a DEBUG version, but no luck. My guess is the main module will not be loaded at all...
      There's nothing useful written to the console at all.

      This is the plugin they are trying to load (you can use the TRY button to download):
      https://aescripts.com/aec4d/

      They also reported that this happens with other plugins as well... I know that @mikeudin Tools4D also has the same problem. @mikeudin if you want to chime in and report your findings... I'm pretty much lost here... haha.

      Cheers,
      Lasse

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch

    Latest posts made by lasselauch

    • RE: Plugin module import freezes on startup

      Hi Ferdinand,
      I was essentially just forwarding this message from the developer of the licence framework. Sorry for not being clearer in the first place.
      I showed him your answer, and here is his response. Please let me know if I can be of any further assistance.

      Hi Ferdinand! I totally understand you so I'll write my findings in this mail instead. I'm not after help with my code, I just want to report the bug I found.

      The pyz file is part of python and allows you to package modules in a zip file for easier distribution, it has nothing to do with obfuscation in our case, it's just easier for the end user to copy one file instead of multiple folders and files.

      My finding with the 10mb file freeze comes from my trial and error. If I compile our licensing framework to work with Python 3.7-3.9 the resulting size is below 10mb, same if I compile for 3.9-3.11, same for 3.10-3.13 or what ever combo I do that ends up in less than 10mb pyz file the C4D plugin will read it but if I compile any combo where the pyz file ends up being more than 10mb the freeze happens.
      Let's say I compile for C4D 2026 it will work if I compile for 3.9-3.11 and it will work for 3.11-3.13 but it won't work for 3.9-3.13, exactly after 10mb. That ends me up thinking something is going on on C4D side.

      Lasselauch sadly seemt o have packaged the project a bit weird, thus Demo_Script.py is pointing wrongly. With "it doesn't happen when running a script" I mean when you run a script from Extensions -> User Scripts.
      Here is another zip with all different file combos for you to try out with yourself: https://www.swisstransfer.com/d/1f1d457f-89fe-4fef-80fd-2185c0ebe34c
      As you can see, using 3.9-3.13 freezes C4D but 3.9-3.11 and 3.11-3.13 does not. The internal code is exactly the same except that they package different PyArmor frameworks. I have double-checked the code and there is no execution-difference between the different pyz files.

      And the whole thing about obfuscation, honestly I'm just a dev that aescripts hired to add their licensing system to python and they want to protect the code so in that area I'm just doing what I'm told.

      //Jacob Danell

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • Plugin module import freezes on startup

      Hi Maxon/Cinema4D devs!

      I'm currently working with aescripts on developing their licensing system for python and for C4D. The license script is packaged in a pyz file for easy of distribution and the plugin script simply imports the pyz file to get access to the licensing system.

      One problem we're facing is that for C4D plugins C4D gets stuck on startup when showing Initializing Plugins 100%. After a lot of trial and error I found out that this happens ONLY when the pyz file is bigger than ~10mb.

      This doesn't happen if you run a script that imports the pyz. Only for plugins that gets loaded on startup.

      Here's a link to a demo repo for you to try it out and hopefully can figure out what's causing this:

      https://www.dropbox.com/scl/fo/87yyir1y6g6qrbi4mv6yr/AEwz6XxVyFuecXqlwVWxsus?rlkey=4yt2c6abiw1hdys5hgujjsre3&st=ymbhaxr5&dl=0

      Any ideas on why that is and how to best prevent the freeze are welcome!

      Thanks & Cheers,
      Lasse

      posted in Cinema 4D SDK python macos windows 2026 2025
      lasselauchL
      lasselauch
    • RE: Importing pythonapi from ctypes freezes C4D

      Hi Ferdinand, thanks for the reply and I totally understand the out of scope of support part!
      Thanks!


      Regarding the freeze, my system specs are:
      15", Apple M2 2023
      macOS 13.5.2 (22G91)
      C4D 2024.4.0
      Just trying to import ctypes freezes C4D instantly.


      Regarding the SpecialEventAdd() case:
      I essentially want to act after a threaded operation is finished. So the last line of my threaded function calls:
      c4d.SpecialEventAdd(ids.PLUGIN_ID_EXPORT)

      To distinguish between different types of export I thought I could use the p1 (x) e.g.: c4d.SpecialEventAdd(ids.PLUGIN_ID_EXPORT, x)

      However when using this inside my dialog, I'm not sure how to receive the different p1 or p2 integers inside the CoreMessage():

      def CoreMessage(self, id, msg):
          if id == ids.PLUGIN_ID_EXPORT:
              logger.info("PLUGIN_ID_EXPORT Message")
              if msg == x:
                  logger.info("Finished thread Message")
                  do_some_logic_here()
                  return True
          return False
      

      So what I'm asking is: I think different int are sufficient enough for my case, but I'm not sure how to receive those correctly within the CoreMessage or Message of a commanddata plugin.

      Thanks again,
      Lasse

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Importing pythonapi from ctypes freezes C4D

      Hi @m_adam,
      yes, that is correct. However, I experience a freeze everytime I do:
      from ctypes import pythonapi
      which I need either way.

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • Importing pythonapi from ctypes freezes C4D

      Hi there,
      I've just noticed something slightly odd.. While doing the following:

      from ctypes import pythonapi, c_void_p, py_object
      

      either in a script or plugin, Cinema4D freezes instantly.

      I came across this issue, because I wanted to implement a way to react to my SpecialEventAdd() messages. I stumbled upon this example:

      https://github.com/Rokoko/rokoko-studio-live-cinema4d/blob/ba4bd7a3c7eb814b13296a7ef564b0024efb0c4d/rokoko_utils.py#L37

      Is this still the way to go in 2024 to receive the SpecialEventAdd() p1 or p2 messages? And why is this instantly freezing C4D on my MacBook Air M2? πŸ™‚

      Cheers,
      Lasse

      posted in Cinema 4D SDK s24 macos python
      lasselauchL
      lasselauch
    • RE: How to find the CallCommand id for Redshift 'Convert and Replace with Nodes'

      AFK currently, but I think you can open the "Script Log..." from the Extensions Menu to check the ID's right!?

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Detect Menu/Manager while hovering...

      Thanks, for the clarification. @ferdinand

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • Detect Menu/Manager while hovering...

      With "Customize Commands..." we are able to "restrict" certain commands to certain "managers" or "menus". I'm wondering if it's possible to detect these managers within a cmd-data-plugin while the mouse is hovering over a certain area.

      Imagine a popup filled with different content based on the currently hovered manager i.e. object-manager, material-manager, take-manager...!

      customize-cmds.png

      Is there a way to detect the underlying context of the mouse via python..?

      Cheers,
      Lasse

      posted in Cinema 4D SDK python maxon api classic api
      lasselauchL
      lasselauch
    • RE: Arranging Objects by order of Object Manager

      I could make a recursive iteration to go through all of the document's objects but that would slow it down significantly...

      Yeah, but that's basically the way to go... Not sure if the following yields faster results:

      def get_next_element(op):
          if not op:
              return
          if op.GetDown():
              return op.GetDown()
          while (not op.GetNext()) and op.GetUp():
              op = op.GetUp()
          return op.GetNext()
      
      def main():
          obj = doc.GetFirstObject()
              
          while obj:
              # act on obj
              print(obj.GetName())
      
              obj = get_next_element(obj)
      

      Always wondered what approach would yield faster results...

      Feel free to do some testing, would love to hear your results. πŸ™‚

      posted in Cinema 4D SDK
      lasselauchL
      lasselauch
    • RE: Arranging Objects by order of Object Manager

      My guess is that iterating over with enumerate BaseDocument.GetObjects(self) would be efficient enough..?

      For example:

      all_objs = doc.GetObjects()
      for i, obj in enumerate(all_objs):
          # Distance can be whatever float or integer
          your_dist = i * 27
          pos = c4d.Vector(your_dist, 0, 0)Β 
          obj.SetAbsPos(pos)
      
      posted in Cinema 4D SDK
      lasselauchL
      lasselauch