Christiaan Posted November 12, 2018 Share Posted November 12, 2018 (edited) Is it possible to have a script that executes the following logic: 1. If visibility of either "Design Layer-1" or "Class Name-1" is off, then toggle them both on 2. If visibility of both "Design Layer-1" and "Class Name-1" is on, then toggle them both off Edited November 12, 2018 by Christiaan Quote Link to comment
Pat Stanford Posted November 12, 2018 Share Posted November 12, 2018 Try this. Procedure Toggle; {If either layer or class specified in Consts is invisible, then sets} {both to visible. If both are visible then sets both to invsible.} {Change the LName and CName in the Const section to match your desired} {class and layer. Note code at bottom to cause proper screen and Nav} {palette updates.} {Warning: Use of this script may cause diziness. Alcohol may make this} {worse. Use care when operating a locamotive while using this script.} {If you are pregnant or considering becomeing pregnant, consult with } {CAD Manager before using this script. Self inflicted hair loss is a } {frequent side effect of learning to script. If script does not operate} {as intended, Do not pass GO, Do not collect $200. Use at your own risk.} {There be dragons. ARRRGH!} {November 12, 2018} {©2018 Patrick Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} Const LName='1-Slab'; CName='Structural-Slab'; Var LHand : Handle; LVis, CVis : Integer; Begin LHand:=GetLayerByName(LName); LVis:=GetObjectVariableInt(LHand, 153); CVis:=GetCVis(CName); If (LVis + CVis) = 0 then {If both layer & class visible} Begin SetObjectVariableInt(LHand, 153, -1); {Layer to invisible} ResetObject(LHand); HideClass(CName); {Class to invisibile} End Else Begin SetObjectVariableInt(LHand, 153, 0); {Layer to visible} ResetObject(LHand); ShowClass(CName); {Class to visible} End; RedrawAll; {For redraw to show hide objects with changed vis} Layer(GetLName(ActLayer)); {Force layer to active layer to update Nav Palette} End; Run(Toggle); 1 Quote Link to comment
Christiaan Posted November 12, 2018 Author Share Posted November 12, 2018 haha, warnings heeded, thanks Pat. Couple of things: 1. Any idea why it checks out (and modifies) the design layer in a Project Sharing file, and how to stop it? 2. How do I stop this VectorScript message appearing? Quote Link to comment
Pat Stanford Posted November 12, 2018 Share Posted November 12, 2018 (edited) I have no idea why it effects project sharing. I have never used the project sharing. My guess is that it is the last line of the script Layer(GetLName(ActLayer)); {Force layer to active layer to update Nav Palette} This sets the active layer to the active layer to force a redraw of the Nav Palette. Try moving the left brace "{" to the beginning of the line to comment it out and see if that fixes the project sharing issue. As for the Message block, just delete the line that reads MEssage(DAte(2,2), LVis); This was for debugging and I missed removing it. (I have edited the script above to remove this. You could just grab it from there again instead.) Edited November 12, 2018 by Pat Stanford Update on editing earlier script Quote Link to comment
Christiaan Posted November 12, 2018 Author Share Posted November 12, 2018 (edited) 7 minutes ago, Pat Stanford said: Try moving the left brace "{" to the beginning of the line to comment it out and see if that fixes the project sharing issue. That didn't work Pat. Curious. Edited November 12, 2018 by Christiaan Quote Link to comment
Pat Stanford Posted November 12, 2018 Share Posted November 12, 2018 Then it must be the changing of the visibility requires project sharing access. I don't think there is anything I can do about that as the script does not specifically ask for access. It does not seem to me (with zero experience in project sharing) that you should need to own the layer to change the visibility. Quote Link to comment
Christiaan Posted November 12, 2018 Author Share Posted November 12, 2018 16 minutes ago, Pat Stanford said: It does not seem to me ... that you should need to own the layer to change the visibility. That's correct, you don't. It must be something peculiar about the VS command and PS. Quote Link to comment
twk Posted November 12, 2018 Share Posted November 12, 2018 Its to do with the SetObjectVariableInt(LHand, 153, -1); {Layer to invisible}; you're actually applying the change to the whole layer (LHand). What I've done in the past is to use the ShowLayer, HideLayer, GrayLayer calls. So your script would be instead: Begin {SetObjectVariableInt(LHand, 153, -1); {Layer to invisible}} Layer(GetLName(LHand)); {Jump to that particular layer} HideLayer; HideClass(CName); {Class to invisibile} End 1 Quote Link to comment
twk Posted November 12, 2018 Share Posted November 12, 2018 (edited) Here it is in python: # November 13, 2018 # Python converted from Patrick Stanford's script: # https://forum.vectorworks.net/index.php?/topic/59673-script-to-toggle-class-layer-on-and-off/&do=findComment&comment=297904 import vs LName = '1-Slab' CName = 'Structural-Slab' LayerHandle = vs.GetLayerByName(LName) LayerVisibility = vs.GetObjectVariableInt(LayerHandle, 153) ClassVisibility = vs.GetCVis(CName) CurrentLayer_Name = vs.GetLayerByName(vs.ActLayer()) if any([LayerVisibility == 0, ClassVisibility == 0]): vs.Layer(LName) # Jump to/Set Active layer name in LName variable vs.HideLayer() vs.HideClass(CName) else: vs.Layer(LName) # Jump to/Set Active layer name in LName variable vs.ShowLayer() vs.ShowClass(CName) vs.Layer(CurrentLayer_Name) # Jump Back to/Set Active current layer name Edited November 12, 2018 by twk 1 Quote Link to comment
Christiaan Posted November 13, 2018 Author Share Posted November 13, 2018 (edited) Awesome, cheers for that. Does the trick but it also gives the following errors and it's creates a new design layer each time. Edited November 13, 2018 by Christiaan Quote Link to comment
twk Posted November 13, 2018 Share Posted November 13, 2018 Woah!. apologies, i had edited that post.. strange the edit didnt go through.. the currentLayer_name call is incorrect it should be this: # November 13, 2018 # Python converted from Patrick Stanford's script: # https://forum.vectorworks.net/index.php?/topic/59673-script-to-toggle-class-layer-on-and-off/&do=findComment&comment=297904 import vs LName = '1-Slab' CName = 'Structural-Slab' LayerHandle = vs.GetLayerByName(LName) LayerVisibility = vs.GetObjectVariableInt(LayerHandle, 153) ClassVisibility = vs.GetCVis(CName) CurrentLayer_Name = vs.GetLName(vs.ActLayer())#Get Layer Name of current/active layer if any([LayerVisibility == 0, ClassVisibility == 0]): vs.Layer(LName) # Jump to/Set Active layer name in LName variable vs.HideLayer() vs.HideClass(CName) else: vs.Layer(LName) # Jump to/Set Active layer name in LName variable vs.ShowLayer() vs.ShowClass(CName) vs.Layer(CurrentLayer_Name) # Jump Back to/Set Active current layer name 1 Quote Link to comment
Pat Stanford Posted November 14, 2018 Share Posted November 14, 2018 Thanks @twk I was being lazy and hoped to not have to switch the active layer to be able to use the Show/Hide/GrayLayer options. Good catch, but I am a little surprised that the Show/Hide/Grey don't do exactly the same as the pref does under the hood. Quote Link to comment
Christiaan Posted November 14, 2018 Author Share Posted November 14, 2018 Getting this error now: Quote Link to comment
twk Posted November 14, 2018 Share Posted November 14, 2018 (edited) theres something weird going on with the formatting, and my posts on this thread; It looks like their are hidden spaces being added between the s and ( in vs.GetCVis(CName)) ClassVisibility = vs.GetCVis(CName) if you copy in the code above, or type it in manually it should work. (Replace this line in the script, with your manually typed one, or the snippet above) Edited November 14, 2018 by twk 1 Quote Link to comment
Christiaan Posted November 14, 2018 Author Share Posted November 14, 2018 Yay! It's working. Thanks guys 🙂 Quote Link to comment
Tom W. Posted February 2, 2022 Share Posted February 2, 2022 Could one of you guys help? I want to add a 'Show/Hide NonPlot' menu command to my Document Context menu (right-click) or keyboard shortcut. Can I do this by modifying @twk's last script above by removing the LName = '1-Slab' line + changing the class line to CName = 'NonPlot', then using the 'Vectorscript Plug-in Manager...' command to create a VS Menu command plug-in...? Or will this not work because it's Python...? Sorry I am utterly ignorant of these things! I just want a quick + easy way to turn the 'NonPlot' class on + off on the design layer whilst modelling. I have millions of Loci bound up in symbols: I want to see them when placing the symbol but not afterwards. And it's a pain finding NonPlot in the Navigation palette each time. Am not confident ploughing into this without someone pointing the way! Thanks Quote Link to comment
danm01 Posted February 2, 2022 Share Posted February 2, 2022 @Tom W. it's super easy if you are willing to have 2 different scripts rather than toggle visibility. I use this method all the time. "Show" script - ShowClass('NonPlot'); "Hide" script - HideClass('NonPlot'); You can create plug-ins with these simple scripts and give yourself menu items. If you have more than one class to show/hide at a time ("NonPlot-Loci" for instance), you can add additional lines to the script. Make sure to use the semicolon at the end of each line. 2 Quote Link to comment
Tom W. Posted February 2, 2022 Share Posted February 2, 2022 @danm01 thank you I'm 100% willing to have two separate scripts! Wow I had no idea it would be so straightforward. That's very cool. Quote Link to comment
Pat Stanford Posted February 2, 2022 Share Posted February 2, 2022 Or you can use a single line that will toggle between Visible and Invisible and have the added benefit of making a class that is Grey first visible then being able to toggle it. If GetCVis('NonPlot')=0 then HideClass('NonPlot') else ShowClass('NonPlot'); Go to Tools:Plugins:Plugin Manager Click the New button Make a Command type PIO and click the OK button Click the Edit Script button and paste the above into the editor window. Click OK Click Close Edit your workspace Find Document Context in the right windows. Find the new PIO you created in the left window. Probably under Miscelaneous. Drag it to the right window. Click OK to save and reload the workspace. HTH. Ask again if you need more information. 2 Quote Link to comment
Boh Posted February 2, 2022 Share Posted February 2, 2022 I actually understand this! I also find having to return to the nav palette to turn classes off a pain and typically before we export a file we like to turn off all the "NonPlot" classes. It would be nice to have one button that does it all. I have a whole bunch of classes with "NonPlot" in the class name. Is it possible to have one script that will toggle them all off if any of them are on but turn them all on if they are all off. Also if I create a new class with "NonPlot" in the name can it also work on this class without changing the script? Quote Link to comment
Pat Stanford Posted February 3, 2022 Share Posted February 3, 2022 It gets more complicated to handle multiple classes. This example toggles each class whose name contains 'NonPlot' in the file. Each class is toggled individually, so if you want them to all react the same, they all need to be in the same state to begin. It gets even more complicated if you want to get only classes that begin or end with a given string. Set the portion of the name you want to match between the single quote marks in the CONST CString='NonPlot'; line. Only change what is between the quotes. Procedure ToggleMultiClasses; {February 2, 2022} {©2022 Patrick Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {No Warranty Expressed of Implied. Use at your own risk.} {Toggles the class visibility of each class whose name contains the} {string defined in the constant CString below.} {Each class is toggles individually, so if you want all classes} {to be turned off, they all must be the same before running the toggle.} CONST CString='NonPlot'; VAR L1, L2:LongInt; S1:String; BEGIN L1:=ClassNum; For L2:= 1 to L1 DO BEGIN S1:=ClassList(L2); If Pos(CString, S1)<>0 then If GetCVis(S1)=0 then HideClass(S1) else ShowClass(S1); End; End; Run(ToggleMultiClasses); 1 Quote Link to comment
Tom W. Posted February 3, 2022 Share Posted February 3, 2022 11 hours ago, Pat Stanford said: Or you can use a single line that will toggle between Visible and Invisible and have the added benefit of making a class that is Grey first visible then being able to toggle it. If GetCVis('NonPlot')=0 then HideClass('NonPlot') else ShowClass('NonPlot'); Go to Tools:Plugins:Plugin Manager Click the New button Make a Command type PIO and click the OK button Click the Edit Script button and paste the above into the editor window. Click OK Click Close Edit your workspace Find Document Context in the right windows. Find the new PIO you created in the left window. Probably under Miscelaneous. Drag it to the right window. Click OK to save and reload the workspace. HTH. Ask again if you need more information. Thanks so much Pat but I've tried it + it's not working...? I followed exactly the same process of creating a Plug-in Menu command + assigning it to my right mouse click as I did with the ShowClass('NonPlot'); and HideClass('NonPlot'); scripts but whilst they work your one doesn't... Does it work at your end? Thanks! What does If GetCVis('NonPlot')=0 mean in layman's terms? Quote Link to comment
Boh Posted February 3, 2022 Share Posted February 3, 2022 7 minutes ago, Tom W. said: If GetCVis('NonPlot')=0 “If class visibility of Nonplot class is visible”?? 1 Quote Link to comment
Tom W. Posted February 3, 2022 Share Posted February 3, 2022 Aha ok thank you @Boh. Any chance you're able to test it at your end? Quote Link to comment
Pat Stanford Posted February 3, 2022 Share Posted February 3, 2022 @Tom W.Four things to check as the troubleshooting. 1. Is your class name exactly 'NonPlot'? No space at the end. No underscore or dash between. 2. Rather than as a PIO just go to the resource manager and create a new script. Paste the single line script into there and run it. Does it work? 3. When you pasted the script into the PIO script edit window at the top was a pull down to choose Vectorscript or Python. The code I sent is Vectorscript. 4. Can you send me a blank file with your classes in it so I can test here? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.