Difference between revisions of "TomDym"

From The Foundry MODO SDK wiki
Jump to: navigation, search
Line 54: Line 54:
 
     a = view.Center()
 
     a = view.Center()
 
     a = view.WorkPlane()
 
     a = view.WorkPlane()
 +
</pre>
 +
 +
=== Listeners ===
 +
 +
<pre>
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
class ListenerTwo(lxifc.NavigationListener):
 +
def __init__(self):
 +
self.listenerService = lx.service.Listener()
 +
self.listenerService.AddListener(self)
 +
self.item = modo.Mesh()
 +
self.view = lx.object.View
 +
lx.out('hey')
 +
 +
def nav_Wheel(self,view, item):
 +
lx.out('Worked')
 +
 +
def nav_Up(self, view, item):
 +
#is Called when move is started
 +
lx.out('nav_up')
 +
 +
def nav_Move(self, view, item, hot, pos, rot, zoom):
 +
pass
 +
#is called every "move" while held down
 +
#lx.out('nav_move')
 +
 +
def nav_Delta(self, view, item, hot, pos, rot, zoom):
 +
lx.out('nav_Delta')
 +
 +
def nav_Down(self, view, item):
 +
#is Called when move is ended
 +
lx.out('nav_down')
 +
 +
def nav_HotSyncPre(self, view, item):
 +
lx.out('nav_HotSyncPre')
 +
 +
def nav_HotSyncPost(self, view, item):
 +
lx.out('nav_HotSyncPost')
 +
 +
ListenerTwo() #instance a Listener to initialize it
 +
 +
###################################
 +
 +
##################################
 +
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
geo  = modo.MeshGeometry("Mesh").internalMesh
 +
port = lx.object.ListenerPort(geo)
 +
 +
class mesh_listener(lxifc.MeshListener):
 +
undoService = lx.service.Undo()
 +
def __init__(self):
 +
self.listenerService = lx.service.Listener()
 +
self.COM_object = lx.object.Unknown(port)
 +
 +
def ml_Changes(self, event):
 +
print "change"
 +
 +
l = mesh_listener()
 +
port.AddListener(l)
 +
 +
 +
###################################
 +
#Command Listener
 +
##################################
 +
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
svc_listen = lx.service.Listener()
 +
 +
class CmdListener(lxifc.CmdSysListener):
 +
def __init__(self):
 +
svc_listen = lx.service.Listener()
 +
svc_listen.AddListener(self)
 +
self.armed = True
 +
 +
def cmdsysevent_UserRedo(self):
 +
#pass
 +
#is called everytime a redo is called
 +
lx.out('cmdsysevent_UserRedo')
 +
 +
def cmdsysevent_UserUndo(self):
 +
#pass
 +
#is called everytime a undo is called
 +
lx.eval('log.masterClear')
 +
lx.out('cmdsysevent_UserUndo')
 +
 +
def cmdsysevent_ExecutePre(self,cmd,type,isSandboxed,isPostCmd):
 +
if self.armed:
 +
cmd = lx.object.Command(cmd)
 +
            # lx.out("'%s' will fire shortly" % cmd.Name())
 +
if cmd.Name() == "app.quit":
 +
lx.eval('replay.fileClose')
 +
 +
def cmdsysevent_ExecutePost(self,cmd,isSandboxed,isPostCmd):
 +
if self.armed:
 +
cmd = lx.object.Command(cmd)
 +
lx.out("'%s' has finished" % cmd.Name())
 +
lx.out('cmdsysevent_ExecutePost')
 +
pass
 +
 +
def cmdsysevent_RefireBegin(self):
 +
        # we don't want a bunch of events when the user is
 +
        # dragging a minislider or something like that,
 +
        # so we disarm the listener on RefireBegin...
 +
self.armed = False
 +
 +
cmdListener1 = CmdListener()
 +
 +
 +
######################################################
 +
#SCENE ITEM LISTENER
 +
######################################################
 +
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
class ListenerTwo(lxifc.SceneItemListener):
 +
def __init__(self):
 +
self.listenerService = lx.service.Listener()
 +
self.COM_object = lx.object.Unknown(self)
 +
self.listenerService.AddListener(self.COM_object)
 +
 +
def sil_ItemAdd(self, item):
 +
lx.out('sil_ItemAdd')
 +
 +
def __del__(self):
 +
self.listenerService.RemoveListener(self.COM_object)
 +
 +
 +
