Jump to content
Developer Wiki and Function Reference Links ×

Can a script change viewport class/layer visibilities?


Recommended Posts

I have a situation where I have various quite complex class/layer visibility setups.

 

Ideally I'd like to say: take the class and layer visibility in a specified saved view, and apply it to these (multiple) viewports.

(Or as a next-best option, take the class and layer visibility in a specified viewport, and apply it to these (multiple) viewports.

 

Is this, in principle, possible with a script?

 

At the moment I have to do this using the eyedropper tool to copy between viewports which is becoming rather tedious when I have a large number of viewports to update.

 

Also, a limitation of this method is that it can't do what saved view settings can do, which is to say don't change certain class visibilities.

Link to comment
7 minutes ago, Kars Keizer said:

 

Quite possibly!

 

I've not tried making a script before - my first question is whether what I want to do is possible in principle.

 

If so, then I'd have to work out whether it's worth me spending the time trying to write something from scratch.

  • Like 1
Link to comment

Yes it is very possible to do. I don't think you will be able to take the data from a Saved View as you can't access the view. You could use the view to set the visibilities and then use that to apply to the viewports, but then you lose the Don't Change ability.

 

As you can see, there are a number of us here who will be happy to help you get started with the script(s) necessary.

 

My guess is that to get a prototype working you will probably need 4-8 hours of time to learn the basics. You will need two to three times that to get everything completely debugged and working nicely if you want it to be more than just a simple menu command. With 30 years of programming VW, I would probably still need 2 hours to get a prototype running.

 

So is it worth that much time to you? Do you have any programming background at all? If you want to move forward, then the next question is do you want to do Vectorscript or Python. I think Vectorscript is easier for beginners as it requires explicit begin/end statements. While these are sometimes a pain to get right, they help make sure the code is actually doing what you want. Python will let you access far more things outside of VW, but if you don't care about that, I recommend Vectorscript.

 

The best way to move forward is to write a complete description of what you want the script to do. I.E. should it apply the settings to all VP? Or Selected VP? Or just Visible Selected VP? How do you want to specify the Layers/Classes to set visibilities for? Do you want separate scripts for Layers and Classes? How would you do this manually? If you can write down all of the little steps, it will be much easier to make sure you don't make design errors that will require lots of changes to the code later.

 

HTH.

  • Like 1
Link to comment

If you want to write the script using Python I can really recommand to read this document.
Really helped me getting started.
https://docs.python.org/3.8/tutorial/appetite.html

 

if you start making scripts, in Vectorscript or Python this will be your most important reference.

https://developer.vectorworks.net/index.php/VS:Function_Reference

 

For making your script you can use for example Eclipse. I use this program as it was recommended to me by Peter.

https://www.eclipse.org/

Link to comment
2 hours ago, Pat Stanford said:

Yes it is very possible to do. I don't think you will be able to take the data from a Saved View as you can't access the view. You could use the view to set the visibilities and then use that to apply to the viewports, but then you lose the Don't Change ability.

 

As you can see, there are a number of us here who will be happy to help you get started with the script(s) necessary.

 

My guess is that to get a prototype working you will probably need 4-8 hours of time to learn the basics. You will need two to three times that to get everything completely debugged and working nicely if you want it to be more than just a simple menu command. With 30 years of programming VW, I would probably still need 2 hours to get a prototype running.

 

So is it worth that much time to you? Do you have any programming background at all? If you want to move forward, then the next question is do you want to do Vectorscript or Python. I think Vectorscript is easier for beginners as it requires explicit begin/end statements. While these are sometimes a pain to get right, they help make sure the code is actually doing what you want. Python will let you access far more things outside of VW, but if you don't care about that, I recommend Vectorscript.

 

The best way to move forward is to write a complete description of what you want the script to do. I.E. should it apply the settings to all VP? Or Selected VP? Or just Visible Selected VP? How do you want to specify the Layers/Classes to set visibilities for? Do you want separate scripts for Layers and Classes? How would you do this manually? If you can write down all of the little steps, it will be much easier to make sure you don't make design errors that will require lots of changes to the code later.

 

HTH.

Thank you - this is really helpful.

 

My programming experience is mainly fiddling around with BASIC as a teenager. Sometimes I feel like some of what you need to do in Vectorworks is programming of a sort. But I would be pretty much a beginner at this.

 

It sounds a bit like the amount of time it would take me would not really match the time it would save me. If I could produce something in an afternoon it would be worthwhile... but from what you say, it would be more than that. I'll have a think about it nonetheless. One question for me is whether it would be useful beyond the project I have immediately in mind.

 

If there was some way to access the info in saved views including the "don't change" ability then that would make it significantly more attractive.

Edited by line-weight
Link to comment

@line-weight

 

As Pat mentioned, translating things from saved views is really difficult as VW basically treats saved views as scripts, so pulling info can be difficult.  As far as I know, there are no Vectorscript commands that will do the job.

 

As for the viewport visibility option, I wrote up a script to do exactly that for a friend of mine.  It opens a dialog box with a drop-down to select the viewport to copy, whether to copy layer settings, class settings, or both, and a list browser allowing you to select which viewports to copy the settings to.  It will copy visibility as well as class overrides.  I could not for the life of me get it to copy layer overrides, so if you need to do that, it would be best to use the eyedropper tool.

 

It was written in Vectorscript in VW2019 and I've loosely tested it in 2021 (it's not one of my main plug-ins and isn't one I use too often myself, so I haven't done a full feature-by-feature test).  It is attached to this message as "Copy Viewport Settings.vsm".  The install process is a bit convoluted if you haven't done it before.

  1. Download the .vsm file.
  2. In Vectorworks, go to your Vectorworks Preferences, select the User Folder tab, and click the button labeled "Explore" (on Windows) or "Open in Finder" (on Mac).
  3. Copy the downloaded .vsm file and paste it in the folder named "Plug-ins".
  4. Restart Vectorworks.
  5. In Vectorworks, open Tools-Workspaces-Edit Current Workspace.
  6. Select the Menus tab, and find the category labeled "JNC" in the left list box and expand it.
  7. Click and drag the Copy Viewport Settings menu command over to the target menu in the right list box.
  8. Click OK.  The menu command should now be in the designated menu.

