Jump to content
Developer Wiki and Function Reference Links ×

runscript in worksheets (and VW 2022 data manager)


Recommended Posts

Hi,

 

actually I am looking for some help how to make a script run within a Vectorworks worksheet.

Actually I know a little about scripting (both Vectorscript and Python) and what I am doing is simple data processing, which doesn't work in worksheets for several reasons.

I actually wrote some scripts, which for example count space objects and sum up their are, in order to recalculate it in a new worksheet. However running scripts inside the datamanager sounds quite appealing, so it could be worth a try.

 

Now my simple idea has been, that either if I work in a worksheet or the datamanager, the system must be quite similar

 

1) in a worksheet for example I create a filter line, which shows me for example all space objects in the drawing or in a specific layer. In Column A I write ='Space'.'11_Occupancy Type' in order to see the text in the corresponding space object record format field. Now I want to hand over that text to a script in column B in order to do whatever I could do with the string from column A. Divide it into substrings, count all Space objects with the corresponding occupancy type and calculate their are,... (sounds quite like it could be possible within the worksheet, but, what I want to achieve goes a little bit further) however

a) where can I define that I want to hand over the string from the worksheet cells A-1.1 -> A1.X?

b) how do catch that string within the script

c) and finally, how do I hand it over back to the worksheet?

 

2) same about the Datamanager. Let's say, I create a new mapping, which reads out the occupancy type of all space objects and has to count all space objects of the corresponding occupancy type and map the result into a "ifc data field".

 

thanks in advance for your answers.

The developer reference was a little bit to short. I didn't find the answer there, unfortunately.

Link to comment

Hi there,

 

I am doing some worksheetscripting and I am wondering if it is possible to get the column index of the column the script is placed in.

I want to grab the string thats in the first row as a kind of search criteria.

 

Thanks in advance for your answers.

Link to comment

Sorry I forgot to say, at the moment I have the "search word" in the 1st Row and the Data and runscript command is in the 3rd row in subrows.

My workaround is to manually write the column index in the 2nd row and use the cell value as parameter when running the script (eg: =runscript('scriptname';B2)

Inside the script I am using WSScript_GetPrmInt(index) to get it in the script and to get the 1st row of this column as searchstring by using GetWSCellString(hand,ROW,COL,searchstring)

But I think there must be a way to to this without the manual index.

 

I am using the German version so I think the use of ; and , and . is different than in the international version, so don't get confused;)

Link to comment

I don't think there is a way to automatically get the row or column number of a cell that is recalculating (running the script).

 

Your manual cell work around is probably the best you are going to get in terms of automating it.

 

If you don't add columns very often, why not just pass the column number as a parameter instead of doing the search? If this script has to run on a lot of objects having to do that each for every subrow in the database could be very slow.

 

Sorry.

Link to comment
8 hours ago, Pat Stanford said:

If you don't add columns very often, why not just pass the column number as a parameter instead of doing the search? If this script has to run on a lot of objects having to do that each for every subrow in the database could be very slow.

 

I'm not Sure if I get your idea. Yes the worksheet gets slow, but I only need it for readout and I can't see a better solution.

 

If you got time to think about it, here is the full story (with a simplified example):

 

I have symbols that are representing devices with 10 "slots".

In each slot I can insert several "cards" of the same type.

So I might have a device with 10x "CardA" in Slot 1 and 2x "CardC" in Slot 2 and the rest is empty

But I might also have a device with 5x "CardC in Slot 1 and also 7x "CardC" in Slot 2

...I hope you get my point

A typical amount of these symbols in a document is 30-150.

 

The Symbols are connected with a record with 10 Popup fields and 10 integer "count" fields.

These Popupfields represent the 10 "slots" and the count field the amount of Cards in each slot.

Every Popup field has the same list of "Cards" (CardA, CardB,...) to select from.

 

Why am I doing things so complicated? It's because of better data input and reduction of fields, especially in combination with a data tag to input/output the informations dynamically. Lets say I have 50 different cards and I don't want to skip thru all "cards" I don't and leave the value 0 and only set an amount in 1 or 2 fields of 50. The popup works much better and I can clarify that I have two slots with the same card, but different amount.

 

But here is the point where I use the worksheetscript, to get the total amount of "CardA" in all symbols of my document, I need to search for "CardA" in every slot of every symbol and sum up all the count-fields of these slots. So I have a worksheet with subrows for every symbol an run the script in 50 columns, each column searches for a different "Card" so Column 1 searches for "CardA"... Column 5 for "CardE"...

I use the same script in every column and get the different searchstring from the header (row1) of the column. Therefor I use GetWSCellString(hand,ROW,COL,searchstring). Therefor I need the index of the Column the script is inserted in.

I can live with the workaround that I manually type in the index in the 2nd row and make this row very narrow, I just thought there is a better way.

 

I end up with a worksheet that has the total amount of each card per device(symbol) in a row and I can sum up the row to get the final sum of that card.

 

@Pat Stanford

any ideas or points on how to make it easier? I'm not a programmer and this is my first worksheet script so I think there is room to improve;)

and yes, that worksheet is very slow, when I change something and it is updating, but I only use it for data readout, and I only update it before looking at it. 

I use another Worksheet where I work on the Symbols data...slots...cards...whatever;)

 

QUESTION:

Is it possible to stop the worksheet to update and run scripts automatically? There was a dialogbox after I inserted the runscript function for the first time, can I get this back, or do I need to reset all dialogboxes in the program settings?

 

Thanks for your help.

Link to comment

Answer to your last question is you have to reset all of the Always/Never dialogs to get the Run Scripts question back.

 

I will take a look at your post in more detail later to see if I can offer any suggestions on a better way.  Are you using Connect Cad? I know it deals with racks with slots. I don't know how it handles them.

 

Link to comment

Take a look at this test file and see if it can work for what you need to do.

 

I used a simple record "Rack", with only 3 slots.  Attached it to two rectangles.  Made a database of the objects having that record.

 

There are two versions of the worksheet script. Both return the number of fields from the record contain a given string.

 

Hardcode has all of the record and field names hardcoded. It is included in Column D.

UseParams lets you specify what Record Name as the first parameter, and what you want to count for as the second parameter. It is used in Columns E, F, & G.

 

By adding columns to count the number of each different card for each "rack" you avoid having to do the comparison of every object in the drawing. You can then add up all of the "CardA" columns to get your total number.

 

While I put the Card Names above the columns so I could use them as a label as well as a parameter for the script, you could put them anywhere you wanted.

 

Count for Records Matching Value.vwx

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