WhoCanDo Posted November 17, 2022 Share Posted November 17, 2022 I have customers that, annoyingly, send me jigsaw pieces of their product. I will re-draw these pieces on design layers and then create viewports of each piece so I can arrange them and fit them together to see what it looks like completed. Next I will add a class to each of the components for parts lists. The reason for the completed viewport view is so I can add classes in some sort of regular alpha-numeric flow (eg. left to right). However, after adding classes, it seems that the default for the viewport class list is "Invisible". I know that this visibility choice can be made by manually creating a new class, but can it be done in VS ? Quote Link to comment
Pat Stanford Posted November 17, 2022 Share Posted November 17, 2022 Yes, it could be done with a script, but you can also do it easily using the Organization Dialog Box. Choose the Viewports Pane and click the Visibilities button at the top right. You can then select the viewports you want and change the classes (and layers) that are visible in all of them at the same time. 1 Quote Link to comment
WhoCanDo Posted November 17, 2022 Author Share Posted November 17, 2022 Nice work-around Pat. However, adding classes, making mistakes, going back to fix them, doing the above multiple times, I'd rather put it in the macro that assigns the classes in the first place. How do you think this is achievable in a script? This doesn't work ForEachObject (ClassesVisible, (Sel = True), (T = Viewport)); Why wouldn't it be default "Visible" ? Who would want to draw something and then give it a class that is not visible on their Viewport? I thought the working flow should be draw-it, class-it, remove it from Viewport if not required. 1 Quote Link to comment
WhoCanDo Posted November 17, 2022 Author Share Posted November 17, 2022 And even if (T = Viewport) did work, you can GetCVis but you can't SetCVis. Quote Link to comment
Pat Stanford Posted November 17, 2022 Share Posted November 17, 2022 I will try to find some time later to give you a sample script. But the reasons to have classes NOT show up is just as valid. If you had a drawing set with a large number of viewports and then create (or import an object with a new class), would you really want that to show up in every viewport and then have to edit it out of all (or many) of them? Most people don't which is why the default is set to invisible in existing viewports. That way you know that you are not changing what you already have. 2 Quote Link to comment
Boh Posted November 17, 2022 Share Posted November 17, 2022 13 hours ago, WhoCanDo said: Why wouldn't it be default "Visible" ? Who would want to draw something and then give it a class that is not visible on their Viewport? I thought the working flow should be draw-it, class-it, remove it from Viewport if not required. This is actually what I do as when I check my drawings prior to issue I am more likely to notice something that is in my drawing but shouldn't be, rather than notice something that should be in my drawing but isn't. :-). 1 Quote Link to comment
WhoCanDo Posted November 17, 2022 Author Share Posted November 17, 2022 (edited) Interesting Boh, that's an interesting process. Thanks for that. Any ideas as to how to switch all classes on for all specifically named Viewports on all Sheet Layers in VS ? Looping through the layers and selecting the specific Viewports is the easy bit. Turning on the class visibility is the problem. Edited November 17, 2022 by WhoCanDo Spelling mistake Quote Link to comment
Pat Stanford Posted November 17, 2022 Share Posted November 17, 2022 This script will set the visibility of all classes in all viewports to visible. Change the criteria in the ForEachObject procedure if you only want to handle specific viewports. Procedure AllClassVisInVP; {November 17, 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.} {Sets all classes to visible in Viewports specified by the Criteria} {Specified in the ForEachObject PROCEDURE {To set classes to set other visibility statuses, use the following} {in the SetObjectVariable procedure.} { 0 = Visible} { -1 = Invisible} { 2 = Gray} VAR H1, H2 :Handle; S1, S2 :STRING; L1, L2 :LongInt; Procedure Execute(Hd1:Handle); BEGIN For L2 := 1 to L1 DO BEGIN SetObjectVariableInt(GetObject(Classlist(L2)),1018, 0); End; End; BEGIN L1:=ClassNum; ForEachObject(Execute,((T=VIEWPORT))); End; Run(AllClassVisInVP); Quote Link to comment
WhoCanDo Posted November 18, 2022 Author Share Posted November 18, 2022 Thanks for your time Pat. So it's SetObjectVariableInt that I was missing. Interestingly, when I searched through the Appendix (and tried a "Find" on the same pages) the other day, Viewport was not found. I can see today that the Appendix has change it's format so I'm not sure where I ended up. Even the Hyperlink that I used has been removed. Quote Link to comment
Pat Stanford Posted November 18, 2022 Share Posted November 18, 2022 There is an art to reading the Appendix. There are things that have changed names everywhere except the Appendix. Unless you know both names it is very hard to find what you want. For a long time Sheet Layers were referred to in the Appendix as Presentation Layers. Ask again when you get stuck. Quote Link to comment
WhoCanDo Posted November 18, 2022 Author Share Posted November 18, 2022 How did you know I would get stuck Pat? 😊 With the following, it turns on all classes for all viewports, selected or not "Class Visibility In All Viewports - 1018 - Integer - VS:SetObjectVariableInt" I just want Selected Viewports (if not named TB) to have all classes on. Selected Viewports are critical because if I have edited the class list for a specific Viewport then I won't select it for this script. procedure ClassOn; procedure Set_Class_On (h : handle); var i : integer; begin if (Pos ('TB', GetName (h)) > 0) then begin end else for i := 1 to ClassNum do SetObjectVariableInt (GetObject (ClassList (i)), 1018, 0); end; begin ForEachObject (Set_Class_On, ((Sel = True) & (T = Viewport))); end; run (ClassOn); Quote Link to comment
Pat Stanford Posted November 18, 2022 Share Posted November 18, 2022 We have all gotten stuck and continue to get stuck. Welcome to the Guild of VW scripters. We are happy to support each other. Pay it forward when you can. 👍 Your problem is that Criteria are case sensitive. Here is my version that appears to work, including some debugging code (N1 counter for how many objects selected by FOR Each Object, AlrtDialog for name of each object as it is handled, message of number of objects handled at end [including the date so you can see if the script actually ran and that you are not seeing the return from a previous run]). procedure ClassOn; Var N1:Integer; procedure Set_Class_On (h : handle); var i : integer; begin AlrtDialog(GetName(h)); if (Pos ('TB', GetName (h)) > 0) then begin end else for i := 1 to ClassNum do SetObjectVariableInt (GetObject (ClassList (i)), 1018, 0); N1:=N1+1; end; begin N1:=0; ForEachObject (Set_Class_On, (((T=VIEWPORT) & (SEL=TRUE)))); Message(Date(2,2),' ',N1); end; run (ClassOn); Quote Link to comment
Pat Stanford Posted November 19, 2022 Share Posted November 19, 2022 OK. My mistake in the previous version. The SetObjectVariableInt(1018) actually does EXACTLY what the definition in the Vectorscript Appendix says it does. "Class Visibility In All Viewports". It sets the visibility of the Class handle that you pass to it the same in EVERY viewport. What we really wanted was SetVPClassVisibility. You give it handle to the VP you want to change the visibility for, the name of the Class, and the visibility status you want. Since it is a Function, I had to define a Boolean variable to take the output of the function. Sorry about leading you down the wrong path. procedure ClassOn; Var N1:Integer; procedure Set_Class_On (h : handle); var i : integer; B1: boolean; begin AlrtDialog(GetName(h)); if (Pos ('TB', GetName (h)) > 0) then begin end else for i := 1 to ClassNum do B1:=SetVPClassVisibility(h, Classlist(i),0); N1:=N1+1; end; begin N1:=0; ForEachObject (Set_Class_On, (((T=VIEWPORT) & (SEL=TRUE)))); Message(Date(2,2),' ',N1); end; run (ClassOn); Quote Link to comment
WhoCanDo Posted November 19, 2022 Author Share Posted November 19, 2022 Perfect Pat, Thanks for you efforts an the coding tips. Quote Link to comment
Pat Stanford Posted November 19, 2022 Share Posted November 19, 2022 And one more coding tip. There are lots of things about Viewports in the Objects - Groups category of the VS Function Reference. Viewports have multiple "groups" (Annotations, Group, Crop Group, etc). Not the place most people think to look for information on Viewports. 1 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.