PDA

View Full Version : Return number of servers on a channel



ernpchan
11-30-2016, 03:06 AM
Is there a way to return the number of servers applied to the envelope of a channel?

Ryan Roye
11-30-2016, 10:59 AM
Here's the simplest way I can think of. This script looks at the items in the user selection, checks their "X.Position" channel, and prints out any plugins they are using, if any. It also prints the number of servers.



import lwsdk

# Get ItemID selection (for script-based functions)
UserSelection = lwsdk.LWInterfaceInfo().selected_items()

for x in range(0, len(UserSelection)):
cGrp = lwsdk.LWItemInfo().chanGroup(UserSelection[x])
chan = lwsdk.LWChannelInfo().nextChannel(cGrp, None)

while chan!= None:
chanName = lwsdk.LWChannelInfo().channelName(chan)

# Insert any channel functions here as desired.
if chanName == "Position.X":
print "Position X Found!"
ServerCount = 1

while ServerCount != None:
Server = lwsdk.LWChannelInfo().server(chan, lwsdk.LWCHANNEL_HCLASS, ServerCount)
print Server
if Server != None:
ServerCount += 1
else:
NumberOfServers = ServerCount - 1
ServerCount = None

chan = lwsdk.LWChannelInfo().nextChannel(cGrp, chan)

print NumberOfServers


Now if you want to check whether or not a channel is controlled via an expression... currently I don't know if its possible as I see no functions that can check for their existence.

ernpchan
11-30-2016, 02:32 PM
Thanks Ryan. I'm already doing something similar. Was hoping there was a direct way to query the number of servers without having to iterate and check.

Ryan Roye
11-30-2016, 03:24 PM
Thanks Ryan. I'm already doing something similar. Was hoping there was a direct way to query the number of servers without having to iterate and check.

If you ever find a way to find whether or not a channel is driven by an expression, let me know. Sometimes I need rigging scripts that can pick apart which items are constrained and which are not, and this kind of blocks me from making things fully automatic/error free for the user.

ernpchan
11-30-2016, 06:18 PM
If you ever find a way to find whether or not a channel is driven by an expression, let me know. Sometimes I need rigging scripts that can pick apart which items are constrained and which are not, and this kind of blocks me from making things fully automatic/error free for the user.

Feature request it. I couldn't find anything that let you check that. Just applying and deleting expressions in the lscript dox.

jwiede
02-05-2017, 06:03 PM
Feature request it. I couldn't find anything that let you check that. Just applying and deleting expressions in the lscript dox.

Did anyone ever file this as a feature request?

There's a bunch of cases like this in LW Python SDK. PRIS (or whatever) ought to provide proper "Pythonic" iterators/generators for processing such entity/attribute lists/hierarchies.