list = ListenerTwo() #instance a Listener to initialize it
 +
 +
######################################################
 +
#Selection Listener
 +
######################################################
 +
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
svc_listen = lx.service.Listener()
 +
 +
class CmdListener(lxifc.CmdSysListener):
 +
def __init__(self):
 +
svc_listen = lx.service.Listener()
 +
svc_listen.AddListener(self)
 +
self.armed = True
 +
 +
def cmdsysevent_UserRedo(self):
 +
#pass
 +
#is called everytime a redo is called
 +
lx.out('cmdsysevent_UserRedo')
 +
 +
def cmdsysevent_UserUndo(self):
 +
#pass
 +
#is called everytime a undo is called
 +
lx.eval('log.masterClear')
 +
lx.out('cmdsysevent_UserUndo')
 +
 +
def cmdsysevent_ExecutePre(self,cmd,type,isSandboxed,isPostCmd):
 +
if self.armed:
 +
cmd = lx.object.Command(cmd)
 +
            # lx.out("'%s' will fire shortly" % cmd.Name())
 +
if cmd.Name() == "app.quit":
 +
lx.eval('replay.fileClose')
 +
 +
def cmdsysevent_ExecutePost(self,cmd,isSandboxed,isPostCmd):
 +
if self.armed:
 +
cmd = lx.object.Command(cmd)
 +
lx.out("'%s' has finished" % cmd.Name())
 +
lx.out('cmdsysevent_ExecutePost')
 +
pass
 +
 +
def cmdsysevent_RefireBegin(self):
 +
        # we don't want a bunch of events when the user is
 +
        # dragging a minislider or something like that,
 +
        # so we disarm the listener on RefireBegin...
 +
self.armed = False
 +
 +
cmdListener1 = CmdListener()
 +
 +
 +
 +
class ListenerTwo(lxifc.SelectionListener):
 +
def __init__(self):
 +
self.listenerService = lx.service.Listener()
 +
self.COM_object = lx.object.Unknown(self)
 +
self.listenerService.AddListener(self.COM_object)
 +
self.type = modo.Item.type
 +
 +
def selevent_Add(self, type, subtType):
 +
lx.eval('log.MasterClear')
 +
lx.out('selevent_Add')
 +
pass
 +
 +
def selevent_Current(self, type):
 +
lx.eval('log.MasterClear')
 +
lx.out('selevent_Current')
 +
pass
 +
 
 +
def selevent_Remove(self, type, subtType):
 +
lx.eval('log.MasterClear')
 +
lx.out('selevent_Remove')
 +
pass
 +
 
 +
def selevent_Time(self, time):
 +
lx.out(time)
 +
pass
 +
 
 +
def selevent_TimeRange(self, type):
 +
pass
 +
 +
 +
list = ListenerTwo() #instance a Listener to initialize it
 +
 +
######################################################
 +
#User Value Listener
 +
######################################################
 +
 +
 +
#python
 +
import lx
 +
import lxifc
 +
import modo
 +
 +
class ListenerTwo(lxifc.UserValueListener?):
 +
def __init__(self):
 +
self.listenerService = lx.service.Listener()
 +
self.COM_object = lx.object.Unknown(self)
 +
self.listenerService.AddListener(self.COM_object)
 +
self.userValue = lx.eval('user.value someValue ?')
 +
 +
def uvl_Added(self, userValue):
 +
lx.out('uvl_Added')
 +
pass
 +
 
 +
def uvl_DefChanged(self, userValue):
 +
lx.out('uvl_DefChanged')
 +
pass
 +
 +
def uvl_Deleted(self, name):
 +
lx.out('uvl_Deleted')
 +
pass
 +
 
 +
def uvl_ValueChanged(self, userValue):
 +
lx.out('uvl_ValueChanged')
 +
pass
 +
 +
 +
 +
list = ListenerTwo() #instance a Listener to initialize it
 +
 +
 +
####
 +
 +
Session Listener
 +
 +
####
 +
 +
# python
 +
import lx, lxifc
 +
svc_listen = lx.service.Listener()
 +
class sesListener(lxifc.SessionListener):
 +
    def __init__(self):
 +
        svc_listen = lx.service.Listener()
 +
        svc_listen.AddListener(self)
 +
    def sesl_SystemReady(self):
 +
        lx.out('Session Listener: system was ready')
 +
sesListener = sesListener()
  
 
</pre>
 
