Ok, I found my own answer, and I shall provide the information here...
This started out as an experiment, seeing if there was another way to add item shapes to nulls besides going through the add server/use comring path, which in LScript takes around 300 lines of code.
Turns out, there is another way, at least in Python:
Code:
lwsdk.command("Generic_AddItemShape")
This layout command has several parameters that can be added to it to fill out all the fields of the itemshape plugin. These are:
Code:
Shape= '<shape>' #Shape = Standard, Box, Ball, Pyramid, Diamond, Ring, Grid, None. Example - Shape='Box'
Axis='<axis>' #axis = 0 for X, 1 for Y, 2 for Z
Scale='<scale>' #scale = scale of shape as a float.
Filled='<flag>' #flag = False, True
XRay='<flag>'
Opacity='<opacity>' Opacity of shape, as a float (0...1)
Label='<label>' #Label Text
Justification='<justify>' #Justify = 0 (Left),1 (Center),2(Right)
UseSelectedColor='<flag>' #flag = False, True
UseUnselectedColor='<flag>'
UseTextColor='<flag>'
SelectedColor='<r g b>' #<r g b> is three float values for the red, green, and blue colors
UnSelectedColor='<r g b>
TextColor='<r g b>'
LineTo='<Object ID>' # Object ID must be a hex value. and prefaced with 0x. <--- This is what was giving me problems.
Or, to put it into one Python Function:
Code:
import lwsdk
id2str = lambda x : lwsdk.itemid_to_str( x )
def addNullShape(scale=1.0, axis=0, shape=0, filled=0, sf=0, uf=0, tf=0, scol=(0,0,0), ucol=(0,0,0), tcol=(0,0,0), opacity=1.0, draw2=0, label='', justify=0, xray=0):
s0 = ('False','True')
lshap = ["'Standard'","'Box'", "'Ball'","'Pyramid'","'Diamond'","'Ring'","'Grid'","'None'"]
a = "Generic_AddItemShape Replace='True'"
a += " Shape=%s Axis='%d' Scale='%f'" % (lshap[shape],axis,scale)
a += " Filled='%s' XRay='%s' Opacity='%f'" %(s0[filled],s0[xray],opacity)
if label: a+= " Label='%s' Justification='%d'" % (label, justify)
if sf: a+= " UseSelectedColor='%s' SelectedColor='%f %f %f'" % (s0[sf],scol[0],scol[1],scol[2])
if uf: a+= " UseUnselectedColor='%s' UnselectedColor='%f %f %f'" % (s0[uf],ucol[0],ucol[1],ucol[2])
if tf and label: a+=" UseTextColor='%s' TextColor='%f %f %f'" % (s0[tf],tcol[0],tcol[1],tcol[2])
if draw2: a+= " LineTo='0x%s'" % id2str(draw2)
lwsdk.command(a)
This can be optimized quite a bit, and probably made into one big formatted string command.
Code:
import lwsdk
id2str = lambda x : lwsdk.itemid_to_str( x )
def addNullShape(scale=1.0, axis=0, shape=0, filled=0, sf=0, uf=0, tf=0, scol=(0,0,0), ucol=(0,0,0), tcol=(0,0,0), opacity=1.0, draw2=0, label='', justify=0, xray=0):
s0 = ('False','True')
lshap = ["'Standard'","'Box'", "'Ball'","'Pyramid'","'Diamond'","'Ring'","'Grid'","'None'"]
a = "Generic_AddItemShape Replace='True'"
a += " Shape=%s Axis='%d' Scale='%f'" % (lshap[shape],axis,scale)
a += " Filled='%s' XRay='%s' Opacity='%f'" %(s0[filled],s0[xray],opacity)
if label: a+= " Label='%s' Justification='%d'" % (label, justify)
if sf: a+= " UseSelectedColor='%s' SelectedColor='%f %f %f'" % (s0[sf],scol[0],scol[1],scol[2])
if uf: a+= " UseUnselectedColor='%s' UnselectedColor='%f %f %f'" % (s0[uf],ucol[0],ucol[1],ucol[2])
if tf and label: a+=" UseTextColor='%s' TextColor='%f %f %f'" % (s0[tf],tcol[0],tcol[1],tcol[2])
if draw2: a+= " LineTo='0x%s'" % id2str(draw2)
lwsdk.command(a)
lwsdk.command('AddNull A_Null')
lwsdk.command("Position 1 0 1")
sel = lwsdk.LWInterfaceInfo().selected_items()
_id = sel[len(sel)-1]
lwsdk.command("AddNull MyNull")
addNullShape (.1,1,4,0,1,1,1,(1,1,0),(0,1,0),(0,1,1),1.0,_id,'Label',2,0)
The example above adds A_Null and saves it's ID, adds MyNull and gives it an octahedron shape at .1 Scale, draws a line to A_null, and sets a text label that is right justified, and sets the colors to Yellow, Green, and Cyan.
Bookmarks