Let me know if something breaks or if you have any questions.

 

The scripting itself isn't terribly complicated, but some of the components of the dialog box (IE, the List Browser) are terribly documented by VW and take a lot of trial and error to get right.  If you would like, I can share the source code but would rather not on the public forum.

 

- Jesse

 

image.thumb.png.816b48a31d18644e0b9ad26d052df0f9.png

Copy Viewport Settings.vsm

  • Like 2
Link to comment

@Jesse Cogswell thanks again for this - it does nearly exactly what I want it to, and I think it'll prompt a bit of a reorganisation of the drawing because it can allow me to do certain things in a less tedious way.

 

On an initial test, it seems to work perfectly.

 

It did give me an error when I first tried it in a blank drawing - presumably because it didn't expect to find zero viewports:

 

1674107603_ScreenShot2020-10-22at09_49_04.thumb.jpg.cddbf76079dc28e19ebda7e60e680236.jpg

 

But that doesn't matter.

 

In the dialogue box, I was hoping that DrawingTitle might allow me to sort by sheet layer name, but I guess it pulls from title blocks, not sheet layer names?

 

What could be really useful would be to have "saved sets" a bit like in the Publish command. So you can have a source viewport, which you update, then can quickly use to update a set of viewports which always share its visibilities.

Link to comment
7 hours ago, line-weight said:

What could be really useful would be to have "saved sets" a bit like in the Publish command. So you can have a source viewport, which you update, then can quickly use to update a set of viewports which always share its visibilities.

That sort of thinking is exactly why I said 4 hours to get a prototype and then 6 to 12 years to get a final script done!  ;-)

  • Like 2
Link to comment

@line-weight Good catch on the error if there are no viewports in the drawing.  The command will now throw a notification if no viewports are detected.

 

The dialog box will populate based on the viewport name (set in the Create Viewport dialog box, or edited in the "Name" field at the bottom of the Object Info Palette).  If you're as lax as I am about naming viewports, this can be a bit confusing.  The Drawing Title is not tied to Title Blocks, but is a separate field for all viewports in the Object Info Palette, which things like Drawing Label objects use when automatic drawing coordination is turned on.

 

I added an "On Layer" column and "Drawing #" column to the list browser to aid in helping distinguish which viewport is which.  The list browser will sort the viewports by layer, then drawing number automatically.

 

I also added an "Update Viewports" checkbox, checked on by default.

 

As for your idea of "presets" of visibilities similar to the publish command, it is certainly possible but that's getting into the point where I start billing you hourly.  Vectorscript doesn't really have a way of doing drawing specific resource files, so I would have to store each "preset" as a worksheet and code in Classes and Layers visibility menus from scratch.  It's certainly possible, but not really something I want to do on a tool I barely use without getting paid for it.

 

