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

    Thinking Particles allocation failure in new document

    Cinema 4D SDK
    python s22
    2
    7
    965
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      ivodow
      last edited by ivodow

      Hi,
      A minimal example to reproduce my issue is posted below. Am I missing a step?
      Please advise...
      Thank you

      S22.118
      Windows 10

      import c4d
      
      def main():
          temp_document = c4d.documents.BaseDocument()
          c4d.documents.InsertBaseDocument( temp_document )
          c4d.documents.SetActiveDocument( temp_document )
      
          pSys = temp_document.GetParticleSystem()
          if pSys is None:
              raise RuntimeError("Failed to retrieve Thinking Particle System from Document.")
      
          particle_id = pSys.AllocParticle()
          if particle_id == c4d.NOTOK:
              raise RuntimeError("particle_id == c4d.NOTOK" )
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • I
        ivodow
        last edited by

        I also tried creating the new document with c4d.CallCommand(12094). AllocParticle() failed with this approach as well.

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel

          hi,

          I need to look forward on this one, but using ExecutePasses does the trick for now.
          I can't say why for now, this look like a bug to me.

          import c4d
          
          def main():
              
              temp_document = c4d.documents.BaseDocument()
              c4d.documents.InsertBaseDocument( temp_document )
              c4d.documents.SetActiveDocument( temp_document )
              
              temp_document.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_NONE)
              
              pSys = temp_document.GetParticleSystem()
              if pSys is None:
                  raise RuntimeError("op is none, please select one object.")
            
          
              # Retrieves the Root group (where all particles belongs as default)
              rootGrp = pSys.GetRootGroup()
              if rootGrp is None:
                  raise RuntimeError("Failed to retrieve root group of tp master system.")
          
              # Allows each particles to get a custom colors
              rootGrp[c4d.PGROUP_USE_COLOR] = False
          
              # Creates 90 Particles
              particlesIds = pSys.AllocParticles(90)
              print particlesIds
              if not particlesIds:
                  raise RuntimeError("Failed to create 90 TP particles.")
          
              # Assigns position and colors for each particles
              for particleId in particlesIds:
                  # Checks if particles ID is ok
                  if particleId == c4d.NOTOK:
                      continue
          
                  # Calculates a position
                  sin, cos = c4d.utils.SinCos(particleId)
                  pos = c4d.Vector(sin * 100.0, cos * 100.0, particleId * 10.0)
                  # Assigns position
                  pSys.SetPosition(particleId, pos)
          
                  # Calculates a color
                  hsv = c4d.Vector(float(particleId) * 1.0 / 90.0, 1.0, 1.0)
                  rgb = c4d.utils.HSVToRGB(hsv)
          
                  # Assigns color
                  pSys.SetColor(particleId, rgb)
          
              # Pushes an update event to Cinema 4D
              c4d.EventAdd()
          
          # Execute main()
          if __name__=='__main__':
              main()
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • I
            ivodow
            last edited by

            Manuel,

            Thank you very much for the workaround.

            Can you tell me more about what ExecutePasses() does, and when it should be normally be called? I am also having an issue where exporting large numbers of scripted particles to alembic (again, by scripting) is creating a nearly empty file. I see the flag BUILDFLAGS_EXPORT on ExecutePasses() and wonder if that might do the trick.

            1 Reply Last reply Reply Quote 0
            • ManuelM
              Manuel
              last edited by

              hi,

              sorry i forgot the link to the doc for the function :

              ExecutePasses

              That allow you to be "sure" that everything is initialized, updated and calculated. As you may see, I'm saying "sure" because sometimes, you need to call it twice in a row.

              Some generator are really special.

              We like to separate question into separate thread, that allow better search results for others people. Can you open another thread for your other issue.
              It doesn't hurt to call ExecutePasses but on a really heavy scene, it will just slow down your script if it's not necessary.

              Cheers,
              Manuel

              MAXON SDK Specialist

              MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • I
                ivodow
                last edited by

                Thank for the additional information.
                So, would ExecutePasses() with the BUILDFLAGS_EXPORT flag set be typically called just before exporting to alembic (to be on the safe side)?

                1 Reply Last reply Reply Quote 0
                • ManuelM
                  Manuel
                  last edited by Manuel

                  @ivodow said in Thinking Particles allocation failure in new document:

                  So, would ExecutePasses() with the BUILDFLAGS_EXPORT flag set be typically called just before exporting to alembic (to be on the safe side)?

                  the exporter is calling ExecutePasses several times, you don't really need it.
                  And because the scene can be sometimes quiet complexe, you have to call it several times in a row.

                  for example, in the alembic exporter :

                  68d39647-ef56-430b-ae1a-2189e1b83617-image.png

                  Cheers,
                  Manuel

                  MAXON SDK Specialist

                  MAXON Registered Developer

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post