SetObjectDisplayMode - all viewports


#1

Relating to this recent thread, this is something I have been meaning to script for myself for awhile, so this gave me an excuse to do it. The following two Python scripts set one or more objects to one of the display modes available - but in all viewports simultaneously. There are two versions - the first one will give you a listbox with all the display modes available and ask you to chose, the second is a “fixed” version where the display mode is hard-coded and thus represents a one-click solution.

In the second case you will need to edit the script to put in the name of the display mode you want to activate (I put in the most common ones, you can change which lines are commented out). Make sure that the display mode is actually present and that the localized name is spelled correctly.

Apologies to the Mac people, the listbox version will not run yet, if I have time I will create a command box string-based version later. Current version now both Mac and Windows compatible, please re-download…! (thanks to Jeff Hammond for testing)

As usual, please report any bugs/failures and/or computer meltdowns :wink:

–Mitch

SetObjDisplayModeAllViewports.py (1.7 KB)

SetSpecificObjDisplayModeAllViewports.py (1.4 KB)

Edit #1: assigning Technical display mode or a variation of it to an object does not seem to be working, so beware. I guess this is because Technical has its own display pipeline - I see it is excluded from the normal SetObjectDisplayMode command as well… I revised the script to exclude these as well.

Edit #2: having unleashed this potentially poisonous tool, I had better also supply the antidote - a tool to remove any special display modes from a set of objects in all viewports…

RemSpecificObjDisplayModeAllViewports.py (782 Bytes)


How this error is corrected, "Display Mode
Button for display style - command
#2

Thanks Mitch for the useful example, no meltdown, but please allow extrusion objects to be selected !

c.


#3

Hey Clement -

Extrusions seem to work here - I tested… Running SR8?

–Mitch


#4

Hi Mitch, i’ve not been aware that intType 1073741824 is explicitely required to pick extrusions, thanks :wink:

For the first script, i appreciate if it lets one choose idividual display modes but would suggest to get rid of Pen, Artistic and Technical as they do switch to Wireframe over here once applied (SR8).

To apply and remove SetObjectDisplayMode in all viewports should really make it into the built in command as an option.

c.


#5

rs.GetObjects includes extrusions as a part of type 8 or 16… There are other rs methods that don’t, though…

Done, re-download from above…

Script added until this is implemented as a real Rhino command, see above…

–Mitch


#6

thanks Mitch ! Now i understand how to use “PipelineLocked”.

c.


PY - SetdisplaymodeEX workaround
#7

Me too… I just figured it out by looking at what the different display modes had under that attribute… :smile:

–Mitch


#8

Hi Mitch!
Your script is great!
Can add to inside the script function to lock an object?
I would be very grateful if can implement this idea :blush:

SetSpecificObjDisplayModeAllViewports.py4


#9

Hi
I’m a little altered your script for locked objects.
SetSpecificObjDisplayModeAllViewportsAndLock.py (1.4 KB)

Based on your script, I want to assign a color in all viewports for all meshes.
attribute objIDs = rs.SelMesh () does not work
Help please, if it will not be so hard :slight_smile:
SetMesh.py (1.3 KB)


#10

To get all meshes in the file use:

all_meshes=rs.ObjectsByType(32)

To get only mesh objects that are visible and selectable, use

normal_meshes=rs.ObjectsByType(32,1)

HTH, --Mitch


#11

It really helped!
It works! Thanks :slight_smile:
How to combine two scripts into one python script?
Is this possible ??

The first script
RemSpecificObjDisplayModeAllViewportsAndUnlock.py (626 Bytes)

and second script
SetDisplaylUnlockMesesOnly.py (1.1 KB)
In the execution of this script TRUE for locked meshes.
How to get rid of?


#12

What code of Objects Type for unlocked meshes?

objIDs=rs.Unloced_meshes_only=rs.ObjectsByType (???)


#13

When mixing the order of function standard arguments with keyword arguments, keyword names need to be assigned. Otherwise python function will “arrange” them as if they were all standard, so in this case “1” will become “True” for “select” argument, and default value of “0” will be used for “state”.

[quote=Helvetosaur]To get only mesh objects that are visible and selectable, use

normal_meshes=rs.ObjectsByType(32,1)

[/quote]

# regular meshes (not hidden, not locked)
normal_meshes=rs.ObjectsByType(32,state=1)

#14

Thank you!
Its helped

Which function is responsible for Unlock selected objects?


#15

Smething like this?

objects = rs.SelectedObjects()
rs.UnlockObjects(objects())


#16

Dosnt works
Message: list is not callable


#17

You can use the ObjectsByType function to return locked objects id, and then unlock them:

# return the ids of locked meshes
objects = rs.ObjectsByType(32,state=2)
# unlock locked meshes
if len(objects)>0:
    un = rs.UnlockObjects(objects)
else:
    print "there are no locked meshes"

Check the ObjectsByType function help file for more info.


#18

How to write an identifier with such content ??

objects = rs.ObjectsByType (All unlocked objects except locked and unlocked meshes)


#19
import rhinoscriptsyntax as rs

# all locked and unlocked objects. Hidden excluded
allObjs = rs.ObjectsByType(0, state=0)
excludeMeshes = []
for obj in allObjs:
    if not rs.IsMesh(obj):
        excludeMeshes.append(obj)

If you want hidden objects included too, replace the upper line 4 with:

# all locked, unlocked and hidden objects
allObjs = rs.ObjectsByType(0, state=7)

#20

Thanks for all!
I got what I wanted to achieve.
I was able to eliminate the script for locked and hidden objects.
I also managed to unite two scripts into one.
The only thing that does not work simulate _UnlockSelected command in python and insert it into this modified script
Here is script After _UnlockSelected .py (1.8 KB)

Please help :wink: