Results 1 to 2 of 2

Thread: LW11 Python example: Select Connected Polygons in Modeler

  1. #1
    Red Mage Celshader's Avatar
    Join Date
    Feb 2003
    Location
    Burbank, California
    Posts
    1,817

    LW11 Python example: Select Connected Polygons in Modeler

    It took me a long time to figure this out, so I'm posting this LW11 Python code here in hopes of cutting down on someone else's learning curve.

    Usage: select a polygon on a mesh and run this script to execute a Select Connected operation on the polygons.

    Code:
    #! /usr/bin/env python
    # -*- Mode: Python -*-
    # -*- coding: ascii -*-
    
    import lwsdk
    
    __author__     = "Jennifer Hachigian"
    __date__       = "September 19, 2012"
    __copyright__  = ""
    __version__    = "1.0"
    __maintainer__ = "Jennifer Hachigian"
    __email__      = "[email protected]"
    __status__     = "Select Connected Example"
    __lwver__      = "11"
    
    class selectConnected(lwsdk.ICommandSequence):
        def __init__(self, context):
            super(selectConnected, self).__init__()
    
    
        # LWCommandSequence -----------------------------------
        def process(self, mod_command):    
        
            command = mod_command.lookup(mod_command.data, "SEL_POLYGON")
            cs_options = lwsdk.marshall_dynavalues(("SET", "CONNECT"))
            result = mod_command.execute(mod_command.data, command, cs_options, lwsdk.OPSEL_USER)
            
            return lwsdk.AFUNC_OK
    
    
    ServerTagInfo = [
                        ( "Python Select Connected", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
                        ( "Select Connected", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
                        ( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
                    ]
    
    ServerRecord = { lwsdk.CommandSequenceFactory("LW_PyRenameSurfaces", selectConnected) : ServerTagInfo }
    "mod_command.lookup" converts "SEL_POLYGON" into an integer that "mod_command.execute" understands as its second argument.

    "lwsdk.marshall_dynavalues" converts the tuple into a list of arguments that "mod_command.execute" understands as its third argument. "SET" means add to the existing selection; "CONNECT" works in conjunction with "SET." The opposite of "SET" ("select") is "CLEAR" ("deselect") -- and the C SDK indicates that "CLEAR" does not work with the "CONNECT" option.

    "mod_command.execute" executes the actual Select Connected command. The first argument is the mesh data. The second argument is the command, the third are the options, and the fourth is the mode. A "Select Connected" command must be executed in USER mode for it to work ("lwsdk.OPSEL_USER").

    LScript equivalent:

    Code:
    // LScript defines ...
    
    @script modeler
    @warnings
    @version 2.3
    @name "Select Connected Polygons"
    
    main{
        selmode(USER);					// scripts can't select data outside of USER mode
        selpolygon( SET, CONNECT );		// select connected
    }
    Jen's 3D -- LightWave stuff.
    Jen's 2D -- my comic book.

    Python is my smashing board. LightWave is my S.M.A.K.

  2. #2
    Kamehameha Chameleon BigHache's Avatar
    Join Date
    Sep 2006
    Location
    Future Past Life
    Posts
    1,894
    Awesome! Thanks for sharing.

Similar Threads

  1. Surface connected polygons
    By nickdigital in forum General Support
    Replies: 2
    Last Post: 03-05-2012, 03:13 PM
  2. Select connected on azerty
    By Mikewave in forum LW - Mac
    Replies: 3
    Last Post: 01-08-2010, 03:58 PM
  3. Automatic Select Connected (']')
    By Kuki in forum Plugin Developers Discussion
    Replies: 7
    Last Post: 08-22-2007, 07:59 PM
  4. Modeler tool to select AND select connected at once
    By Pavlov in forum LW - Feature Requests
    Replies: 0
    Last Post: 05-18-2006, 02:21 AM

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
  •