MoI discussion forum
MoI discussion forum

Full Version: Scripting Object Visibility?

Show messages:  1-20  21

From: FDP
22 Jul   [#1]
How could I go about making a quick script to allow a user to add individual objects to a visibility list and then toggle that list on and off? My projects tend to be dozens of objects in size and I'd like to be able to select different elements with their already assigned colors, names, etc. and then turn their visibility on and off with a single click or hotkey.

I have tried Groups and have had a great deal of difficulty with Groups working efficiently - they tend to bog down the system, cause minor freezes, and generally muck up object selection when I want to pull a single element from a group and move it or copy it. In the long term Groups are probably a workable solution to my needs, but this script would still be useful for turning visibility on and off for multiple groups or elements of groups.

Thanks,
FDP
From: Michael Gibson
22 Jul   [#2] In reply to [#1]
Hi FDP, probably the simplest way to do that is to assign the objects you want on a "visibility list" to all have the same name.

That name will then appear as an entry in the "objects" section of the scene browser and you can turn it visible/hidden with one click there.

If you want a hierarchical arrangement then groups would be how to do that. If you are having problems with groups can you send me some example files?

Maybe there is something I can fix or some tips that might help you. Like for example if you want to target one element nested inside of a group you can hold down the Ctrl key while clicking on an unselected object inside of a group and it will select that object by itself immediately instead of going into the group hierarchy.

- Michael
From: Michael Gibson
22 Jul   [#3] In reply to [#1]
For a script like you describe I'm not quite understanding how that would be different than assigning the same name to the objects you want to turn on/off together.

Is it that you want to do it without using the object's name? What are you doing with the name then?

Do you want to have multiple "visibility lists" or just a single global one?

Because having multiple visibility lists that you can turn on/off just sounds like redoing what the scene browser does already... ?

- Michael
From: shayno
22 Jul   [#4]
Hi Michael
Is it possible to write a script to assign to a key say f5 f6 f7 etc that hides / unhides a colour from the styles colours ?
so with one keystroke they are hidden or shown
rather than mouse the command
cheers
shayne
From: Michael Gibson
22 Jul   [#5] In reply to [#4]
Hi shayne,

re:
> Is it possible to write a script to assign to a key say f5 f6 f7 etc that hides / unhides
> a colour from the styles colours ?

Yes, try this:

script: /* Toggle visibility on given style */ var style_name = 'Blue'; var item = moi.ui.sceneBrowser.styles.find( style_name ); if ( item.hasStatusHiddenUnlocked || item.hasStatusHiddenLocked ) { item.alterStatus( 'show' ); } else { item.alterStatus( 'hide' ); }

- Michael
From: shayno
23 Jul   [#6]
Hi Michael
it works to hide the colour but not to unhide it if pressed again

cheers
shayne
From: Michael Gibson
23 Jul   [#7] In reply to [#6]
Hi shayne, the unhide is working ok for me over here running in the v5 beta.

What version of MOI are you using?

- Michael
From: Michael Gibson
23 Jul   [#8] In reply to [#6]
Hi shayne, for v5 there was more stuff added for scripting the scene browser that makes it more convenient to write this script.

For v4 it's still possible just not as convenient, try this one for v4:

script: /* Toggle visibility on given style */ var style_name = 'Blue'; var item = moi.ui.sceneBrowser.styles.find( style_name ); var style = moi.geometryDatabase.findStyle( style_name ); if ( style ) { var style_index = style.index; var any_hidden = false; var objs = moi.geometryDatabase.getObjects(); for ( var i = 0; i < objs.length && !any_hidden; ++i ) { var obj = objs.item( i ); if ( obj.styleIndex == style_index && obj.hidden ) { any_hidden = true; } var subobjs = obj.getSubObjects(); for ( var j = 0; j < subobjs.length && !any_hidden; ++j ) { var subobj = subobjs.item(j); if ( subobj.styleIndex == style_index && subobj.hidden ) { any_hidden = true; } } } } if ( any_hidden ) { item.alterStatus( 'show' ); } else { item.alterStatus( 'hide' ); }

- Michael
From: shayno
23 Jul   [#9]
Sorry Michael
V4 , I am very imbedded with
I will upgrade to V5 when its complete

cheers
shayne
From: shayno
23 Jul   [#10]
That works perfectly thanks
I just need some extra keys on my keyboard as I am not using all letters, ctrl+ most letters, Alt+Most letters, and Shft+ most letters and F1-F12
This
Thanks
From: FDP
24 Jul   [#11] In reply to [#2]
Thanks Michael,

Ideally I would like to be able to have a random collection of objects that can be added/removed from a visibility group without impacting Object Grouping or naming. This might make more sense if I explain my current naming and my ideal (Groups working more reliably) naming:

For my example I will imagine a theoretical design project for a guitar capo. I would organize it now as follows:

Capo Static Curves <- Curves/Drawing
Capo Static Construction <- Solid Geometry for CSG
Capo Static Solids <- Finished Solids
Capo Static M3 x 8mm Pivot Pin Supplier ID#XXXXXXX <- Parts as assembly name then part name then manufacturer ID
Capo Static Spring 1mm Supplier ID#XXXXXXX
Capo Hinged Curves
Capo Hinged Construction
Capo Hinged Solids

If groups worked better I would ideally label as follows:
Capo Static (Group)
-> Curves
-> Construction
-> Solids
-> M3 x 8mm Pivot Pin Supplier ID#XXXXXXX
-> Spring 1mm Supplier ID#XXXXXXX

Capo Hinged (Group)
-> Curves
-> Construction
-> Solids

My projects usually have dozens of individual named objects and the scenario I find myself in all the time is needing to see how say, the M3 Pivot Pin and Spring interact with the Capo Hinged Group items. Right now this involves hunting around and toggling visibility for many items on and off. I would LOVE a hotkey for named groups to toggle them on and off.

The control key is a great tip, thank you! The large issues I have with groups are:

1.) Accidentally copying a group when I want to copy one object in the group. If the group is large enough (I have some 800MB projects with a hundred or more objects) this can cause the UI to stutter.
2.) Groups causing UI stuttering just by existing in a project.
3.) This is an issue with the latest beta and not only a group problem, but some sub-objects randomly turning their visibility on and off during project loading. It seems like visibility state is not saving correctly when projects are saved and then loaded. This is a V5 Beta issue.

As always, thank you so much for your help and for MoI!
Kind Regards,
FDP
From: Michael Gibson
24 Jul   [#12] In reply to [#11]
Hi FDP, thanks for the information. But it's pretty difficult for me to fully understand what you're seeing without having specific examples.

Can you please post example 3DM models for each of the situations that you describe?

For example, you wrote:

> My projects usually have dozens of individual named objects and the scenario
> I find myself in all the time is needing to see how say, the M3 Pivot Pin and Spring
> interact with the Capo Hinged Group items.

You say how the objects "interact" - do you mean you want to know if these objects touch each other?

Can you please post a 3DM model file (or e-mail to me at moi@moi3d.com) with the "M3 Pivot Pin and Spring" and "Capo Hinged Group items" so that I can try to repeat what you are doing over here and try to gain better understanding?


> 1.) Accidentally copying a group when I want to copy one object in the group. If the group is large enough
> (I have some 800MB projects with a hundred or more objects) this can cause the UI to stutter.

Can you please send a 3DM file where you are getting the stutter when accidentally copying a group?

For files larger than 10MB you'll need to use a sharing surface like WeTransfer, DropBox, OneDrive.


> 2.) Groups causing UI stuttering just by existing in a project.

Can you send the project file where you're seeing the UI behaving differently with a particular group existing versus with it removed?


> 3.) This is an issue with the latest beta and not only a group problem, but some sub-objects
> randomly turning their visibility on and off during project loading. It seems like visibility state
> is not saving correctly when projects are saved and then loaded. This is a V5 Beta issue.

There was a v5 bug that was preventing shaded surfaces from being shown on an object that started out hidden in the initial file load. It would end up looking like a wireframe display with only the edge curves showing on a solid and not shaded faces.

That should be fixed in the current v5 beta though. If you have any cases where visibility state is not saving correctly in the current v5 beta please send me the model files so I can reproduce the problem and then try to fix it.


Thanks,
- Michael
From: shayno
5 Aug   [#13]
Hi Michael
The one key hide unhide script is magic thanks
another on my wishlist is to select all objects of a colour (say gold) and run _cvolume 10 on it, copying the volume cm3 to the clipboard
is this possible please for moi ver4

I am always doing this for gold colour

cheers
shayne
From: Michael Gibson
5 Aug   [#14] In reply to [#13]
Hi shayne,

re:
> another on my wishlist is to select all objects of a colour (say gold) and run _cvolume 10 on
> it, copying the volume cm3 to the clipboard

It would be easiest to do this by making a customized modified version of the _cvolume script.

Please attach the _cvolume .htm and .js files that you currently use and I'll show you what to modify to do those things.

- Michael
From: shayno
5 Aug   [#15] In reply to [#14]
Thanks Michael
uploaded both
cheers Shayne

Attachments:
_CVolume.htm
_CVolume.js


From: Michael Gibson
6 Aug   [#16] In reply to [#15]
Hi Shayne, try this version - instead of using selected objects it will use whatever solids are on style = gold whether selected or not.

And copies volume value to the clipboard.

- Michael

Attachments:
_CVolumeGold.htm
_CVolumeGold.js


From: shayno
10 Aug   [#17]
Thanks Michael
works perfectly
and I changed my old _CVolume.htm to also copy to the clipboard

cheers
shayne
From: shayno
12 Aug   [#18]
Hi Michael
Similar to hide unhide by style
Is it possible to write script to hide / unhide by object name say 'old'
As I cad new rings next to old designs I constantly have to hide/unhide the old one to clear the screen
Moi Ver 4
kind regards
shayne
From: Michael Gibson
12 Aug   [#19] In reply to [#18]
Hi shayne,

re:
> Similar to hide unhide by style
> Is it possible to write script to hide / unhide by object name say 'old'

Try this one:

script: /* Toggle visibility of given name */ var name = 'old'; var item = moi.ui.sceneBrowser.objects.find( name ); if ( item ) { var any_hidden = false; var objs = moi.geometryDatabase.getObjects(); for ( var i = 0; i < objs.length && !any_hidden; ++i ) { var obj = objs.item( i ); if ( obj.name == name && obj.hidden ) { any_hidden = true; } var subobjs = obj.getSubObjects(); for ( var j = 0; j < subobjs.length && !any_hidden; ++j ) { var subobj = subobjs.item(j); if ( subobj.name == name && subobj.hidden ) { any_hidden = true; } } } } if ( any_hidden ) { item.alterStatus( 'show' ); } else { item.alterStatus( 'hide' ); }

- Michael
From: shayno
12 Aug   [#20]
Thanks Michael
I demonstrated and recommended your software to a business associate yesterday , I'm certain he will purchase it.
kind regards
shayne

Show messages:  1-20  21