Anyhow, updated file is attached.  Just replace the file in the Plug-ins folder with this one and restart Vectorworks.

Copy Viewport Settings.vsm

Link to comment
1 hour ago, Jesse Cogswell said:

@line-weight Good catch on the error if there are no viewports in the drawing.  The command will now throw a notification if no viewports are detected.

 

The dialog box will populate based on the viewport name (set in the Create Viewport dialog box, or edited in the "Name" field at the bottom of the Object Info Palette).  If you're as lax as I am about naming viewports, this can be a bit confusing.  The Drawing Title is not tied to Title Blocks, but is a separate field for all viewports in the Object Info Palette, which things like Drawing Label objects use when automatic drawing coordination is turned on.

 

I added an "On Layer" column and "Drawing #" column to the list browser to aid in helping distinguish which viewport is which.  The list browser will sort the viewports by layer, then drawing number automatically.

 

I also added an "Update Viewports" checkbox, checked on by default.

 

As for your idea of "presets" of visibilities similar to the publish command, it is certainly possible but that's getting into the point where I start billing you hourly.  Vectorscript doesn't really have a way of doing drawing specific resource files, so I would have to store each "preset" as a worksheet and code in Classes and Layers visibility menus from scratch.  It's certainly possible, but not really something I want to do on a tool I barely use without getting paid for it.

 

Anyhow, updated file is attached.  Just replace the file in the Plug-ins folder with this one and restart Vectorworks.

Copy Viewport Settings.vsm 14.53 kB · 0 downloads

 

@Jesse Cogswell I wasn't actually expecting you to implement my requests! It's very kind of you to make those changes - both of which make this even more useful for me now.

 

Being able to sort things by "on layer" is very useful for the project I'm using this on (I have sheet layers set up with sets of multiple viewports, there are a lot of viewports and sorting by layer narrows things down).

 

I'm normally pretty lax about naming viewports but for this drawing, all the important ones are named, so that I can find them and so I know what they are when I export them, so the viewport name column is very useful too.

 

Totally understand that having presets would involve a load of extra coding work.

 

I have one observation - I'm not asking you to fix this, just mentioning in case it's of interest - this is when I choose the "update viewports" option which is a very useful addition which will save me quite a lot of clicks for various processes. When I use this to update multiple viewports, I notice that VW goes to the relevant sheet layer, it starts the first one rendering, then it seems to reload the whole sheet layer, start rendering the second one, reload the whole sheet layer, start rendering the third one, and so on.

 

This is different to what happens if I multiple-select several viewports and then update them in the normal manner - they all start re-rendering at the same time, which I think saves a bit of time. It doesn't really matter, because I'd just leave it to do its thing anyway, just thought I would mention.

 

Thanks again for this, an unexpectedly good outcome from my starting this thread.

Link to comment

@line-weight That's interesting.  When I run the command on 2019, it does not take me to a sheet layer (even if the command is run from a design layer) and renders the viewports one at a time. This is also consistent with selecting multiple viewports and pressing Update, VW does them one at a time for me.

 

I had originally placed the UpdateVP command in the same procedure as applying the visibility changes, but now gave the update process a dedicated procedure so that all of the viewports update at once to see if it cleans up the process for you.  Let me know if you see a change.

Copy Viewport Settings.vsm

Link to comment
  • 2 weeks later...
On 10/21/2020 at 7:13 PM, line-weight said:

 

Yes indeed ... although there is also the possibility that an investment of time doing something moderately engaging, to write a script say, is still worth it, if it avoids a smaller amount of time doing something incredibly tedious/frustrating.

 

Note that the eyedropper tool works on viewports with layer and class settings and is pretty immediate.

Link to comment

@SamIWas ,

@line-weight mentioned in the original post that they have been using the eyedropper tool to do this, but it becomes very tedious if you have a large number of viewports spread across multiple sheet layers, the tool I wrote and posted above allows you to do it all in one go, and has the ability to force the viewports to run an update as well.

 

@VectorGeek ,

The only thing that it does above and beyond the eyedropper tool is that it can apply to any number of viewports all at once.  If you're copying settings from one viewport to, let's say, 10 other viewports spread across multiple sheet layers, that can take a little time.  It also is a hair faster choosing between copying layer visibilities, class visibilities, or both since it's built into the dialog box, no need to open up the tool's settings menu and tick/untick a bunch of boxes.

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...