Tuesday, 20 March 2018

MODO and LDRAW (Part 3)

One of the problems that I discovered with using MODO command line was that there appear to be a number of commands that don't seem to work.  They work in the GUI version of MODO but when you execute the commands in the command line, MODO_CL responds that it has executed the command but doesn't actually do anything - this is frustrating especially when you're just starting using the scripting tools and you've only got a limited trial period to figure things out.  Some of these commands play a key role in framing the model in camera and then rendering the resulting output.

These commands include...

viewport.fitSelected
camera.fit true true
camera.syncView
render.syncView

All the above are useful for trying to frame a model in camera automatically.  By the time I realised these commands didn't work I'd lost a couple of days.  So I needed a mechanism of figuring out how to get the bounding box data for a model in MODO.  There are some useful leads in The Foundry community pages but needless to say not that many trying to frame LEGO models from the command line.

In the end I created the following python script that I could call from MODO_CL and it would give me the bounding box (both local and world) dimensions for all the assets (bricks) in the model.

#C:\python27\python.exe

# From MODO_CL prompt execute the following...
#Open your LDR file...
#scene.open "C:\Users\Neil\Google Drive\modoscript\lighthouse2.ldr"
#Call this script!
#script.implicit "C:\Users\Neil\AppData\Roaming\Luxology\BoundingBox.py"

import lx

selLayerIDs = []

selLayers = lx.evalN("query layerservice layers ? all")
print selLayers
for layer in selLayers:
    #this will also 'select' the layer for the layerservice
    layerID = lx.eval1('query layerservice layer.ID ? %s' % layer)
    selLayerIDs.append(layerID)
print "Layer Name", selLayerIDs

#select items
for mesh in selLayerIDs:
    lx.eval('select.subItem %s add' % mesh)
    print mesh
    lbounds = lx.eval('query layerservice layer.bounds ? %s' % mesh)
    wbounds = lx.eval('query layerservice layer.wbounds ? %s' % mesh)
    print lbounds
    print wbounds

It's looks simple but the problems I had in getting this script to run from the command line were considerable - some python scripts ran, some didn't - I never figured out why.  Errors from both Python and MODO_CL were difficult to untangle and isolating the data from individual bricks, which should have been easy, turned out to be anything but! 


I ended up analyzing the output in Excel because I was running out time with my trial version and I was never really able to isolate how to calculate the camera framing from the bounding box information - it should be easy but in the time I had available it defeated me.

I've included it here in case anyone else works with MODO_CL, LEGO, LDRAW and Python - this may help you get started.

My trial of MODO has now ended so I need to wait for MODO V12 which The Foundry have said should be out shortly before I can investigate MODO any more.

No comments:

Post a Comment