Thinking Particles allocation failure in new document
-
Hi,
A minimal example to reproduce my issue is posted below. Am I missing a step?
Please advise...
Thank youS22.118
Windows 10import 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()
-
I also tried creating the new document with c4d.CallCommand(12094). AllocParticle() failed with this approach as well.
-
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 -
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.
-
hi,
sorry i forgot the link to the doc for the function :
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 callExecutePasses
but on a really heavy scene, it will just slow down your script if it's not necessary.Cheers,
Manuel -
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)? -
@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 :
Cheers,
Manuel