Sat, Nov 30, 4:43 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Resize Image_Map Nodes?


parrotdolphin ( ) posted Thu, 08 October 2009 at 12:39 AM · edited Sat, 30 November 2024 at 4:38 AM

Hi all,

Is there any script out there that will re-size the Image_Map node(s) for a material? I use a lot of seamless tiles and I thought it would be nice to have something like this. To be more specific, a user could enter a scale factor on the script. The script would then find all the image_map nodes for the currently selected material and multiply the U_Scale and V_Scale by the factor provided by the user.

I actually have a lot of other ideas too, but I'll start with this. One thing I'll say is that it shouldn't scale an Image_Map if it's hooked up to Reflection. Maybe not Refraction either (haven't played with that one).

So, I guess if anyone has anything like this, I'm really interested, and if not, can anyone direct me on how I'd start out writing one on my own? Maybe there is some similar script I could look at? 

Thanks for any help,
Janet


markschum ( ) posted Thu, 08 October 2009 at 1:30 AM

Look at the script I did to change the blinn setting . That shows how to get the shader tree and find nodes of a specific type and set the parameter values.  You should be able to work the rest out by reading the poser python methods manual . (off the help menu in poser)

It is not that complicated for a basic node setup, but it gets harder as you get more complex.


parrotdolphin ( ) posted Thu, 08 October 2009 at 11:02 PM

Thanks very much for the help. I've got a bit done after taking your advice. :)

I wanted the script to be for just the current material, and I got it to do that, but I was trying to get it to not re-size the reflection map image. But it doesn't work, the reflection map image gets re-sized too, and now I'm stumped.

Here's my script:

import poser
factor = 2   #  amount to scale tiled images
#factor = AskFloat("Enter the scale factor")
mat = poser.Scene().CurrentMaterial()
tree = mat.ShaderTree()
nods = tree.Nodes()
for nod in nods:
 print mat.Name()
 print poser.Scene().CurrentMaterial().ReflectionMapFileName()
 refmap = poser.Scene().CurrentMaterial().ReflectionMapFileName()
 if nod.Type() == poser.kNodeTypeCodeIMAGEMAP:
  print nod.Input(0).Name()
  imfile = nod.Input(0).File()
  if imfile != refmap:
   e = nod.Input(2).Value()
   nv = e * factor       
   nod.Input(2).SetFloat(nv)
   e = nod.Input(3).Value()
   nv = e * factor      
   nod.Input(3).SetFloat(nv)
tree.UpdatePreview()
print "Done"

The output is this:
skirt
C:Program FilesPoser6Runtime_V4.2RuntimetexturesPd-Metalspdmt-Reflect01.jpg
Image_Source
Traceback (most recent call last):
  File "C:Program FilesPoser 7RuntimePythonposerScriptsParrotDolphinchange_ImagemapTimes2.py", line 13, in ?
    imfile = nod.Input(0).File()
AttributeError: File

So, it likes nod.Input(0).Name() just fine but it doesn't like nod.Input(0).File()
I am just going off the .mt5 file to get the syntax hopefully right.

Any ideas anyone? 

Thanks, Janet


markschum ( ) posted Thu, 08 October 2009 at 11:52 PM · edited Thu, 08 October 2009 at 11:55 PM

try imfile = nod.Input(0).Value()
the returned value depends on what the input is , so for a filename you should get a string containing the file name.

Use the python methods manual. Its a pdf file in the poser program folder and available from the help menu.

You can use  input.InNode  to find out what node is plugged in to a particular input but that gets tedious in complex materials.


parrotdolphin ( ) posted Fri, 09 October 2009 at 7:57 PM

Thank you. That worked fine. Thanks for the additional info too! :)


parrotdolphin ( ) posted Sat, 10 October 2009 at 9:53 AM

One more question please. Can someone tell if this script will work okay on a MAC? Here's the updated script, with the user input working:

import poser
factor = 100

def GETfactor():
 prcent = poser.DialogSimple.AskFloat("Enter a percent to scale the current material by.")
 if prcent != None and prcent != 0:
  return prcent
 else:
  print "Please type in a number next time. The number cannot be zero."
  return 100
  
factor = GETfactor() / 100

if factor != 1:
 refmap = poser.Scene().CurrentMaterial().ReflectionMapFileName()
 mat = poser.Scene().CurrentMaterial()
 tree = mat.ShaderTree()
 nods = tree.Nodes()
 for nod in nods:
  if nod.Type() == poser.kNodeTypeCodeIMAGEMAP:
   imfile = nod.Input(0).Value()
   if imfile != refmap and factor != 1:
    nv = nod.Input(2).Value() * factor       
    nod.Input(2).SetFloat(nv)
    nv = nod.Input(3).Value() * factor      
    nod.Input(3).SetFloat(nv)
 tree.UpdatePreview()

Thanks again, Janet


Vex ( ) posted Wed, 28 October 2009 at 6:19 PM

it works in snow Leopard P8 sR1, but its a bit awkward.

if you type in say 90 for the first time, it will set it to 90. then if you type in another number, instead of scaling from 1/1 it scales from 0.9/0.9



markschum ( ) posted Wed, 28 October 2009 at 7:07 PM · edited Wed, 28 October 2009 at 7:10 PM

Yes, thats right, it scales whatever the current uv scale settings are by the factor input.
You can remove the scale calculation lines nv = nod.Input(3).Value() * factor and directly set the input value nod.Input(3).SetFloat(nv) by replacing nv with the value prcnt .

askfloat should let you enter a decimal value , like 0.9 directly , but your way may be clearer .


parrotdolphin ( ) posted Wed, 28 October 2009 at 8:24 PM

Thank you Vexiphne!

I think it works how it should for the purpose. It's for a tiled image that usually isn't at scale 1/1 to begin with. The problem with tiles is that you can't really see what they look like in the preview window - you need to do a quickie render to see them correctly.  So a user could render and then say - I want it whatever percent bigger or smaller. And adjust according to the render. It all hinges on the size of the object vs. the size it is in the render (think of a dress vs a little arm band) and that along with how much room it takes up on the UV plane.

I waffled back forth about the percent vs the decimal factor (90% or 0.9), and figured percent might be more what people are used to.

Anyway, big ramble.. :)   thanks for testing it for me.


Privacy Notice

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.