Jump to content

Worksheet of Viewports and scale


Recommended Posts

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);

 

Link to comment

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

Link to comment

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

Link to comment
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.

Link to comment
  • 2 years later...
  • 5 months later...
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?

 

Link to comment

@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.

 

 

Link to comment

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.

Link to comment
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!

 

 

Link to comment

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.

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...