Hi.

Welcome to my blog. I document my adventures in travel, style, and food. Hope you have a nice stay!

Tips for Modo Kit / Script Developpers - # 1

Tips for Modo Kit / Script Developpers - # 1

Hi everyone,

I wanted to engrave this in the marble, in order to store this valuable information. I hope this helps


Check Modo Preferences State to avoid bug on different user

I've notice that even if my scripts works well on my end, sometimes (to not say often) people doesn't use the same preferences than yours.

A basic case is when you're using Copy / Paste command in your Python script:

lx.eval('copy')
lx.eval('paste')

If you're aware of and have enough experience, you know already that you can get many different combination of behavior via the Modo / Preferences / Defaults / Mesh Items. thoses are set via boolean (true or false)

  • Deselect Elements after Copying

  • Select Pasted Elements

  • Deselect Elements Before Pasting

I have all those 3 Enable by default.
All the Macro 's and Scripts that i've made the past 10 years are impacted by those settings.
So it's important to set the same preferences before running a script i made on a different machine.


So down below i have put some checks procedure in 2 parts: One at the Start and one at the End of the script. The code is probably not Fine and Well done from an optimization perspective, but it does the job. Feel free to share an optimized one.


I hope this will help you sort things up.
I will probably add more tips like this in this thread.
Share yours
here.

Best regards, Franck.


1st part:
Checking current state, and see if it's needed to get changed.

###############COPY/PASTE Check Procedure#################
## create variables
lx.eval("user.defNew name:User_Pref_CopyDeselectChangedState type:boolean life:momentary")
lx.eval("user.defNew name:User_Pref_PasteSelectionChangedState type:boolean life:momentary")
lx.eval("user.defNew name:User_Pref_PasteDeselectChangedState type:boolean life:momentary")

lx.eval("user.defNew name:User_Pref_CopyDeselect type:boolean life:momentary")
lx.eval("user.defNew name:User_Pref_PasteSelection type:boolean life:momentary")
lx.eval("user.defNew name:User_Pref_PasteDeselect type:boolean life:momentary")
###################

# Look at current Copy / Paste user Preferences:
User_Pref_CopyDeselect = lx.eval('pref.value application.copyDeSelection ?')
lx.out('User Pref: Deselect Elements after Copying', User_Pref_CopyDeselect)
User_Pref_PasteSelection = lx.eval('pref.value application.pasteSelection ?')
lx.out('User Pref: Select Pasted Elements', User_Pref_PasteSelection)
User_Pref_PasteDeselect = lx.eval('pref.value application.pasteDeSelection ?')
lx.out('User Pref: Deselect Elements Before Pasting', User_Pref_PasteDeselect)
# Is Copy Deselect False ?
if User_Pref_CopyDeselect == 0:
    lx.eval('pref.value application.copyDeSelection true')
    User_Pref_CopyDeselectChangedState = 1
    
# Is Paste Selection False ?
if User_Pref_PasteSelection == 0:
    lx.eval('pref.value application.pasteSelection true')
    User_Pref_PasteSelectionChangedState = 1
    
# Is Paste Deselect False ?
if User_Pref_PasteDeselect == 0:
    lx.eval('pref.value application.pasteDeSelection true')
    User_Pref_PasteDeselectChangedState = 1
    
# Is Copy Deselect True ?
if User_Pref_CopyDeselect == 1:
    User_Pref_CopyDeselectChangedState = 0
    
# Is Paste Selection True ?
if User_Pref_PasteSelection == 1:
    User_Pref_PasteSelectionChangedState = 0
    
# Is Paste Deselect True ?
if User_Pref_PasteDeselect == 1:
    User_Pref_PasteDeselectChangedState = 0
################################################

2nd part:
At the end of your script put this to Restore the value in case of changed state:

###############COPY/PASTE END Procedure#################
# Restore user Preferences:
if User_Pref_CopyDeselectChangedState == 1 :
    lx.eval('pref.value application.copyDeSelection false')
    lx.out('"Deselect Elements after Copying" have been Restored')
if User_Pref_PasteSelectionChangedState == 1 :
    lx.eval('pref.value application.pasteSelection false')
    lx.out('"Select Pasted Elements" have been Restored')
if User_Pref_PasteDeselectChangedState == 1 :
    lx.eval('pref.value application.pasteDeSelection false')
    lx.out('"Deselect Elements Before Pasting" have been Restored')
########################################################
MODO | Sharpen Curve Corners

MODO | Sharpen Curve Corners

Hidden Gems

Hidden Gems