Forum: Poser Python Scripting


Subject: batch import

stonemason opened this issue on Sep 30, 2008 · 16 posts


stonemason posted Tue, 30 September 2008 at 8:02 PM

hi guys..I'm wondering if it's possible to have a script do batch imports with Poser?

Cheers
Stefan

Cg Society Portfolio


PhilC posted Tue, 30 September 2008 at 9:21 PM

Like import all OBJ files from a particular directory?


stonemason posted Tue, 30 September 2008 at 9:39 PM

hi Phil,
yes..point to a directory & let it load in everything,maybe using the last used import settings?(everything unchecked)
I've got a parented prop set with over 100 parts & importing manually takes forever.

Cg Society Portfolio


PhilC posted Tue, 30 September 2008 at 10:39 PM

Try this:-
http://www.philc.net/forum/viewtopic.php?t=2334


stonemason posted Tue, 30 September 2008 at 11:31 PM

thanks for looking into this Phil..unfortunately I get the message '0 OBJ files imported'
it allows me to browse & select the folder but nothing imports

using P7 & 6 and selecting a geometrie folder at the root of drive

I should add I know bugger all about Python so it may be something simple I'm missing,

Cg Society Portfolio


PhilC posted Wed, 01 October 2008 at 12:46 AM

Can you please post a Windows Explorer screen shot showing the OBJ files?

Thanks


stonemason posted Wed, 01 October 2008 at 12:58 AM

sure..

Cg Society Portfolio


PhilC posted Wed, 01 October 2008 at 1:44 AM

Your files need to have the extension ".obj" or ".OBJ"

Alternatively edit the script so that it will attempt to import every file.

def visit(something, dirname, names):<br></br>
    for name in names:<br></br>
        try:  <br></br>
           
filepath = os.path.join(dirname,name) <br></br>
            importOBJ(filepath)<br></br>
        except:<br></br>
            pass

nruddock posted Wed, 01 October 2008 at 3:03 AM

Quote - Your files need to have the extension ".obj" or ".OBJ"

They do have the right extension, but Windows Explorer is set to hide them.
This doesn't affect anything but what it displays.

Although it doesn't appear necessary in this case, but why not use string.split(name,".")[1].lower() == "obj" as the extension test to cover odd combinations of cases.


PhilC posted Wed, 01 October 2008 at 6:05 AM

Originally I was using :-

if string.split(name,".")[1] == "obj" or string.split(name,".")[1] == "OBJ":

which is pretty much the same thing unless the extension was "oBj" which though possible I felt unlikely.

I appreciate that the extension has been hidden. It should indeed not make a difference but the script was failing to import the files so I used the try/except edit to take the file type out of the equation.

The next questions to ask would be:-

Are they well formed OBJ files?
Can they be imported manually?
Has the latest Poser service release been installed?


semidieu posted Wed, 01 October 2008 at 6:26 AM

Why don't you use:

os.path.splitext(filename)[1].lower()=='.obj'

This way, you will be sure to have the correct extension!

Another question Stefan: do you want to load all obj in the folder or choose a selection of props located in a folder ?


PhilC posted Wed, 01 October 2008 at 7:42 AM

OK duh!

This line was missing from the top of the script:-

scene = poser.Scene()

I've also changed the extension test to include the mixed case scenario as opposed to the either upper or lower case that I had originally.

http://www.philc.net/forum/viewtopic.php?p=12956

The script worked on my machine because I had previously been running any number of scripts that had set this variable. I found the error when I ran the script on a different computer after a reboot.


stonemason posted Wed, 01 October 2008 at 7:56 AM

hey that new version works perfectly...117 props loaded... whilst making a coffee :)

thank you very much Phil!

semidieu..I wanted everything from one folder loaded,but having an option to selected a group of objects might make the script handy for others.
I always dread having to manually bring in each part to Poser as my sets are so big,so many parts,
Phil you've saved me from a hell of a repetetitve task..I owe you one :)

Cheers
Stefan

Cg Society Portfolio


semidieu posted Wed, 01 October 2008 at 1:15 PM

I'll make this script and will post it somewhere (rdna).


stonemason posted Wed, 01 October 2008 at 10:09 PM

hey if your working on import scripts..how about a batch export while your at it?..not really anything I have an immediate use for but to fill out the suite it would be a cool adition.

Cg Society Portfolio


semidieu posted Thu, 02 October 2008 at 12:58 PM

Ok... I'll do it :D