Skip to content

Instantly share code, notes, and snippets.

@nicelifeBS
Created April 1, 2014 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicelifeBS/9925143 to your computer and use it in GitHub Desktop.
Save nicelifeBS/9925143 to your computer and use it in GitHub Desktop.
modo - pyAPI test. Returns a list of all selection sets of a selected meshItem. First two methods are old python scripting (the second uses the lx.Service for query). The third method is pyAPI
#!/usr/bin/env python
import time
import lx
import lxu.select
def output(command):
'''introspect methods and classes'''
lx.out('$$$$$$$$$ dir $$$$$$$$')
for i in dir(command):
lx.out(i)
lx.out('$$$$$$$$$$$$$$$$$$$$$')
lx.out('''
###################################
API TESTING
###################################
''')
lx.out('########### py script ###########')
def pyScript():
# Stop Watch
t1 = time.time()
selSets = []
lx.eval('query layerservice layer.id ? main')
num_polset = lx.eval('query layerservice polset.N ? all')
for i in range(num_polset):
selSets.append(lx.eval('query layerservice polset.name ? %s' %i))
lx.out('selSet: ', selSets)
t2 = time.time()
# Stop Watch
lx.out('Time: ', t2-t1)
def pyScriptSvc():
lx.out('########### py script with lx.Service ###########')
# Stop Watch
t1 = time.time()
# Layer service
layer_svc = lx.Service('layerservice')
selSets = []
layer_svc.select('layer.id', 'main')
num_polset = layer_svc.query('polset.N')
for i in range(num_polset):
layer_svc.select('polset.name', str(i))
selSets.append(layer_svc.query('polset.name'))
lx.out('selSet: ', selSets)
t2 = time.time()
# Stop Watch
lx.out('Time: ', t2-t1)
def pyAPI():
lx.out('########## API ##########')
# Stop Watch
t1=time.time()
# scene service, reference of the scene and a channel read object
scene_svc = lx.service.Scene()
scene = lxu.select.SceneSelection().current()
chan_read = scene.Channels(lx.symbol.s_ACTIONLAYER_EDIT, 0.0)
# current selected items in scene
selection = lxu.select.ItemSelection().current()
# Get a int ID for the item type.
#type_mesh = scene_svc.ItemTypeLookup(lx.symbol.sITYPE_MESH)
type_mesh = lx.symbol.i_CIT_MESH
# Find the first meshItem in the selection
for item in selection:
if item.TestType(type_mesh):
meshItem = item
break
else:
meshItem = None
# Read the mesh channel from the item to get the mesh object
mesh_obj = chan_read.ValueObj(meshItem ,meshItem.ChannelLookup(lx.symbol.sICHAN_MESH_MESH))
mesh = lx.object.Mesh(mesh_obj) # mesh object
# Get the selection sets from the mesh with PICK and save them into a list
selSets = []
num_polset = mesh.PTagCount(lx.symbol.i_PTAG_PICK)
for i in xrange(num_polset):
selSets.append(mesh.PTagByIndex(lx.symbol.i_PTAG_PICK, i))
lx.out('selSets:', selSets)
# Stop Watch
t2=time.time()
lx.out('Time: ', t2-t1)
pyScript()
pyScriptSvc()
pyAPI()
@nicelifeBS
Copy link
Author

Speed comparison from my machine:

##### py script

selSet: ['01', '02']
Time: 0.000408172607422

##### py script with lx.Service

selSet: ['01', '02']
Time: 0.000134944915771

#### API

selSets: ['01', '02']
Time: 0.000102043151855

The difference between the two py scripts are amazing. And as expected the API is the fastest but also the more complex one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment