PDA

View Full Version : query render subpatch level



bazsa73
06-21-2014, 07:48 AM
Hi Folks!

I just finished my 1st python script based on this thread
http://forums.newtek.com/showthread.php?142189-display-subpatch-level
(Thanks ernpchan for kicking me into the right direction!)

So if you have a scene with lots of items and all are set to different Render Subpatch Levels (RSL)
and for some reason you happen to set the Display Subpatch Levels (DSL) to a different value than the RSL was
but later at some point when you want to render the scene and you dont want to wait ages while LW re-tesselates all the geometry
plus wastes lot of precious RAM for having 2 different geometry sets stored in RAM then you need this script because
this will read the RSL and replaces the DSL values which is great because you dont need to do it manually which can be bothersome after a while.

Use it and modify it as you wish to your needs pals.
Cheers!



import sys
import lwsdk

__author__ = " Peter Balazs"
__date__ = "June 20 2014"
__copyright__ = "Copyright (C) 2014 Peter Balazs"
__version__ = "1.0"
__maintainer__ = "Peter Balazs"
__email__ = "[email protected]"
__status__ = "beta"
__lwver__ = "11"

class display2render(lwsdk.IGeneric):
def __init__(self, context):
super(display2render, self).__init__()

# LWGeneric -------------------------------------------

def process(self, ga):
lwsdk.command('SelectAllObjects')
items = lwsdk.LWInterfaceInfo().selected_items()
LWObjectInfo = lwsdk.LWObjectInfo()
d_level = 0
r_level = 0

for item in items:
# Get the objects ID
id = lwsdk.itemid_to_str( item )
cmd = "SelectItem " + str(id)
lwsdk.command(cmd)

d_level, r_level = LWObjectInfo.patchLevel(item)

cmd = "SubPatchLevel " + str(r_level) + " " + str(r_level)
lwsdk.command(cmd)

return lwsdk.AFUNC_OK

ServerTagInfo = [
( "Python Display2Render", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Display2Render", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("LW_Display2Render", display2render) : ServerTagInfo }

ernpchan
06-21-2014, 08:33 AM
Nice!

It would also be easy to make a version of this script to set all the display values to a small value. Then you could switch back and forth really quickly.

bazsa73
06-21-2014, 12:25 PM
Nice!

It would also be easy to make a version of this script to set all the display values to a small value. Then you could switch back and forth really quickly.

Cool, thanks!
Then it would be more elegant setting up a user interface but for the time being one needs to replace this line


cmd = "SubPatchLevel " + str(low_level) + " " + str(r_level)
lwsdk.command(cmd)

where low_level is any value you want for display levels

ernpchan
06-21-2014, 03:02 PM
Ha! Learning the ui controls is next for you then.
:D

bazsa73
06-22-2014, 04:18 AM
Completed with a mini User Interface.
Modify, share, spread.

I used this great sources> http://justaddmilk.org/?p=122 , lawson3d.com

insert this after # LWGeneric -------------------------------------------


def process(self, ga):
lwsdk.command('SelectAllObjects')
items = lwsdk.LWInterfaceInfo().selected_items()
LWObjectInfo = lwsdk.LWObjectInfo()
d_level = 0
r_level = 0
#we set up a mini user interface
ui = lwsdk.LWPanels()
panel = ui.create('User Input')
msg = lwsdk.LWMessageFuncs()

#exclusive bool buttons
self.hchoice = panel.hchoice_ctl("Set Display Subpatch levels ",["to Render levels","to 1"])
#set default value
self.hchoice.set_int(0)

#panel width 300 pixel
panel.setw(300)

if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0:
ui.destroy(panel)
return lwsdk.AFUNC_OK
#get button value
buttvalue = self.hchoice.get_int()

for item in items:
# Get the objects ID
id = lwsdk.itemid_to_str( item )
cmd = "SelectItem " + str(id)
lwsdk.command(cmd)

d_level, r_level = LWObjectInfo.patchLevel(item)

if buttvalue == 0:
cmd = "SubPatchLevel " + str(r_level) + " " + str(r_level)
lwsdk.command(cmd)
else:
cmd = "SubPatchLevel " + str(1) + " " + str(r_level)
lwsdk.command(cmd)


ui.destroy(panel)
return lwsdk.AFUNC_OK