</pre>

Revision as of 11:02, 24 October 2019

DoWhileUserIsIdle

//If you try to execute a script while holding down a modifier like ctrl or shift, it will postpone execution until you release the modifier
#python
import lx, lxifc
 
class visitor(lxifc.Visitor):                  
    def __init__(self):     # The initial setup method 
        pass
 
    def vis_Evaluate(self):                           
        lx.out("Visitor")
pSrv = lx.service.Platform()
vis = visitor()
com_visitor = lx.object.Unknown(vis)
pSrv.DoWhenUserIsIdle(com_visitor, lx.symbol.fUSERIDLE_MODIFIER_KEYS_UP)

//Too cancel it you need to pass exactly the same com object and flags
pSrv.CancelDoWhenUserIsIdle(com_visitor, lx.symbol.fUSERIDLE_MODIFIER_KEYS_UP )

Toggle Command

lx.eval('tool.set falloff.linear ?+')

Path of Selected Preset Item

#!python
ppaths = lxu.select.PresetPathSelection().current()
print ppaths

View3dService Example

import modo, lx

viewSvc = lx.service.View3Dport()
currentView = lx.object.View3D(viewSvc.View(viewSvc.Current()))

for i in range(viewSvc.Count()):
    view = lx.object.View3D(viewSvc.View(i))

    print view.Matrix(0)
    print view.Angles()
    print view.Axis()
    print view.EyeVector()
    lx.out(view.WorkPlane())
    a = view.To3D(150.0,150.0,2000)
    a = view.Center()
    a = view.WorkPlane()

Listeners

#python
import lx
import lxifc
import modo

class ListenerTwo(lxifc.NavigationListener):
	def __init__(self):
			self.listenerService = lx.service.Listener()
			self.listenerService.AddListener(self)
			self.item = modo.Mesh()
			self.view = lx.object.View
			lx.out('hey')

	def nav_Wheel(self,view, item):
		lx.out('Worked')
		
	def nav_Up(self, view, item):
		#is Called when move is started
		lx.out('nav_up')
		
	def nav_Move(self, view, item, hot, pos, rot, zoom):
		pass
		#is called every "move" while held down
		#lx.out('nav_move')
		
	def nav_Delta(self, view, item, hot, pos, rot, zoom):
		lx.out('nav_Delta')
		
	def nav_Down(self, view, item):
		#is Called when move is ended
		lx.out('nav_down')
		
	def nav_HotSyncPre(self, view, item):
		lx.out('nav_HotSyncPre')

	def nav_HotSyncPost(self, view, item):
		lx.out('nav_HotSyncPost')

ListenerTwo() #instance a Listener to initialize it

###################################

##################################

#python
import lx
import lxifc
import modo

geo  = modo.MeshGeometry("Mesh").internalMesh
port = lx.object.ListenerPort(geo)

class mesh_listener(lxifc.MeshListener):
	undoService = lx.service.Undo()
	def __init__(self):
		self.listenerService = lx.service.Listener()	
		self.COM_object = lx.object.Unknown(port)
		
	def ml_Changes(self, event):
		print "change"
		
l = mesh_listener()
port.AddListener(l)


###################################
#Command Listener
##################################

#python
import lx
import lxifc
import modo

svc_listen = lx.service.Listener()

class CmdListener(lxifc.CmdSysListener):
	def __init__(self):
			svc_listen = lx.service.Listener()
			svc_listen.AddListener(self)
			self.armed = True
		
	def cmdsysevent_UserRedo(self):	
		#pass
		#is called everytime a redo is called
		lx.out('cmdsysevent_UserRedo')
		
	def cmdsysevent_UserUndo(self):
		#pass
		#is called everytime a undo is called
		lx.eval('log.masterClear')
		lx.out('cmdsysevent_UserUndo')
		
	def cmdsysevent_ExecutePre(self,cmd,type,isSandboxed,isPostCmd):
		if self.armed:
			cmd = lx.object.Command(cmd)
            # lx.out("'%s' will fire shortly" % cmd.Name())
			if cmd.Name() == "app.quit":
				lx.eval('replay.fileClose')

	def cmdsysevent_ExecutePost(self,cmd,isSandboxed,isPostCmd):
		if self.armed:
			cmd = lx.object.Command(cmd)
			lx.out("'%s' has finished" % cmd.Name())
		lx.out('cmdsysevent_ExecutePost')
		pass

	def cmdsysevent_RefireBegin(self):
        # we don't want a bunch of events when the user is
        # dragging a minislider or something like that,
        # so we disarm the listener on RefireBegin...
		self.armed = False

