Results 1 to 3 of 3

Thread: Random Particle/ Line Thickness Python script

  1. #1
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    50

    Random Particle/ Line Thickness Python script

    In the 'Lightwavers are Everywhere' facebook group Mark Warner asked for a specific way to randomly change the Particle/ Line Thickness value for all selected objects. Values should have a specific range defined by the user.

    Click image for larger version. 

Name:	Screen Shot 2017-03-06 at 01.43.09.png 
Views:	114 
Size:	30.2 KB 
ID:	136207 Click image for larger version. 

Name:	Screen Shot 2017-03-06 at 01.25.34.png 
Views:	104 
Size:	21.8 KB 
ID:	136204

    It is specific to his motion needs but you never know who else could find this useful later on.

    Click image for larger version. 

Name:	15109600_625350414324522_7935864706498231116_n.jpg 
Views:	112 
Size:	107.0 KB 
ID:	136205

    Mark Warner says:1x 2point poly chain with a bit of displacement. Radial Arrayed in Layout. Select all chains and run Ludwig's script. Texture using the Instance Info/Fixed Random into a gradient (fortunately they don't have to be instances!). Took about 5 mins where it would otherwise have taken much MUCH longer.

    Python File to use, edit or destroy. UI thanx to the cheat sheet @ justaddmilk.org and BAM it works.
    RandomThink.py.zip


    Code:
    #! /usr/bin/env python
    # -*- Mode: Python -*-
    # -*- coding: ascii -*-
    
    """
    Random value Particle/Line Thickness
    - Select one or more objects
    - Click the 'RndThick' Button
    - change min and max values to your liking
    - to cancel out press the 'Escape' button
    - to process script, press continue
    """
    
    __author__     = "LAG"
    __date__       = "5 march 2017"
    __copyright__  = ""
    __version__    = ""
    __maintainer__ = ""
    __email__      = ""
    __status__     = ""
    __lwver__      = "2015.3"
    
    # ------------------------------------------------------------------------------
    # Import Modules
    # ------------------------------------------------------------------------------
    import lwsdk
    import random
    
    class random_thickness(lwsdk.IGeneric):
        # Default min and max values to populate initial inputs when ui opens
        thicknessMin = 1
        thicknessMax = 1
        #initialize plugin
        def __init__(self, context):
            super(random_thickness, self).__init__()
        # Start process ----------------------------------
        def process(self, ca):
            ui = lwsdk.LWPanels()
            panel = ui.create("Random Thickness")
            #min value
            self.float_min_edit = panel.float_ctl("Min Float")
            self.float_min_edit.set_float(self.thicknessMin)
            self.float_min_edit.set_event(self.float_min_callback)
            #max value
            self.float_max_edit = panel.float_ctl("Max Float")
            self.float_max_edit.set_float(self.thicknessMax)
            self.float_max_edit.set_event(self.float_max_callback)
            # what to do when user cancels/ close ui panel
            if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_RESIZE) == 0:
                ui.destroy(panel)
                return lwsdk.AFUNC_OK
            # apply randomization to all selected objects
            self.user_selection()
            # close ui panel
            ui.destroy(panel)
            return lwsdk.AFUNC_OK
        # when user inputs value store this value in thickenssMin
        def float_min_callback(self, id, data):
            self.thicknessMin = self.float_min_edit.get_float()
        # when user inputs value store this value in thickenssMin
        def float_max_callback(self, id, data):
            self.thicknessMax = self.float_max_edit.get_float()
        # function to store current user selection and object ID
        def user_selection(self):
            UserSelection = lwsdk.LWInterfaceInfo().selected_items()
            UserSelectionID = []
            for item in UserSelection:
                UserSelectionID.append(lwsdk.itemid_to_str(item))
            # loop through each selected object and apply the random thickness code
            for i in range(0, len(UserSelection)):
                lwsdk.command("SelectItem " + str(UserSelectionID[i]))
                self.changeThickness()
            # reselect all objects
            for i in range(0, len(UserSelection)):
                if i == 0:
                    lwsdk.command("SelectItem " + UserSelectionID[i])
                else:
                    lwsdk.command("AddToSelection " + UserSelectionID[i])
        # randomize between user input values min and max
        def changeThickness(self):
            newValue = random.uniform(self.thicknessMin, self.thicknessMax)
            lwsdk.command("LineThickness " + str(newValue))
        # I have no idea what this is for
        # LWInstanceFuncs -------------------------------------
        def inst_descln(self):
            "You should never see this! If you do, run!"
    
    
    ServerTagInfo = [
                        ( "RndmThick", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
                        ( "RndmThick", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
                        ( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
                    ]
    
    ServerRecord = {lwsdk.GenericFactory("Random_Thicnkess", random_thickness): ServerTagInfo}

  2. #2

    Nnnnnice!  
    LW vidz   DPont donate   LightWiki   RHiggit   IKBooster   My vidz

  3. #3
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    50
    Thanks Erikals, nice feeling when I run an experimental code and it actually runs.

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
  •