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. FlavioDiniz
    3. Posts
    • Profile
    • Following 1
    • Followers 1
    • Topics 8
    • Posts 24
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by FlavioDiniz

    • RE: DrawHudText interferes with Polygon Pen Tool etc

      Thanks @i_mazlov !
      So, I figured what the problem was, it was kind of my fault due to my not so good scripting skills, lol

      I'll explain the issues I was having anyway:

      Issue 1

      File save state was constantly unsaved. If you click to save, then click to close the document, it would ask if you want to save the document. CTRL+S didn't do any difference.

      Issue 2

      When the DrawHudText was visible on screen, it was preventing the usage of some tools:

      1. Polygon Pen Tool,
      2. Loop / Path Cut,
        pen_tool.mp4

      I'm attaching the C4D file and the code on the python tag below:
      Using C4D 2025.2.1
      DrawHudText_Issue.c4d

      # Autosave Info By Flavio Diniz
      import c4d
      
      def main() -> None:
          pass
      
      def draw(bd: c4d.BaseDraw) -> bool:
      
          savedColor = bd[c4d.BASEDRAW_HUD_TEXTCOLOR]
          savedBG = bd[c4d.BASEDRAW_HUD_BACKCOLOR]
          savedOpacity = bd[c4d.BASEDRAW_HUD_BACKOPACITY]
      
          if bd.GetDrawPass() != c4d.DRAWPASS_OBJECT or bd.GetDrawParam(c4d.BASEDRAW_IS_PICK_OBJECT):
              return True
      
          bd = doc.GetActiveBaseDraw()
      
          if c4d.GetWorldContainerInstance()[c4d.WPREF_AUTOSAVE_ENABLE] == 1:
              autosave = "Enabled"
      
              bd[c4d.BASEDRAW_HUD_TEXTCOLOR]= c4d.Vector(0.3, 0.8, 0.3)
              bd[c4d.BASEDRAW_HUD_BACKCOLOR]= c4d.Vector(0,0.7,0)
              bd[c4d.BASEDRAW_HUD_BACKOPACITY] = 0.2
      
              bd.DrawHUDText(0, 3, "Autosave: {}".format(autosave))
      
              bd[c4d.BASEDRAW_HUD_TEXTCOLOR]= savedColor
              bd[c4d.BASEDRAW_HUD_BACKCOLOR]= savedBG
              bd[c4d.BASEDRAW_HUD_BACKOPACITY] = savedOpacity
      
      
          elif c4d.GetWorldContainerInstance()[c4d.WPREF_AUTOSAVE_ENABLE] == 0:
              autosave = "Disabled"
      
              bd[c4d.BASEDRAW_HUD_TEXTCOLOR]= c4d.Vector(0.8, 0.5, 0.5)
              bd[c4d.BASEDRAW_HUD_BACKCOLOR]= c4d.Vector(0.9,0,0)
              bd[c4d.BASEDRAW_HUD_BACKOPACITY] = 0.1
      
              bd.DrawHUDText(0, 3, "Autosave: {}".format(autosave))
      
              bd[c4d.BASEDRAW_HUD_TEXTCOLOR]= savedColor
              bd[c4d.BASEDRAW_HUD_BACKCOLOR]= savedBG
              bd[c4d.BASEDRAW_HUD_BACKOPACITY] = savedOpacity
      
          return c4d.DRAWRESULT_OK
      

      .

      So, in short, the problem is my attempt to change the background and text color of the DrawHudText !
      998f9a83-a908-4303-a686-074fd1b55bc3-image.png

      I know it's not fully supported in Python, but I found a piece of code that allowed me to store the original HUD color, then change the color, draw the HUD, then revert back the color to the original... yes, I imagine this is 200% not recommended to do hahaha

      As soon as I remove these functions to change color from the code, both issues listed above are gone !

      This is the code without the coloring part:

      # Autosave Info By Flavio Diniz
      import c4d
      
      def main() -> None:
          pass
      
      def draw(bd: c4d.BaseDraw) -> bool:
          if bd.GetDrawPass() != c4d.DRAWPASS_OBJECT or bd.GetDrawParam(c4d.BASEDRAW_IS_PICK_OBJECT):
              return True
      
          bd = doc.GetActiveBaseDraw()
      
          if c4d.GetWorldContainerInstance()[c4d.WPREF_AUTOSAVE_ENABLE] == 1:
              autosave = "Enabled"
              bd.DrawHUDText(0, 3, "Autosave: {}".format(autosave))
      
          elif c4d.GetWorldContainerInstance()[c4d.WPREF_AUTOSAVE_ENABLE] == 0:
              autosave = "Disabled"
              bd.DrawHUDText(0, 3, "Autosave: {}".format(autosave))
      
          return c4d.DRAWRESULT_OK
      

      I can live without the coloring part, if you know a better way to do it or a fix, good! if not, that's fine! 🙂

      Cheers,
      Flavio Diniz

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • DrawHudText interferes with Polygon Pen Tool etc

      It's me again @i_mazlov, sorry ☹️
      I came across another issue caused by the DrawHudText:

      It's almost impossible to use some tools while the DrawHudText is active. As soon as I disable it, everything goes back to normal !

      The tools I noticed the issue are:

      • Polygon Pen Tool
      • Loop / Path Cut

      I Imagine that's because these tools draws stuff on screen in the same "canvas" the DrawHudText draws...
      I'll investigate it a bit more, maybe there's some z-depth or another settings that helps on this, maybe other flags for the GetDrawParam ...

      If anything, I could try to disable automatically the draw function if those modeling tools get selected 🤔

      Cheers,
      Flavio Diniz

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: DrawHUDText issue with viewport camera navigation

      Thanks a lot @i_mazlov !
      The issue is solved !

      posted in Bugs
      FlavioDinizF
      FlavioDiniz
    • RE: BaseDraw.DrawTexture Issue

      Fantastic @i_mazlov !
      Both issues are solved, thank you so much !

      Cheers,
      Flavio Diniz

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • BaseDraw.DrawTexture Issue

      Hi !
      In an attempt to circumvent a bug in the DrawHUDText and DrawMultipleHUDText (link below), I'm trying to use the DrawTexture function, but now we have two issues.
      (https://developers.maxon.net/forum/topic/15394/drawhudtext-issue-with-viewport-camera-navigation)

      1 - The first issue is the mouse cursor doesn't orbit to the object in the viewport, it's like the text is being drawn in the whole screen and the camera is orbiting around the text... I tested several Zdepth settings. no luck.

      2 - The second issue is the lag, notice the difference in C4D 2023 and 2025 in the video below (problem is also present in 2024).

      So far I noticed the lag (and the camera orbit issue) on the DrawHUDText, DrawMultipleHUDText and DrawTexture functions. Other simple functions like DrawPoint2D, DrawLine2D and DrawLine does't have issues.

      The code I'm using on a tag is:

      import c4d
      from c4d import plugins, bitmaps, documents
      
      def main() -> None:
          pass
      
      def draw(bd) -> bool:
          bh = c4d.plugins.BaseDrawHelp(bd, doc)
          bd.LineZOffset(2)
      
          bd.SetMatrix_Screen()
      
          text = "My Tex asssssssssssssssssssdasdasdt"
      
          cm = c4d.bitmaps.GeClipMap()
          cm.Init(0, 0, 32)
          cm.BeginDraw()
          width = cm.TextWidth(text)
          height = cm.TextHeight()
          cm.EndDraw()
          cm.Destroy()
      
          cm.Init(width, height, 32)
          cm.BeginDraw()
          cm.SetColor(255, 255, 255, 255)
          cm.TextAt(0,0,text)
          cm.EndDraw()
          bd.SetMatrix_Screen()
          bd.SetLightList(c4d.BDRAW_SETLIGHTLIST_NOLIGHTS)
      
          xpos=255
          ypos=255
      
          padr = [(c4d.Vector(xpos,ypos,0)), (c4d.Vector(xpos+width,ypos,0)), (c4d.Vector(xpos+width,ypos+height,0)), (c4d.Vector(xpos,ypos+height,0))]
          cadr = [(c4d.Vector(1,1,1)), (c4d.Vector(1,1,1)), (c4d.Vector(1,1,1)), (c4d.Vector(1,1,1))]
          vnadr = [(c4d.Vector(0,0,1)), (c4d.Vector(0,0,1)), (c4d.Vector(0,0,1)), (c4d.Vector(0,0,1))]
          uvadr = [(c4d.Vector(0,0,0)), (c4d.Vector(1,0,0)), (c4d.Vector(1,1,0)),(c4d.Vector(0,1,0))]
      
          cmbmp = bitmaps.BaseBitmap()
          cmbmp = cm.GetBitmap()
          bmp = bitmaps.BaseBitmap()
          bmp = cm.GetBitmap()
          alpha = bmp.GetInternalChannel()               #Get at the RGBA channels of the bitmap copy
          alpha = bmp.AddChannel(True, False)
      
          bd.SetDepth(False)
          bd.DrawTexture(bmp,padr,cadr,vnadr,uvadr,4,c4d.DRAW_ALPHA_NORMAL,c4d.DRAW_TEXTUREFLAGS_0)
      
          return True
      

      There's nothing special on the code, we can also see the issue with a simpler code:

      import c4d
      def main() -> None:
          pass
      def draw(bd: c4d.BaseDraw) -> bool:
          bd = doc.GetActiveBaseDraw()
          bd.DrawHUDText(200,200,"TESTING TEXT")
      
          return c4d.DRAWRESULT_OK
      

      I'm also attaching my C4D file:
      draw_hud_text_issue2.c4d

      That said, is there any working way to write text to the viewport with Python ?

      Thanks in advance !
      Flavio Diniz

      posted in Cinema 4D SDK 2025 python
      FlavioDinizF
      FlavioDiniz
    • RE: BaseDraw.DrawHUDText in Cinema4D 2024

      @ferdinand said in BaseDraw.DrawHUDText in Cinema4D 2024:

      But generally speaking, no, DrawHUDText is not broken, at least not our knowledge.

      Hi @ferdinand , sorry if this is an inappropriate place to post, but I should remember there's a bug on DrawHudText.
      It's not related to the issue @Runner009 related, but this one: https://developers.maxon.net/forum/topic/15394/drawhudtext-issue-with-viewport-camera-navigation

      I just downloaded the script you provided in the post above and tested in C4D 2024.2.0, and the issue exists, not sure if it was fixed in C4D 2024.4.

      Best,
      Flavio Diniz

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: DrawHUDText issue with viewport camera navigation

      I think it must be a bug ! and I'm surprised I haven't heard anyone talking about this so far, since the "DrawHUDText" is so common for people to use 🤔
      I also noticed the same problem happening with "DrawMultipleHUDText".

      Thanks!
      Flavio Diniz

      posted in Bugs
      FlavioDinizF
      FlavioDiniz
    • DrawHUDText issue with viewport camera navigation

      Hi!

      I made an script back in C4D 2023 to draw some information on the viewport (filename, camera lens, frame number, etc). It was working perfectly in C4D 2023, but in 2024 it is glitching the viewport camera navigation.

      It's like the drawn text is in front of everything and when you click to orbit the camera, you click on the drawn text instead of the object.

      Let me try to explain with some GIFs.
      2023: I click on the corner of the cube to orbit the camera around it and it works.
      Cinema_4D_ocPCAax3qM.gif

      2024: I click on the corner of the cube to orbit the camera and the orbit pivot insn't on the cube, but on the center of the screen.
      Cinema_4D_HsHckRZN05.mp4_1024px_24fps.gif

      It's not about the navigation mode, I already made sure I'm on the "mouse" mode.
      bb6d1516-d622-4351-8780-ee9bc7318b0a-image.png

      When I delete the script on 2024, everything goes back to the normal, so I know the problem is the script.

      and here it is, it's on a python tag:

      # Playblast Overlay by Flavio Diniz
      import c4d
      
      def main() -> None:
          pass
      
      def draw(bd: c4d.BaseDraw) -> bool:
          bd = doc.GetActiveBaseDraw()
      
          frame = bd.GetFrame()
          right = frame["cr"]
          bottom = frame["cb"]
      
          camera = "Camera: "+ bd.GetSceneCamera(doc).GetName()
          filename =  doc[c4d.DOCUMENT_FILEPATH].split("\\",-1)[-1]
          focal = str(bd.GetSceneCamera(doc)[c4d.RSCAMERAOBJECT_FOCAL_LENGTH]) +" mm"
          frame = "Frame: "+ str(doc[c4d.DOCUMENT_TIME].GetFrame(doc.GetFps()))
      
          bd.DrawHUDText(int(right /2)-300, int(bottom)-20, "{0}   |   {1} - {2}   |   {3}".format(filename, camera, focal, frame))
      
          return c4d.DRAWRESULT_OK
      

      Does anyone have any idea of what could be happening ?
      Thanks!

      Flavio Diniz

      posted in Bugs 2024 python
      FlavioDinizF
      FlavioDiniz
    • RE: Get edges segments in a polygon object

      Awesome @m_magalhaes, works perfect now!
      Thank very much!

      Flavio

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: Get edges segments in a polygon object

      Fantastic @m_magalhaes !
      works very well! and for the use I'm planning, I will always be using parallel selection segments, so cross selections isn't a issue 🙂 !

      there's an small error, I guess it's happening because there's no polygons to the left to be checked.
      alt text

      I haven't had time to fully read your code yet, but it's already very helpful!
      I'll try to solve this error by modifying your code or building another use using you as base.

      Thank you!

      (I'll let it unsolved for today, in case someone wants to post something else, then I'll change to solved)

      Flavio Diniz

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: Get edges segments in a polygon object

      @PluginStudent @C4DS
      ah, so I think this is more complex than I thought 🤔

      I guess I have to make a function to compare the edges by using their points...
      if two edges shares the same point, it means these two edges are a single segment. So create a BaseSelect of these edges and use it in a for loop.
      It may cause some bugs depending how the geometry is... but at least is a starting point and a tough one for me xD

      Thank you guys!

      Flavio Diniz

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • Get edges segments in a polygon object

      Hi!
      I'm trying to find the selected edges segments in a polygon object, like the one below:
      alt text

      I want to get each segment separated, so I can create some functions like the example below:

      for segment in segmentlist:
          MoveInUvSpace()
      

      I've tried a lot of things with BaseSelect, Neighbor and PolygonObject classes, but no success...

      here's my testing code, I was able to get the total edge count, get the ammount of edges selected edges and get the the selected edge with its index.

      import c4d
      
      def main():
          
          op = doc.GetActiveObject()
          
          nb = c4d.utils.Neighbor()
          nb.Init(op)
          
          seledges = op.GetSelectedEdges(nb,c4d.EDGESELECTIONTYPE_SELECTION) #base select
          print seledges.GetSegments()
          print seledges.GetCount()
          print seledges.GetRange(1,nb.GetEdgeCount())
          print "total edges", nb.GetEdgeCount()
          
          
          notselected = []
          selectededge = []
          bs = op.GetEdgeS()
          sel = bs.GetAll(nb.GetEdgeCount())
          for index, selected in enumerate(sel):
              if not selected: continue
              print "Index", index, "is selected"
              selectededge.append(selected)
          print notselected
          print selected
          
      
      if __name__=='__main__':
          main()
          
      

      if anyone have any hint in how I could achieve this, I would be very happy!

      Flavio Diniz

      posted in Cinema 4D SDK python r21
      FlavioDinizF
      FlavioDiniz
    • RE: Plane by Python Generator

      @indexofrefraction I know this is not what you've asked, but it might help you:
      Redshift does have a method of subdivision called screen space adaptive, which make more subdivisions on polygons that are close to the camera and less to those that are far from the camera. So it relatively lightweight because it happen only at render time and still bring good results.
      alt text

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: Plane by Python Generator

      @indexofrefraction I was experimenting this exactly right now!
      I'm sure it's not done in the most optimized way, but it does return a beautiful quad polygon, here is:

      import c4d
      
      def main():
      
          poly = c4d.PolygonObject(4,1)
      
      
          a = c4d.CPolygon(0,1,2,3)
      
      
          poly.SetPolygon(0,a)
          poly.SetPoint(0, c4d.Vector(0,0,0))
          poly.SetPoint(1, c4d.Vector(50,0,0))
          poly.SetPoint(3, c4d.Vector(0,0,-50))
          poly.SetPoint(2, c4d.Vector(50,0,-50))
      
      
          return poly
      

      edit: this is just for generating a polygon, I don't know how to make parametric subdivisions on it.

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: Close any C4D Window

      @Cairyn said in Close any C4D Window:

      That's because there is none. The Windows functionality in the API is very limited. You can open some through CallCommand but identification and handling of specific windows is not supported.

      Only thing you could do is loading a new layout.

      I was afraid of that answer 😥
      But thank you anyway 🙂

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • Close any C4D Window

      Hi !
      Is it possibly to close any Cinema4D window like the ones below by using python ?

      alt text

      I've tried acessing this command, but I had no success, because I didn't find anything on the python API to get C4D windows...
      alt text

      Thanks!

      posted in Cinema 4D SDK python r20
      FlavioDinizF
      FlavioDiniz
    • RE: Shortcuts for buttons from gui.GeDialog

      Thanks a lot @C4DS @m_adam !
      So I think it's better to create separate CommandDataplugins to perform the same action of each button, it's less complicated and allow the user to change the keyboard shortcuts and exclude the need of the GUI being always open.

      Although the m_adam suggestions may be useful for other plugins ideas I have. I'll try it later.
      Thanksss !

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • Shortcuts for buttons from gui.GeDialog

      Hello!
      I'm so happy with the C4D python API, it allows to create scripts, plugins, interfaces, menus, etc, very easily!

      My question is:
      Is it possible to assign shortcuts to these buttons from gui.GeDialog ?
      alt text

      If not, I think I could achieve that by writing separate scripts to perform the same action the button does, so it appear in the customize commands window.

      Thanks in advance!

      Flavio

      posted in Cinema 4D SDK r20 python
      FlavioDinizF
      FlavioDiniz
    • RE: Linking something to a handle

      Sorry @a_block !
      That's because I have R19 at home and R20 at the studio I work.

      But look the amazing result I got so far! it's almost done, I just need to test a little bit more to see if I find any bug and maybe implement some time saving utility.
      alt text

      Thanks again!

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz
    • RE: Linking something to a handle

      @a_block Nice!
      Thanks a lot for explaining very well and for explaining the good practices when using a python tag, I used to use it wrong many times !

      I'll certainly try to convert this script in to a plugin, since this rig is very popular in the studio I work.

      I'll post on GENERAL PROGRAMMING & PLUGIN DISCUSSIONS when its done :^)

      Thanks again!

      posted in Cinema 4D SDK
      FlavioDinizF
      FlavioDiniz