cmdListener1 = CmdListener()


######################################################
#SCENE ITEM LISTENER
######################################################

#python
import lx
import lxifc
import modo

class ListenerTwo(lxifc.SceneItemListener):
	def __init__(self):
			self.listenerService = lx.service.Listener()
			self.COM_object = lx.object.Unknown(self)
			self.listenerService.AddListener(self.COM_object)
		
	def sil_ItemAdd(self, item):
		lx.out('sil_ItemAdd')
		
	def __del__(self):
		self.listenerService.RemoveListener(self.COM_object)


list = ListenerTwo() #instance a Listener to initialize it

######################################################
#Selection Listener
######################################################

#python
import lx
import lxifc
import modo

#python
import lx
import lxifc
import modo

svc_listen = lx.service.Listener()

class CmdListener(lxifc.CmdSysListener):
	def __init__(self):
			svc_listen = lx.service.Listener()
			svc_listen.AddListener(self)
			self.armed = True
		
	def cmdsysevent_UserRedo(self):	
		#pass
		#is called everytime a redo is called
		lx.out('cmdsysevent_UserRedo')
		
	def cmdsysevent_UserUndo(self):
		#pass
		#is called everytime a undo is called
		lx.eval('log.masterClear')
		lx.out('cmdsysevent_UserUndo')
		
	def cmdsysevent_ExecutePre(self,cmd,type,isSandboxed,isPostCmd):
		if self.armed:
			cmd = lx.object.Command(cmd)
            # lx.out("'%s' will fire shortly" % cmd.Name())
			if cmd.Name() == "app.quit":
				lx.eval('replay.fileClose')

	def cmdsysevent_ExecutePost(self,cmd,isSandboxed,isPostCmd):
		if self.armed:
			cmd = lx.object.Command(cmd)
			lx.out("'%s' has finished" % cmd.Name())
		lx.out('cmdsysevent_ExecutePost')
		pass

	def cmdsysevent_RefireBegin(self):
        # we don't want a bunch of events when the user is
        # dragging a minislider or something like that,
        # so we disarm the listener on RefireBegin...
		self.armed = False

cmdListener1 = CmdListener()



class ListenerTwo(lxifc.SelectionListener):
	def __init__(self):
			self.listenerService = lx.service.Listener()
			self.COM_object = lx.object.Unknown(self)
			self.listenerService.AddListener(self.COM_object)
			self.type = modo.Item.type
		
	def selevent_Add(self, type, subtType):
		lx.eval('log.MasterClear')
		lx.out('selevent_Add')
		pass
		
	def selevent_Current(self, type):
		lx.eval('log.MasterClear')
		lx.out('selevent_Current')
		pass
   
	def selevent_Remove(self, type, subtType):
		lx.eval('log.MasterClear')
		lx.out('selevent_Remove')
		pass
   
	def selevent_Time(self, time):
		lx.out(time)
		pass
   
	def selevent_TimeRange(self, type):
		pass


list = ListenerTwo() #instance a Listener to initialize it

######################################################
#User Value Listener
######################################################


#python
import lx
import lxifc
import modo

class ListenerTwo(lxifc.UserValueListener?):
	def __init__(self):
			self.listenerService = lx.service.Listener()
			self.COM_object = lx.object.Unknown(self)
			self.listenerService.AddListener(self.COM_object)
			self.userValue = lx.eval('user.value someValue ?')
		
	def uvl_Added(self, userValue):
		lx.out('uvl_Added')
		pass
  
	def uvl_DefChanged(self, userValue):
		lx.out('uvl_DefChanged')
		pass
 
	def uvl_Deleted(self, name):
		lx.out('uvl_Deleted')
		pass
  
	def uvl_ValueChanged(self, userValue):
		lx.out('uvl_ValueChanged')
		pass



list = ListenerTwo() #instance a Listener to initialize it


####

Session Listener

####

# python
import lx, lxifc
svc_listen = lx.service.Listener()
class sesListener(lxifc.SessionListener):
    def __init__(self):
        svc_listen = lx.service.Listener()
        svc_listen.AddListener(self)
    def sesl_SystemReady(self):
        lx.out('Session Listener: system was ready')
sesListener = sesListener()