danborn opened this issue on Jan 19, 2011 · 25 posts
danborn posted Wed, 19 January 2011 at 10:07 PM
G'day All,
Noob to Poser & Python here, but am fairly-well versed in CAD and scripting automation. Basically, I'm using the animation keyframes in Poser as a comic-strip storyboard. The net result are gross changes in camera, poses and props between keyframes, and no interpolating animation is (or will ever be) required.
So what I'd like to accomplish is 'capturing' camera position and figure poses frame-by-frame to the Library for each comic strip, for reuse in future episodes going forward.
Currently I'm doing this manually, and it's been a real pain in my date!
User Setup:
To keep it simple, I envision capturing just poses for the 'selected' figure, and operating on the 'selected' library collections for poses and cameras. And to further simplfy, I envision using the frame number as the library pose and camera position save-name -- thus the library collections created will be self-indexing to the comic strip episode frames from whence they came.
So to begin, the user first selects the desired figure, and the desired library collections for poses and cameras.
Python Script Pseudocode:
Am pretty handy with a text editor (UltraEdit), VBA, VBS, Perl and Regular Expressions, but Python is new territory. Now the user...
Runs the script, and a confirmation dialog box is shown naming the user's selected figure, and and Library pose and camera collections that will be updated, with options for 'OK' and 'Cancel'.
If user clicks OK, then loop thru the frames (partially based on a scrap of code I found thanks to Mr. Okham), red is my psedocode:
for n in range(scene.NumFrames()):
scene.SetFrame(n)
# Pad-out n with leading zeros, as required...
nnnnnn = Pad(n)
# Auto-overwrite any existing library elements of the same name...
scene.SaveLibrary("Pose", nnnnn)
scene.SaveLibrary("Camera", nnnnn)
self.master.destroy()
In the time it took me to write this, I could've indexed perhaps one of my comic strips. And there's dozen more to do with many more on the way. Going forward, as I come down the learning curve on Python, I envision adding multiple characters and props to the loop, and I do promise to share the results as a token of my appreciation for the leg-up here.
So if any of you 'Pythoncologists' out there have an extra few minutes to flesh-out this straw horse, I'd be much obliged...
Cheers!
Danborn
markschum posted Wed, 19 January 2011 at 10:46 PM
ok, www.python.org for the manuals on python itself. There is a pdf file in Poser that gives you the poser specific commands.
You are aware that saving your file as a pz3 (scene) file will save everything ? what you describe is fairly common for a series of pics all using the same basic set.
the self.master.destroy bit is from tkinter and is not required if you are doing a single pass program
you need to select the figure to save the pose for and select the camera being saved.
the library to save in must be specified but yo can code it as a relative path
and you can create the folder manually to suit each project.
poselib = ":runtime:libraries:pose:myposeset:"
camlib = ":runtime:librariesmyposeset:"
posenam = fig.Name + nnnn
savenam = poselib +posenam
scene.SaveLibraryPose( savenam )
scene.SaveLibraryCamera( )
a simple dialog like this
dialog = poser.DialogSimple.YesNo(message)
if dialog == 1:
print " Continuing with script."
will let you put out a message and get a yes/no reply
I will try to write something tomorrow for you .
markschum posted Wed, 19 January 2011 at 11:55 PM
the savelibrarypose lines need to be changed to include the start and end frane number which in my script is n .
EnglishBob posted Thu, 20 January 2011 at 4:00 AM
It took me a while to work out why you would want to do this, but I think I get it now. I quite often use the animation slider in a non-linear way, to render a series of variations on a single scene; sometimes with nothing more than different camera angles, sometimes with small or not-so-small variations in the figures' poses. It's an efficient way to wring the maximum use out of a single scene set-up.
However I've sometimes been in the situation where I want to alter the scene considerably, which means going through the timeline and saving poses, cameras and lights for the parts I want to re-use. This proposed script would be very useful for that.
Mind if I fiddle along with this?
markschum posted Thu, 20 January 2011 at 9:33 AM
Be my guest :)
It should be fairly easy to alter to do all figures and props.
I actually wondered if it would be easier to pull apart the pz3 file, but that seemed more work.
danborn posted Thu, 20 January 2011 at 10:45 PM
The more the merrier...!
Let me try to shine a ray of light or two into my thinking, and perhaps that will spur some insights from a coding perspective:
Like a situation comedy, the comics re-use the same set, with the same actors and props, over and over.
To press on with the 'set' paradigm, I build a 'virtual set' with all the needed 'locales' in the .pz3 file ... for example, if it were 'Seinfeld', the pz3 file contains Jerry's apartment, the Soup Nazi's kitchen, Kramer's apartment, etc. but all sharing common walls between them.
If the comic needs a new locale, I just build it into the set and move forward with that pz3 file, keeping the existing locales fixed for compatibility with saved poses and cameras.
Some expanded thinking on the 'self-indexing' feature...
Thus the proposed script should greatly simplify the task of FINDING the poses and camera setups used in previous episodes, for utilization in new episodes. Because restoring the pose or camera info is easy... but FINDING the right info to restore is the hard part!
So I haven't noodled with example script provided just yet, but will start cracking on it this weekend.
Regards & Thanks!
Danborn
markschum posted Thu, 20 January 2011 at 11:26 PM
The script will prompt with the current figure name for a yes/no response and it will list the generated names for the pose and camera. That name is the figure or camera name with a 4 digit frame number appended.
The path to the correct folder is added to the filename for the save.
Amending the script to prompt for a project name would not be hard , and automatically creating the folders isn't difficult either. There is no way I know of to get the pz3 file name from in Poser.
Doing all the figures is a simple loop, props are a little harder but doable.
The current script does all frames , not all keyframes, so If you build scenes at 10,20,30 etc it will need to be changed.
EnglishBob posted Sat, 22 January 2011 at 5:46 PM
A couple of things remain. There seems to be an inconsistency between SaveLibraryPose, which by default saves single frame poses and automatically supplies the .pz2 extension, and SaveLibraryCamera which saves animated camera settings and requires the script to supply the extension.
I've fixed the extension bug and a few others - the changes I made are marked by comments in the attached script. I can't find how to tell SaveLibraryCamera to save single frame settings - the Python methods manual says there's a parameter which I've set to zero, but I still get animated cm2s.
markschum posted Sat, 22 January 2011 at 7:14 PM
did you try scene.SaveLibraryCamera(“RuntimeLibraries MyCamera.cm2”, 0,2,2) for a single frame of camera at frame 2?
I dont have poser running at the moment so I cant test.
My copy of python methods gives path, multiframe, start frame , end frame as parameters for savelibrarycamera. multiframe = 0 for single frame.
EnglishBob posted Sun, 23 January 2011 at 6:46 AM
I tried
scn.SaveLibraryCamera( camnam, 0, n, n )
but it still saved an animated camera - in Poser 7 at least. None of the parameters I'm applying to SaveLibraryPose or SaveLibraryCamera seem to be working, both are just doing their defaults. (I tried adding a parameter to SaveLibraryPose to include morphs, but that didn't have any effect either.)
Bear in mind that I'm a total Python newb, so I may have missed something obvious. ;)
markschum posted Sun, 23 January 2011 at 9:35 AM
I will try to get a test done today . The only other thing I can think to try is defining variable as integer and using that but it seems unlikely.
markschum posted Sun, 23 January 2011 at 2:09 PM
The pose part seems to work.
For my test I added a SetFrame(n) to the script and changed the command to scn.SaveLibraryPose(path,0,0)
I am know working on the camera.
I have switched to the last script posted by EnglishBob.
markschum posted Sun, 23 January 2011 at 8:52 PM
Here is the script as my last attempt. I think the poses work, with morphs included , which may be ok. I may have to write a camera script to save the single camera.
EnglishBob posted Mon, 24 January 2011 at 8:34 AM
I posted a query at PhilC's forum, in case he hasn't seen this thread.
Being able to save the poses is a good start for me. Even if I have to save the camera manually it will be a saving of work, since I generally only need to keep the main camera on each frame.
markschum posted Mon, 24 January 2011 at 10:39 AM
I have a save camera script nearly done , The paramater names are not quite what I expected but thats not hard to fix. Should be done today.
I was thinking that the morphs should be saved with the pose, so that the character gets set correctly. If thats not whats needed it may be easier to use one of the pose saver scripts that already exist instead of the python savelibrarypose.
EnglishBob posted Mon, 24 January 2011 at 11:17 AM
Quote - I was thinking that the morphs should be saved with the pose, so that the character gets set correctly. If thats not whats needed it may be easier to use one of the pose saver scripts that already exist instead of the python savelibrarypose.
Sometimes you would want to apply the poses to the same character - this would be likely with a comic book type scenario. Other times you might want to change the character, in which case the ideal would be to keep the expression morphs but ditch the rest. I don't know of any way to do that without maintaining a list of which morphs are which for each defined character. It's a lot easier to opt not to save any morphs in that case, I think.
markschum posted Mon, 24 January 2011 at 4:27 PM
there are a couple things to be added but it seems to work.
the code is a bit of a mess :(
If this works I suggest removing the camera code from the other script and modifying it to save poses for all figures.
EnglishBob posted Mon, 24 January 2011 at 5:08 PM
Mess or no, it certainly seems to do the job, thanks.
PhilC posted Mon, 24 January 2011 at 5:15 PM
Why not just save the scene, then for the next figure:-
Load the scene.
Find the next figure in the library.
Load to the scene using the "Replace" option rather than the more used "Add to".
The new figure will replace the existing figure, and here is the kicker it will take on its animated pose.
Cameras will remain unchanged.
Click:save
Click:select next figure
Click:change fig button
Hope that helps.
markschum posted Mon, 24 January 2011 at 6:53 PM
EnglishBob posted Tue, 25 January 2011 at 5:38 AM
Thanks again Mark. I think this has reached the point where I dare to apply it to my project. :) I'll let you know how it goes.
markschum posted Tue, 25 January 2011 at 10:24 AM
Remember to remove the camera stuff from the pose script, actually just comment out the savelibrarycamera line. The camera script will overwrite any files of the same name.
EnglishBob posted Wed, 26 January 2011 at 2:31 PM
I had an initial glitch because I tried to create my libraries in an external runtime and hadn't spotted that it uses the main runtime by default. Both scripts seem to have done their jobs, anyway, so thanks once again.
If I foresee using this often, which is a possibility, I may merge the pose and camera scripts into one. On the other hand, there may be situations where I might want to save one aspect and not the other. I was going to procrastinate, but I couldn't decide when to start. :)
markschum posted Wed, 26 January 2011 at 6:17 PM
you could always just add a command to execute the camera script from the pose script.
You may want to modify the pose script to do all the figures in one run.
EnglishBob posted Thu, 27 January 2011 at 3:40 AM
For now, I had only one figure that I wanted to keep anyway - and I can imagine that in a multi-figure scene, I'd probably not want to save all their poses. Running the script on each individual is no big effort, after all. I suppose one could get really fancy and select the required figures from a list, but I'm not that keen. :)