PDA

View Full Version : Single-shot Python script to set content directory and custom paths in Layout



Celshader
05-09-2013, 06:02 PM
An artist asked if it was possible to use LWPython to set both the content directory and custom paths in Layout and Modeler. I am not yet sure about Modeler, but I have a single-shot script that sets custom paths in Layout.

In this script, LWPython sets the Layout content directory to "C:\Temp\Content", the default Objects directory to "Meshes," and the default Images directory to "Plates."



import lwsdk, os

## this version places all of the variables up here for easier editing.
contentDir = "C:\\Temp\\Content"
objectsDir = os.path.join(contentDir, "Meshes")
imagesDir = os.path.join(contentDir, "Plates")

## single-shot formatting:
ga = lwsdk.GenericAccess()

## turn off "Use custom paths" to "clean out" the old custom directories
ga.evaluate("UseCustomPaths 0")

## change the Content Directory.
ga.evaluate("ContentDirectory " + contentDir)

## turn on "Use custom paths" to enable fresh, new custom directories
ga.evaluate("UseCustomPaths 1")

## change only those directories that you like. The rest will remain at LW defaults.
ga.evaluate("ContentTypeDirectory Objects " + objectsDir)
ga.evaluate("ContentTypeDirectory Images " + imagesDir)

## tell the user what you've done.
title = "Done."
message = "Changed content directory to: " + contentDir
mf = lwsdk.LWMessageFuncs()
mf.info( title, message )

nickdigital
05-09-2013, 10:26 PM
Very cool!

:thumbsup:

BigHache
05-10-2013, 05:25 AM
Thanks Jen.

wellsichris
02-21-2014, 02:58 PM
Jen did you ever figure out a way to do this in modeler? I have been banging my head against it as of late.

thanks

also for anyone that uses Generation, This will connect to generation and get the open project and change your content directory to it. I'm trying to do the same for modeler but haven't figured out the correct command, maybe even put it as a startup command so as you startup, it will see if generation is running and just set it for you. of course change to match your file structure, and tab in the if statement.

import lwsdk, os
import sys
sys.path.append('c:\\Python27\\Lib\\site-packages')

import PeyeonScript as eyeon

gen = eyeon.scriptapp("Generation")
if gen != None:
proj = gen.ProjectGet()
projectName = proj.Path
contentDir = projectName + "LW\\"
lwsdk.command("ContentDirectory " + contentDir)