Difference between revisions of "User:Ivo.grigull"

From The Foundry MODO SDK wiki
Jump to: navigation, search
m
(Joota)
 
(18 intermediate revisions by the same user not shown)
Line 4: Line 4:
  
 
[http://modo.sdk.thefoundry.co.uk/wiki/Category:Objects SDK Objects]
 
[http://modo.sdk.thefoundry.co.uk/wiki/Category:Objects SDK Objects]
 +
 +
==== Creating an undo context in a fire and forget script ====
 +
 +
http://pastebin.com/AWNV6vGd
 +
Your scripts can simply do <pre>lx.eval('undo.init')</pre> and it'll create an undo context for you.
 +
 +
=== Python ===
 +
==== Using imp ====
 +
import imp, os, os.path
 +
def import_(filename):
 +
    (path, name) = os.path.split(filename)
 +
    (name, ext) = os.path.splitext(name)
 +
    (file, filename, data) = imp.find_module(name, [path])
 +
    return imp.load_module(name, file, filename, data)
 +
jedi = import_(r'C:\Python27\Lib\site-packages\jedi')
 +
 +
 +
=== Jedi completion ===
 +
<syntaxhighlight lang="python">
 +
# Jedi completion example
 +
 +
import imp, os, os.path
 +
 +
def import_(filename):
 +
    (path, name) = os.path.split(filename)
 +
    (name, ext) = os.path.splitext(name)
 +
    (file, filename, data) = imp.find_module(name, [path])
 +
    return imp.load_module(name, file, filename, data)
 +
 +
jedi = import_(r'C:\Python27\Lib\site-packages\jedi')
 +
 +
s = '''import imp, os, os.path
 +
os.p'''
 +
 +
script = jedi.Script (s, 2, 4, '')
 +
c = script.completions()
 +
c[8].complete
 +
</syntaxhighlight>
 +
 +
 +
=== Rebuilding the python plugin ===
 +
build clean: force: proj:extra\python
 +
build init && build proj:extra\python
 +
cd apps\modo && qmake repack
 +
 +
 +
=== Finding the scene's workspace ===
 +
 +
assemblies = [asm for asm in modo.Scene().groups if asm.type=='assembly']
 +
workspaces = [w for w in assemblies if ('SGID', 'workspace') in w.getTags().items()]
 +
 +
=== Joota ===
 +
==== Get components ====
 +
<syntaxhighlight lang="python">import Layers
 +
l = Layers.GLOABL_LAYER_OBJECT
 +
layer = l.getSelectedLayers()[0]
 +
layer.getLayerType()
 +
layer.getLayerKey()
 +
#vl = layer.getVectorLayer()
 +
feature = layer.getFeature()
 +
print [modo.Item(i).channel('elid').get() for i in feature.getComponents()]
 +
</syntaxhighlight>
 +
 +
==== Locations to remember ====
 +
* VectorImportSVGCommand
 +
* ComponentPlacer::swapComponent, ComponentPlacer::replace2D, place2D
 +
* ComponentPlacer::importSVGComponent
 +
* CurveConstraint.cpp ModifierElement::Eval draws the components in 2d (and 3d of course)
 +
* VectorImportSVGCommand::cmd_Execute
 +
* Core\VectorTools\include\VectorTools\UI\SceneController.h
 +
* VectorContextManager::removeScene
 +
* Vector Shapes live in Core\VectorTools\src\Scene\Shape.cpp
 +
* UniqueNameIndex* Shape::uniqueNameIndex in Shape.cpp this is where the indexing starts!
 +
* VectorContext.getUniqueNameIndex() return private member m_uniqueNameIndex
 +
 +
==== VectorContextManager: ====
 +
 +
// This notification occurs after the Modo scene has finished loading.
 +
// However vector layers may be created prior to this during serialization and
 +
// will need to be added to a valid scene at that point. Because of this we will
 +
// support lazy scene creation in 3 different places:
 +
//
 +
// 1. pins_newBorn - initial item creation, re-creation as a result of undo/redo.
 +
// 2. pins_Loading - item created while loading a scene
 +
// 3. sil_SceneCreate - to cover there case where we loaded a Modo scene with no layers it.
 +
 +
==== Printing ELIDS ====
 +
<syntaxhighlight lang="python">
 +
 +
for l in LAYERS.getAllLayers():
 +
    if hasattr(l, 'element'):   
 +
        print l.element.ELID
 +
 +
for l in LAYERS.getLayersByType( symbols.sLAYER_TYPE_VECTOR ):
 +
    print l.getELID_List()
 +
 +
</syntaxhighlight>
 +
 +
==== Shelve that brings back Modo hotkeys ====
 +
103058
 +
 +
==== VBOM ====
 +
*[http://stackoverflow.com/questions/12460677/python-etree-control-empty-tag-format You might need this to ensure empty Elements are closed the way we want]
 +
 +
=== Modo ===
 +
 +
==== Progress bar snippet ====
 +
<syntaxhighlight lang="python">#python
 +
 +
import time
 +
 +
def WasteTime(n,monitor):
 +
    mon = lx.object.Monitor(monitor)
 +
    mon.Initialize(n)
 +
    for i in range(n):
 +
        time.sleep(0.1)
 +
        mon.Increment(1)
 +
 +
dialog_svc = lx.service.StdDialog()
 +
mon = lx.object.Monitor(dialog_svc.MonitorAllocate('Calculating Center Of Mass ...'))
 +
try:
 +
WasteTime(50, mon)
 +
except RuntimeError as e:
 +
if e.message == 'bad result: RENDER_ABORTING':
 +
pass
 +
else:
 +
raise
 +
 +
dialog_svc.MonitorRelease()
 +
</syntaxhighlight>
 +
 +
===== Get available image file formats =====
 +
<syntaxhighlight lang="python">def get_imagesavers():
 +
    """ Returns a list of available image savers. Each entry in the returned list
 +
      is a tuple made up of the format's internal name, it's username and it's
 +
      DOS type (extension).
 +
 +
  """
 +
    host_svc = lx.service.Host()
 +
    savers = []
 +
    for x in range(host_svc.NumServers('saver')):
 +
        saver = host_svc.ServerByIndex('saver', x)
 +
        out_class = saver.InfoTag(lx.symbol.sSAV_OUTCLASS)
 +
        if  (out_class == 'image' or out_class == 'layeredimage'):
 +
            name = saver.Name()
 +
            uname = saver.UserName()
 +
            try:
 +
                dostype = saver.InfoTag(lx.symbol.sSAV_DOSTYPE)
 +
            except:
 +
                dostype = ''
 +
            savers.append((name, uname, dostype,))
 +
    return savers
 +
</syntaxhighlight>

Latest revision as of 14:20, 17 November 2016

Schematic connection

SDK Interfaces

SDK Objects

Creating an undo context in a fire and forget script

http://pastebin.com/AWNV6vGd

Your scripts can simply do
lx.eval('undo.init')
and it'll create an undo context for you.

Python

Using imp

import imp, os, os.path
def import_(filename):
    (path, name) = os.path.split(filename)
    (name, ext) = os.path.splitext(name)
    (file, filename, data) = imp.find_module(name, [path])
    return imp.load_module(name, file, filename, data)
jedi = import_(r'C:\Python27\Lib\site-packages\jedi')


Jedi completion

# Jedi completion example
 
import imp, os, os.path
 
def import_(filename):
    (path, name) = os.path.split(filename)
    (name, ext) = os.path.splitext(name)
    (file, filename, data) = imp.find_module(name, [path])
    return imp.load_module(name, file, filename, data)
 
jedi = import_(r'C:\Python27\Lib\site-packages\jedi')
 
s = '''import imp, os, os.path
os.p'''
 
script = jedi.Script (s, 2, 4, '')
c = script.completions()
c[8].complete


Rebuilding the python plugin

build clean: force: proj:extra\python
build init && build proj:extra\python
cd apps\modo && qmake repack


Finding the scene's workspace

assemblies = [asm for asm in modo.Scene().groups if asm.type=='assembly']
workspaces = [w for w in assemblies if ('SGID', 'workspace') in w.getTags().items()]

Joota

Get components

import Layers
l = Layers.GLOABL_LAYER_OBJECT
layer = l.getSelectedLayers()[0]
layer.getLayerType()
layer.getLayerKey()
#vl = layer.getVectorLayer()
feature = layer.getFeature()
print [modo.Item(i).channel('elid').get() for i in feature.getComponents()]

Locations to remember

  • VectorImportSVGCommand
  • ComponentPlacer::swapComponent, ComponentPlacer::replace2D, place2D
  • ComponentPlacer::importSVGComponent
  • CurveConstraint.cpp ModifierElement::Eval draws the components in 2d (and 3d of course)
  • VectorImportSVGCommand::cmd_Execute
  • Core\VectorTools\include\VectorTools\UI\SceneController.h
  • VectorContextManager::removeScene
  • Vector Shapes live in Core\VectorTools\src\Scene\Shape.cpp
  • UniqueNameIndex* Shape::uniqueNameIndex in Shape.cpp this is where the indexing starts!
  • VectorContext.getUniqueNameIndex() return private member m_uniqueNameIndex

VectorContextManager:

// This notification occurs after the Modo scene has finished loading.
// However vector layers may be created prior to this during serialization and
// will need to be added to a valid scene at that point. Because of this we will
// support lazy scene creation in 3 different places:
//
// 1. pins_newBorn - initial item creation, re-creation as a result of undo/redo.
// 2. pins_Loading - item created while loading a scene
// 3. sil_SceneCreate - to cover there case where we loaded a Modo scene with no layers it.

Printing ELIDS

for l in LAYERS.getAllLayers():
    if hasattr(l, 'element'):    
        print l.element.ELID
 
for l in LAYERS.getLayersByType( symbols.sLAYER_TYPE_VECTOR ):
    print l.getELID_List()

Shelve that brings back Modo hotkeys

103058

VBOM

Modo

Progress bar snippet

#python
 
import time
 
def WasteTime(n,monitor):
    mon = lx.object.Monitor(monitor)
    mon.Initialize(n)
    for i in range(n):
        time.sleep(0.1)
        mon.Increment(1)
 
dialog_svc = lx.service.StdDialog()
mon = lx.object.Monitor(dialog_svc.MonitorAllocate('Calculating Center Of Mass ...'))
try:
	WasteTime(50, mon)
except RuntimeError as e:
	if e.message == 'bad result: RENDER_ABORTING':
		pass
	else:
		raise
 
dialog_svc.MonitorRelease()
Get available image file formats
def get_imagesavers():
    """ Returns a list of available image savers. Each entry in the returned list
       is a tuple made up of the format's internal name, it's username and it's
       DOS type (extension).
 
   """
    host_svc = lx.service.Host()
    savers = []
    for x in range(host_svc.NumServers('saver')):
        saver = host_svc.ServerByIndex('saver', x)
        out_class = saver.InfoTag(lx.symbol.sSAV_OUTCLASS)
        if  (out_class == 'image' or out_class == 'layeredimage'):
            name = saver.Name()
            uname = saver.UserName()
            try:
                dostype = saver.InfoTag(lx.symbol.sSAV_DOSTYPE)
            except:
                dostype = ''
            savers.append((name, uname, dostype,))
    return savers