View Full Version : Set background image

05-15-2013, 10:34 AM
Hey guys,

After some hunting around in the docs regarding loading images, I noticed that it doesnt create an Image Object Agent like lscript. Instead it returns the ID of the image you load/replace/etc. I am trying to find the equivalent to this Lscript code:


Currently I am able to load an image and get its ID. However, according to the information in the docs I can't current set the background image I can only return its ID. So I hope I can bypass this limitation using something like the following command:

bgImageID = lwsdk.LWImageList().load(imgPath)
bgImage = some command to convert the ID into an image object agent
lwsdk.command('SetBackgroundImage %s' % bgImage)

The problem is that lscript creates an image agent where as python only gives me an ID when loading an image. Does anyone know how to take this ID and get the image object agent associated with it? Or a workaround to set the background image in python that doesn't involve calling an external lscript?


05-16-2013, 03:18 AM
"SetBackgroundImage sname
Set the background image to the named image. The image must already be loaded into the scene. You should use the image name "(none)" to clear an existing image from the slot."

So it just needs name.

"SetBackgroundImage black.png"

05-16-2013, 05:19 AM
In python the second parameter is not the name but the position in the list i.e. a number. This is my test code, substitute you own locations.



#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

This is a LightWave Command Sequence plug-in (Modeler) that creates
a ball and a box, each in a separate layer.

import sys
import lwsdk

__author__ = ""
__date__ = ""
__copyright__ = ""
__version__ = "1.0"
__maintainer__ = ""
__email__ = ""
__status__ = ""
__lwver__ = "11"

class background_test(lwsdk.IGeneric):
def __init__(self, context):
super(background_test, self).__init__()

# LWCommandSequence -----------------------------------
def process(self, mod_command):
# bgname = "C:\\LightWave64Bit11.5\\Content\\Images\\Environme nts\\Backgrounds\\landscape_background.jpg"
# bgname = "C:\\LightWave64Bit11.5\\Content\\Images\\Environme nts\\DirtyBldg\\newtek_sky29.jpg"
il = lwsdk.LWImageList()
bgImageID = il.load("C:\\LightWave64Bit11.5\\Content\\Images\\Environme nts\\Backgrounds\\landscape_background.jpg")
bgImage = il.name(bgImageID)
listp = 0
ilf = il.first()
while ilf:
if ilf == bgImageID:
lwsdk.command("SetBackgroundImage %s" % listp)
ilf = il.next(ilf)
listp = listp + 1
return lwsdk.AFUNC_OK

ServerTagInfo = [
( "Python Background Test", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Background Test", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )

ServerRecord = { lwsdk.GenericFactory("LW_PyBackground", background_test) : ServerTagInfo }

05-16-2013, 10:01 AM
Great! Thank you both for the information. This really helps and I am sure other people will find this useful as well.


05-16-2013, 01:06 PM
SetBackgroundImage [name]
SetBackgroundImage [index]
appears to be both working, even from Utilities > Command Input

05-16-2013, 03:18 PM
good to know :)