Learning Poser Python...

Discussion in 'Scripts - Poser' started by Ken1171, Jun 9, 2018.

  1. phdubrov

    phdubrov Noteworthy Contributing Artist

    AFAIK, not in a straight way. All solutions that I saw used either temp matfile/posefile (Netherworks) or nodetree recreation (Snarlygribbly, BB). Or, as a variation of the former, template matfile, where the script reads it, insert/change image files references, and saves with another name. (Made such script for myself, helps a lot with flowers packages, when you have a lot of texture options.)

    Had an intention to look at pickle way to do it, but still didn't. Had enough of Zope world before switched to Django.
     
  2. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    It's not particularly difficult for me to recreate this specific shader in code (only 3 nodes), but I don't know how to make a compound node out of it. I know how to create a compound node, but not how add nodes into it, or plug the respective inputs and name them. In Poser, this is not how these are created. We first select the nodes we want to group, and then activate the grouping function. In PoserPython, there is a command to create compound node, but that's all it shows.

    Any clues?
     
  3. phdubrov

    phdubrov Noteworthy Contributing Artist

    Python Shell has autocompletion and tips IDE-style. So you can see methods of CompoundData object. Never used it, but looks it's like ShaderTree manipulations.

    Add: played in the console, yes, works like a charm.
     
    Last edited: Jun 11, 2018
  4. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Oh, that's good to know. I am writing my classes on notepad, and having to restart Poser whenever I edit an imported class. Kind of a chore.
     
  5. phdubrov

    phdubrov Noteworthy Contributing Artist

    Use reload. By the way, you probably can call reload from Python Shell. Should work. Commands history works with CTRL-UpArrow, by the way. Do not remember if docs says so.
     
  6. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    What does it do? Reload all cached classes? Is it a language command or a shell command?
     
  7. phdubrov

    phdubrov Noteworthy Contributing Artist

  8. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Not sure if it's just me, but that article offers not a single code example. Do I call this from the PY file that imports the class I want to reload? Or from the Python shell? Or from the class I have modified? Sorry, I am confused.
     
  9. phdubrov

    phdubrov Noteworthy Contributing Artist

    from the PY file that imports the class

    like this:

    #dosomething.py
    import donothing
    reload(donothing)


    my = donothing.MyClass()
    my.f()

    OR (possibly) from python shell in poser. Do not forget to destroy any instances of your class you created! Instances do not change with reload.
     
  10. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Aha! Nothing like a code example - worth a thousand words. Thanks!

    I keep reading about instances not changing with reload, but I don't understand what that means. Once the program is closed, all instances go to garbage collection, and will be created again next time I run the program. I don't change classes that are still used by a running script. At least that's how I see it. Am I missing something?

    Also, I am here trying to make sense of the Python Shell. It opens like a shell, but you've mentioned it being used like an IDE with code completion? How?
     
  11. phdubrov

    phdubrov Noteworthy Contributing Artist

    Once Poser is closed - yes. Once your script finished its works - dependent on your code scope structure.

    So, if you do something like
    First test run
    a = mymodule.MyClassOldVerWithMethodA()

    Second test run
    reload(mymodule)
    a = mymodule.MyClassNewVerWithMethodB()

    probably both a.A() and a.B() could be defined. Or not. Grey zone. So better del a when the script is finished.

    autocompletion - just try to start s = poser. - and here autocompletion will fire with methods and properties. Plus you will have a tip with method parameters once you choose a method.
     
  12. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Ooh, I see! I thought instances were killed by garbage collection once execution passes their last occurrence in code.
     
  13. phdubrov

    phdubrov Noteworthy Contributing Artist

    It's right. But! We are in never-ending (until Poser quits) interactive session here. So all depends on the scope organization of the script.
     
  14. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Let's see, from the code below, is there something left after execution? As I see it, once main() finishes execution, wouldn't GC kill everything? There is no references left.

    def main():
    ....import Foo
    ....o= Foo()
    ....0.doThis()
    ....o.doThat()

    main()
     
  15. phdubrov

    phdubrov Noteworthy Contributing Artist

    This should clean instances IMHO. But not module, modules do not unload.
     
  16. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Gotcha. Thank you! I managed to get everything I wanted done, to include creating compound nodes, GUIs, and file management. Only thing missing is to understand how events work in Python. That's my next thing. :)
     
  17. Miss B

    Miss B Drawing Life 1 Pixel at a Time CV-BEE

    Sounds like you're making good headway Ken. :)
     
  18. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    Haha thanks, but not thanks to the abundance of documentation laying around. ;)
     
  19. Miss B

    Miss B Drawing Life 1 Pixel at a Time CV-BEE

    Hey, whatever works. :)
     
  20. Ken1171

    Ken1171 Dances with Bees Contributing Artist

    This was the first time in YEARS since I have found Poser documentation this poorly written. In Esha's tutorial, she has also claimed PhilC's tutorial was outdated and some parts wont work in the current version. I was putting too much faith on it, and ended up learning more from my books instead. They are old, but they get to the point more quickly than his tutorial. Maybe because books tend to be more organized than tutorials, and also cover the subjects in more depth. PhilC was presenting many code listings, but he didn't explain what some commands actually did, so I was starting to feel sort of "cheated", if you know what I mean. The code listings just weren't working for me.
     

Share This Page