Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Dec 02 3:16 pm)
try it, change nothing :-(
import poser, os
scn = poser.Scene()
fig = scn.CurrentFigure()
sdir = "C:UsersAndryDesktopTEST"
frame = 0
myfiles = os.listdir(sdir)
print myfiles
for myfile in myfiles:
if myfile[-3:] == "obj":
cfile = os.path.join(sdir, myfile)
try:
print cfile
imex = scn.ImExporter()
options = imex.ImportOptions("obj", None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', cfile, options)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
act.SetVisibleInRender(1)
frame = frame + 1
scn.SetFrame(frame)
act.SetVisibleInRender(0)
if frame > 2:
scn.SetFrame(frame - 2)
act.SetVisibleInRender(0)
scn.SetFrame(frame)
except:
print "t error on ",myfile
print "Done"
SetAnimated is listed under Shader Node Input methods.
I think you would be better writing a toggle function. I am not entirely sure what exactly you are after, but maybe something like this would work
import poser
scene=poser.Scene()
def toggleanim(scene,framecount,toggle=False):
scene.SetFrame(0)
if toggle:
for frame in range(frames):
scene.SetFrame(frame)
else:
return False
toggleanim(scene, framecount, True)
the third value ( True ) should overwrite the default of False and therefore the animation should toggle (in this case frame by frame)
Locked Out
after looking at your code it seems you want to make an actor invisible in certain frames and visible in others so there are 3 ways to accomplish this :
as markschum said you can use
setvisibleinrender
or you can use
SetVisible
SetVisibleInCamera
import poser
scn=poser.Scene()
def ActVisible(act,toggle,frame):
scene.SetFrame(frame)
act.SetVisible(act,toggle,frame)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
ActVisible(act,1,0)
frame = frame + 1
scn.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scn.SetFrame(frame - 2)
ActVisible(act,0,frame)
scn.SetFrame(frame)
both setvisibleinrender and setvisibleincamera will not appear to do anything until you actually render
Locked Out
i have wrote:
import poser, os
scn = poser.Scene()
fig = scn.CurrentFigure()
sdir = "C:Users"
frame = 0
myfiles = os.listdir(sdir)
print myfiles
for myfile in myfiles:
if myfile[-3:] == "obj":
cfile = os.path.join(sdir, myfile)
try:
print cfile
imex = scn.ImExporter()
options = imex.ImportOptions("obj", None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', cfile, options)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
ActVisible(act,1,0)
frame = frame + 1
scn.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scn.SetFrame(frame - 2)
ActVisible(act,0,frame)
scn.SetFrame(frame)
except:
print "t error on ",myfile
print "Done"
but i found error message if run this script:
line 33
act.SetName(myfile[:-4])
^
IndentationError: unexpected unindent
important i dont want invisible in render only but i need invisible obj in scene:
because I have to load heavy objects and this is the only way to lighten the scene
now error:
line 6
def ActVisible(act,toggle,frame)
^
SyntaxError: invalid syntax
the script:
import poser, os
scn = poser.Scene()
def ActVisible(act,toggle,frame)
scene.SetFrame(frame)
act.SetVisible(toggle)
fig = scn.CurrentFigure()
sdir = "C:Users"
frame = 0
myfiles = os.listdir(sdir)
print myfiles
for myfile in myfiles:
if myfile[-3:] == "obj":
cfile = os.path.join(sdir, myfile)
try:
print cfile
imex = scn.ImExporter()
options = imex.ImportOptions("obj", None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', cfile, options)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
ActVisible(act,1,0)
frame = frame + 1
scn.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scn.SetFrame(frame - 2)
ActVisible(act,0,frame)
scn.SetFrame(frame)
except:
print "t error on ",myfile
print "Done"
error here:
line 7
scn.SetFrame(frame)
^
IndentationError: expected an indented block
the script:
import poser, os
scn = poser.Scene()
def ActVisible(act,toggle,frame):
scn.SetFrame(frame)
act.SetVisible(toggle)
fig = scn.CurrentFigure()
sdir = "C:Users"
frame = 0
myfiles = os.listdir(sdir)
print myfiles
for myfile in myfiles:
if myfile[-3:] == "obj":
cfile = os.path.join(sdir, myfile)
try:
print cfile
imex = scn.ImExporter()
options = imex.ImportOptions("obj", None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', cfile, options)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
ActVisible(act,1,0)
frame = frame + 1
scn.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scn.SetFrame(frame - 2)
ActVisible(act,0,frame)
scn.SetFrame(frame)
except:
print "t error on ",myfile
print "Done"
this is how I would write it - all the indentations are correct
import poser, os,os.path
scn = poser.Scene()
fig = scn.CurrentFigure()
def ActVisible(act,toggle,frame):
scn.SetFrame(frame)
act.SetVisible(toggle)
def ImportObj(cfile):
imex = scn.ImExporter()
options = imex.ImportOptions("obj", None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', cfile, options)
sdir = os.path.join('c:', os.sep , 'users')
frame = 0
myfiles = os.listdir(sdir)
print myfiles
for myfile in myfiles:
if myfile.endswith('.obj'):
cfile = os.path.join(sdir, myfile)
try:
ImportObj(cfile)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
ActVisible(act,1,0)
frame += 1
scn.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scn.SetFrame(frame - 2)
ActVisible(act,0,frame)
scn.SetFrame(frame)
except:
print 'error on ', myfile
print 'done'
Locked Out
lol - ok - i missed an indent :)
for myfile in myfiles:
if myfile.endswith('.obj'):
cfile = os.path.join(sdir, myfile)
try:
ImportObj(cfile)
act = scn.CurrentActor()
act.SetName(myfile[:-4])
ActVisible(act,1,0)
frame += 1
scn.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scn.SetFrame(frame - 2)
ActVisible(act,0,frame)
scn.SetFrame(frame)
except:
print 'error on ', myfile
print 'done'
Locked Out
yes - you can, but what you must understand is that the visible object will remain visible in all frames (the invisible object will remain invisible in all frames) that is to say -
once it is made visible - it will be visible in every frame from start to finish, likewise if it is invisible it will be invisible in all frames.
the only way to use it in an animation is to set it on and off as you need it
i will sitemail you with an email addy.
Locked Out
def ActVisible(act,toggle,frame):
obj=''
scene.SetFrame(frame)
for frame in frames:
if act.Name().endswith(frame):
act.SetVisible(1)
else:
act.SetVisible(0)
for myfile in myfiles:
if myfile.endswith('.obj'):
cfile = os.path.join(sdir, myfile)
try:
ImportObj(cfile)
act = scene.CurrentActor()
act.SetName(myfile[:-4])
act.SetName(act.Name())+'%03d' % frame
ActVisible(act,1,0)
frame += 1
scene.SetFrame(frame)
ActVisible(act,1,frame)
if frame > 2:
scene.SetFrame(frame - 2)
ActVisible(act,0,frame)
scene.SetFrame(frame)
except:
Locked Out
the reason nothing is changing is because the script is not moving the animation and the animation is not re-drawing.
this script will do that, but it does not account for lights and cameras.
import poser
scene = poser.Scene()
act = scene.CurrentActor()
frame = 0
for act in scene.Actors():
name = act.Name() + ' - %03d' % frame
act.SetName(name)
frame +=1
for f in range(scene.NumFrames()):
if act.Name().endswith(str(f)):
scene.SetFrame(f)
scene.SelectActor(scene.Actor(act.Name()))
act.SetVisible(1)
else:
for act in scene.Actors():
if not act.Name().endswith(str(f)):
scene.SelectActor(scene.Actor(act.Name()))
act.SetVisible(0)
scene.DrawAll()
Locked Out
import poser, os,os.path
scn = poser.Scene()
fig = scn.CurrentFigure()
def IsValid(actor):
if actor !='' and actor !=None:
if actor.IsLight() or actor.IsCamera():
return False
else:
return True
def ActVisible():
for act in scene.Actors():
act.SetName(myfile[:-4])
name = act.Name() + ' - %03d' % frame
if IsValid(act):
act.SetName(name)
frame +=1
for f in range(scene.NumFrames()):
if act.Name().endswith(str(f-1)) and IsValid(act):
scene.SetFrame(f)
scene.SelectActor(scene.Actor(act.Name()))
act.SetVisible(1)
else:
for act in scene.Actors():
if not act.Name().endswith(str(f-1)) and IsValid(act):
scene.SelectActor(scene.Actor(act.Name()))
act.SetVisible(0)
scene.DrawAll()
def ImportObj(cfile):
imex = scn.ImExporter()
options = imex.ImportOptions("obj", None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', cfile, options)
sdir = os.path.join('c:', os.sep , 'users')
frame = 0
myfiles = os.listdir(sdir)
print myfiles
for myfile in myfiles:
if myfile.endswith('.obj'):
cfile = os.path.join(sdir, myfile)
try:
ImportObj(cfile)
except:
print 'error on ', myfile
ActVisible
print 'done'
Locked Out
ok - this should work
import poser , os.path
act=scene.CurrentActor()
sdir = os.path.join('c:','users')
def IsValid(actor):
if actor !='' and actor !=None:
if actor.IsLight() or actor.IsCamera():
return False
else:
return True
def ImportObj(fName):
imex = scene.ImExporter()
options = imex.ImportOptions('obj', None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', fName, options)
actlist=[]
lof=os.listdir(sdir)
for f in lof:
if f.endswith('.obj'):
fName = os.path.join(sdir, f)
try:
ImportObj(fName)
except:
print 'error on ', f
print 'done'
[actlist.append(act) for act in scene.Actors() if IsValid(act)]
la=len(actlist)
for nf in range(la):
actlist[nf].SetVisible(1)
scene.SetFrame(nf+1)
for i in range(la):
if not i == nf:
actlist[i].SetVisible(0)
scene.DrawAll()
for x in range(10000000):
x+=1
x=0
#========================================================#
you may need to edit the IsValid function to add more things you do not want to change in your scene
eg.
if actor.Name()=='Ground':
return False
Locked Out
same error:
line 3, in
act=scene.CurrentActor()
NameError: name 'scene' is not defined
this is the script:
import poser , os.path
act=scene.CurrentActor()
scene = poser.Scene ()
sdir = "C:SEQFOLDER"
def IsValid(actor):
if actor !='' and actor !=None:
if actor.IsLight() or actor.IsCamera():
return False
else:
return True
def ImportObj(fName):
imex = scene.ImExporter()
options = imex.ImportOptions('obj', None)
options[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 0
options[poser.kImOptCodeOFFSETZ] = 0.0
options[poser.kImOptCodeOFFSETY] = 0.0
options[poser.kImOptCodeOFFSETX] = 0.0
options[poser.kImOptCodeFLIPUTEXTCOORDS] = 0
options[poser.kImOptCodeWELDIDENTICALVERTS] = 0
options[poser.kImOptCodeCENTERED] = 0
options[poser.kImOptCodePERCENTFIGSIZE] = 0
options[poser.kImOptCodeFLIPVTEXTCOORDS] = 0
options[poser.kImOptCodeFLIPNORMS] = 0
options[poser.kImOptCodePLACEONFLOOR] = 0
imex.Import('obj', 'File Format Wavefront', fName, options)
actlist=[]
lof=os.listdir(sdir)
for f in lof:
if f.endswith('.obj'):
fName = os.path.join(sdir, f)
try:
ImportObj(fName)
except:
print 'error on ', f
print 'done'
[actlist.append(act) for act in scene.Actors() if IsValid(act)]
la=len(actlist)
for nf in range(la):
actlist[nf].SetVisible(1)
scene.SetFrame(nf+1)
for i in range(la):
if not i == nf:
actlist[i].SetVisible(0)
scene.DrawAll()
for x in range(10000000):
x+=1
x=0
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
Any idea ?