Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36

Thread: Kryslin's Python Questions

  1. #31
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Next question:

    I'm currently working on converting my lscripts to python. With use of the PRIS library, things are going quite well; I prototype the scripts as one shots, then code them into a class based script.

    Anyway, I've come into a problem; PRIS doesn't have something analogous to the isCurve() lScript function. I know this is a call to polyType(), and should return a True value if the polygon is of lwsdk.POLTYPE_CURB, false if otherwise.

    Not all the hard to do. the PRIS library stores its mesh op session in a global variable. Can this global variable be read by a script that is using the library in which it is defined? ie:
    Code:
    my_mesh_op = lwsdk.pris.modeler._local_me #Assign the current pris mesh op to a local variable.
    I'm not seeing much to answer the question either way between google and my Python books.

    If that's the case, it'll make thing a bit easier. Otherwise, I'll have to go in and do things the harder way...

    *edit* Nevermind, I ran a short test, and you can get access to the PRIS global variable for a mesh op session...
    Last edited by Kryslin; 06-08-2020 at 09:26 AM.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  2. #32
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    I need to get the polygon IDs associated with a point ID.

    in (soon to be broken) LScript, assuming that v is a valid point ID, I would do so by using the .polygon() method.
    Code:
    //An Example
    foreach v in points{
       assoc_polys = v.polygon();
       (...do stuff...)
    }
    How does one go about this in Python?

    From my reading of the various SDK documents (what a disorganized mess), it appears that I have to gather a lot of data regarding selected points and the edges associated with them to get the polygon ID's associated with the point ID. Am I on the right track, or have I gone down a rabbit hole?
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  3. #33
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    I have a question for those of you who know the python SDK...

    I have discovered lwsdk.command('Generic_AddItemShape'), and have figured out all the fields to set a null's item shape parameters with it (in less than 500 lines of code!), except one:

    Draw Line To.

    Does anyone know it? I've tried "DrawTo=", "LineTo=", "DrawLineTo=", "Draw=","Line=" and "To=" and so far, no results. Any clues or hints?
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  4. #34
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    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.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  5. #35
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    Argh... I hate posting incorrect information.

    This Line:
    Code:
    lshap = ["'Standard'","'Box'", "'Ball'","'Pyramid'","'Diamond'","'Ring'","'Grid'","'None'"]
    Should read:
    Code:
    lshap = ["'Standard'","'Box'", "'Ball'","'Pyramid'","'Diamond'","'Tetra'","'Ring'","'Grid'","'None'"]
    Apologies for any confusion.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

  6. #36
    Super Member Kryslin's Avatar
    Join Date
    Feb 2009
    Location
    Prescott, IA
    Posts
    1,653
    I have now discovered that it is possible to write code so objectionable to the LW Python system that it refuses to even load, let alone execute.
    --------
    My Scripts for Lightwave
    Intel Core i7 960 @3.20 Ghz, 24 GB ram, EVGA 6GB GTX980Ti "Classified" driving 2 x HP LA2405.

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •