markdd Posted January 5, 2018 Share Posted January 5, 2018 I would like to create a worksheet of all the Viewports in my drawing and most specifically what scale they are. Available criteria for viewports are limited. Is there a worksheet function I could use to achieve this? Many thanks. Mark Quote Link to comment
Pat Stanford Posted January 6, 2018 Share Posted January 6, 2018 This can only be done using a Worksheet Script. I can provide the script. Are you up for a bit of a learning curve on how to use it? Quote Link to comment
markdd Posted January 6, 2018 Author Share Posted January 6, 2018 (edited) Yes please! Always looking to find new ways to customise Vectorworks. Edited January 6, 2018 by markdd Quote Link to comment
Pat Stanford Posted January 9, 2018 Share Posted January 9, 2018 OK, here you go. There are two scripts attached. One that returns the scale as a real number, the other that returns it as a string showing as "1:Scale". If you save these scripts into your file (any script palette will do), then you can call them in a worksheet by using a function of "=RunScript('ScriptName')". Where the script name is replaced by the name you are showing in the script palette. Copy everything in the code blocks below. You can name the scripts anything you want, but I named them "Get_VP_Scale" and "Get_VP_Scale_Text". If you want to be able to use these across multiple files without having to have the script in each file, create a new VW file that contains the script(s) and save it in the Defaults folder for Reports and Schedules. /Users/Your User Name/Library/Application Support/VectorWorks/2017/Libraries/Defaults/Reports_Schedules. Then modify the function in the worksheet to "=RunScript(120,'ScriptName') If you need a different format, the scripts can be embellished as necessary to do other processing of the numbers/text to get the output you want. Procedure Get_VP_Scale; Var H1:Handle; R1:Real; Begin H1:=WSScript_GetObject; R1:=GetObjectVariableReal(H1,1003); WSScript_SetResReal(R1); End; Run(Get_VP_Scale); Procedure Get_VP_Scale_Text; Var H1,H2:Handle; N1:Integer; R1:Real; S1:String; Begin H1:=WSScript_GetObject; R1:=GetObjectVariableReal(H1,1003); WSScript_SetResStr(Concat('1:',R1)); End; Run(Get_VP_Scale_Text); Quote Link to comment
markdd Posted January 9, 2018 Author Share Posted January 9, 2018 Many thanks Pat. I'm very grateful. I'll report back with how I get on. Mark Quote Link to comment
markdd Posted January 9, 2018 Author Share Posted January 9, 2018 These work like a charm. Thank-you. If I wanted to get other information from the viewport like Drawing title, number, name etc., what part of the script would I adapt? Also, where would I find information within the help files to find the necessary information so I can do it for myself and hopefully learn a little more about scripts etc.... Thanks. Mark Quote Link to comment
Pat Stanford Posted January 9, 2018 Share Posted January 9, 2018 Start with the Vectorscript Appendix. There is a section showing all of the ObjectVariables for viewports. That will give you a starting point. This should be in your VW folder under VWHelp:Script Reference. And keep asking until you get what you need. 1 Quote Link to comment
markdd Posted January 10, 2018 Author Share Posted January 10, 2018 Thanks Pat I have found the info and I think I understand it. What I can't seem to find in the appendix under viewports, is any reference to the Drawing Title field and the Drawing Number field. Could you guide me as to how I could pull that kind of info into a worksheet. Many thanks Mark Quote Link to comment
Pat Stanford Posted January 10, 2018 Share Posted January 10, 2018 Drawing title and Drawing number are combined into the viewport object Name field at the bottom of the shape pane of the OIP. It can be accessed in a database with a formula of =N I will see if I can find a way to access the fields individually. Quote Link to comment
markdd Posted January 11, 2018 Author Share Posted January 11, 2018 Many thanks Pat. I've managed that, but wondered how I could get the Drawing Title field and the Drawing Number fields individually. Mark Quote Link to comment
Pat Stanford Posted January 11, 2018 Share Posted January 11, 2018 GetObjectVariableString(FSActLayer,1032) = Drawing Title (listed as Viewport Description in the Appendix) GetObjectVariableString(FSActLayer,1033) = Drawing Number (listed as Viewport Locator in the Appendix). Quote Link to comment
markdd Posted January 13, 2018 Author Share Posted January 13, 2018 Thanks Pat. I've tried the above and I just get errors. Could you put above into the context of the earlier script that you wrote for me? At least that way I can see what I am doing wrong. Many thanks Mark Quote Link to comment
Pat Stanford Posted January 16, 2018 Share Posted January 16, 2018 Procedure Get_Drawing_Title; Var H1,H2:Handle; N1:Integer; R1:Real; S1:String; Begin H1:=WSScript_GetObject; S1:=GetObjectVariableString(H1,1032); WSScript_SetResStr(S1); End; Run(Get_VP_Scale_Drawing_Title); Create the above script with a name of Get_Drawing_Title and then use a function in the worksheet of "=RunScript('Get_Drawing_Title')" just like you used the other worksheet scripts. The type of data returned (in the _SetRes line) must match the type of data provided, so if you are getting a sting it will be WSScript_SetResStr, for real _SetResReal, etc. Quote Link to comment
markdd Posted January 16, 2018 Author Share Posted January 16, 2018 Thanks Pat. I'll look into this later today. Mark Quote Link to comment
markdd Posted January 22, 2018 Author Share Posted January 22, 2018 I've taken your advise and learned loads. The resulting worksheet is just what I need. Many thanks. Mark 1 Quote Link to comment
Pat Stanford Posted January 22, 2018 Share Posted January 22, 2018 You are welcome. Keep asking if you need more help. 1 Quote Link to comment
C. Andrew Dunning Posted February 27, 2020 Share Posted February 27, 2020 I just found this old thread. MANY thanks to you, Pat!!!!!! 1 Quote Link to comment
Boh Posted July 31, 2020 Share Posted July 31, 2020 On 1/10/2018 at 6:55 AM, Pat Stanford said: If you save these scripts into your file (any script palette will do), then you can call them in a worksheet by using a function of "=RunScript('ScriptName')". Where the script name is replaced by the name you are showing in the script palette. Copy everything in the code blocks below. You can name the scripts anything you want, but I named them "Get_VP_Scale" and "Get_VP_Scale_Text". Hi Pat. I can't get this to work. What am I doing wrong? 2020-07-31 17-54-27.mp4 Quote Link to comment
Pat Stanford Posted July 31, 2020 Share Posted July 31, 2020 @Boh, I have no idea. If you can post your test file I will take a look. I just copies the scripts from above in the thread and pasted them into new scripts in a test file and I get exactly what I am supposed to. The only possibility I can think of is that at some point you check the Never Run Scripts box. To get that back you will need to go to VW Preferences:Session:Reset Saved Settings... and reset the "Always Do Selected Action" choices. Quote Link to comment
Boh Posted July 31, 2020 Share Posted July 31, 2020 Thanks Pat. Will post file on Monday. I actually hit the “always execute” option as I was trying lots of variations in the worksheet and got annoyed with the pop up. Quote Link to comment
Boh Posted August 2, 2020 Share Posted August 2, 2020 Hi Pat. File attached. Thanks for having a look. Viewport worksheet.vwx Quote Link to comment
Pat Stanford Posted August 3, 2020 Share Posted August 3, 2020 I just opened the file in VW2020 and it did exactly what it was supposed to. Are you positive that you didn't accidentally click the Never button for Run Scripts? My suggestion is to reset all of the "Always do the selection choices" under VW Preferences:Session Pane:Reset Saved Settings... button. I don't have VW2019 installed anywhere to test it there. Sorry. Quote Link to comment
Boh Posted August 3, 2020 Share Posted August 3, 2020 15 minutes ago, Pat Stanford said: Are you positive that you didn't accidentally click the Never button for Run Scripts? 100% positive. So yes I opened the file in vw2020 and it works, so it must not work in 2019. That's fine, good to know this capability is there in later versions. I will revisit this again when I am actually using vw2020 (or it looks likely we'll be holding off to vw2021 now). Cheers! Quote Link to comment
Pat Stanford Posted August 3, 2020 Share Posted August 3, 2020 The scripts were written in 2018, so they should work in 2019. Don't know what else to tell you. I just downloaded VW2019. You are correct. It is broken in 2019SP6. :-( BUT, there seems to be a strange work around. If you add two blank columns to the right of the column(s) with the Runscript commands, then they calculate correctly. VERY strange. Quote Link to comment
Boh Posted August 3, 2020 Share Posted August 3, 2020 (edited) How bizzare! Yes I added a couple of columns and now it works. I then deleted both the columns and it still works. Bugsville! How bizzare also that you managed to figure that out!!!! Edited August 3, 2020 by Boh 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.