Changing workset visibility with single scrip

Ok so very new to dynamo but am exited to learn more about it, I work for a electrical contractor and do a lot of the modeling and detailing in Revit but I’m always into finding new shortcuts.

In my workflow I hide and unhind worksets tons of times throw out the day so I’ve been trying to create a script to either show or hind a particular workset, then using a add in to tie in to a hot key.

So far I was able to get a single script to either hide or show the workset so i made two scripts one to show and one to hind but I haven’t been able to get one script to do both which I’m guessing is possible

does anyone have any hints on how to make this work? like I mentioned I’m very new to this so any help would be appreciated

This is what i thought would work but it doesn’t seam to be, it will make the workset visible in this case but if I cant the true statement to hidden it will hide the workset.

It looks like you’re quite new to programming concepts (which is OK, but start simple if so!), suggest you spend some time with the Dynamo Primer. The If nodes don’t quite make sense in above example, the top one gives same result either way, and the second one isn’t driven by a boolean condition.

This is how you could do it. In the top option, you set the visibility from one of three options, and in the lower example you can set it to Visible or Hidden by string command (the dropdown for visibility just sends a piece of text out). The problem with an If node is you can only get one of two outcomes, but visibility has three possible settings.

script.dyn (29.6 KB)

One way to work around the three options without a dropdown is a list picker like this.

4 Likes

Ya I’m very new haha but hopefully once I start understanding the basics thing will start to make more sense to me. I started going through the dynamo primer and I have so much to learn haha.

This helps me alot and almost gets me to what I ultimately and trying to accomplish

So both of these options worked as long as I keep dynamo open and either change the true or false command or if I move the slider.

What I’m hoping is possible to do is tie this script to a hot key and without even opening dynamo I want it to run and do basically the opposite of what the visibly is set to. Or like you mentioned since there are 3 options even if the script would run next option each time its ran.

I would look into Dyno for this, but you would need to tune it to have a setting for every workset name so it doesn’t really scale well. This is the only platform of this type I know of that supports shortcut bindings to the scripts it turns into buttons (but there may be others).

Think about what happens when you press that button - how does Dynamo or any app for that matter know which workset you intend to impact, as well as how you want to impact them? A UI of some sort is needed in either case. Maybe a data shapes bulk show/hide script - but this is complex and you would get ahead of yourself here I think, work your way up to this over time via the Primer.

In the interim, I would suggest using Dynamo Player to package this script.

Ya I’ve been working my way through the primer each night haha, its helping and things are starting to make more and more sense.

I have the shortcut working with a addin called NonicaTab. It allows me to tie any script into a button and then to a hot key. However I have to have one script to turn on a workset and a different script to then turn off the workset. Which works but I was just thinking there should be a way for a single script to turn on or off a individual workset, even if I need a separate script for each workset.

Thank you for help so far though!

1 Like

As for shortcut keys - you can’t beat pyRevit. In my opinion, it is a must have for deploying Dyanmo. It can do what Nonica is doing for free and unlimited. (and more)

With that said, yes you can combine the two functions into one button. You just need to merge the two scripts into one file an then create a front end that determines the current workset visibility state.
A pretty simple if on then off and in off then on.
This would replace your incoming visibility options.

So as an outline:
Document.ActiveView > Current Workset Visibility > If 0 then return 1 else 0 > Visibility

I don’t know if there is a custom node to pull the current view’s workset visibility setting (I’d typically just code it in Python)

1 Like

Ill get that one out, Nonica was just the first one that popped up haha.

you gave me some great ideas and I think I’m very close and probably way over complicating this but hey its how you learn lol.

clearly I’m new to dynamo and but I’m even newer to python but ultimately that what I want to learn.

So this is what I can up with so far and it all seams to work beside the python scrip is not recognizing the string “Show” for some reason.

I tried making it (“Show”) and it clears the error but then the script always outputs the else command.

Other then that i think its all working. Any ideas to why python is not recognizing the input?

Ah yes I forgot PyRevit has shortcut bindings, thanks!

In that case, go down that path for sure - but be ready to do some research, there’s quite a bit to learn to produce tools in PyRevit, with a good payoff as reward.

@S.orchardR4UKW for your Python script, make sure Show is “Show”. It is a string. Again, I encourage you to learn the fundamentals before hitting Python, but up to you which pathway suits you best.

Here is two non-Python routes to form that statement also. Be sure to spend some time with design script and code blocks as they will give you a better understanding of Dynamo itself, whereas Python is more commonly used for Revit API functions and complex list functions (using loops).

image

It works!!!

Ya Ill look into PyRevit for sure, and I agree I’m not ready for python yet but ill get there some day.

Thank you guys for all the help!

Here is a finial shot of the script if anyone else searches for this.

1 Like

Don’t feel like you’re not necessarily ready for python, each person’s learning journey is different. Just make sure you cover the fundamentals early on - they will serve you well in your coding journey!

Dynamo easily integrates into pyRevit. Just use a MyProgram_scrpit.dyn instead of a MyProgram_script.py. The advantage of pyRevit is that designing a user interface is super easy and requires very little deployment and maintenance time in an office. The only disadvantage is that you lose the variable input controls in Dynamo player. But these can be replaced with more sophisticated UI tools with some python and pyRevit’s dialog box tools. Or you can just use DataShapes inside Dynamo (still using Dynamo script for the bulk of the lifting.)

Personally, I use Dynamo more as a development tool rather than final product. It is easy to knock some thing out that is part python and part dynamo to get a fast end result. In the end, I do try and convert everything to python because it simply runs faster. You don’t have the overhead of loading and unloading Dynamo. Also using just python - I don’t have to worry about deploying any custom nodes. And when I do make a hybrid py/dyn app - I make sure to not use any custom nodes. Again - it makes deployment foolproof.

2 Likes