Jump to content
Developer Wiki and Function Reference Links ×

Recalculate Individual Worksheet


Recommended Posts

Hey all,

I whipped this up the other day:

Procedure RAW;

VAR

H, H2 :Handle;

x, y :Real;

Begin

GetPt(x, y);

H:= PickObject(x,y);

H2 := GetWSFromImage(H);

RecalculateWS(H2);

End;

Run(RAW);

It's able to recalculate a single worksheet which is already inserted into the drawing. I was finding that hitting recalc on a worksheet was doing them all when sometimes I only needed one to update. Obviously the negative thing is that I can't make it recalculate if it's only in the resource browser and not inserted.

Just wondering if anyone knows how I can call a list of worksheets in the browser or replace the GetPt with a select this worksheet in the browser function.

Hmmmmmm.

J

Link to comment

Here's a way of doing this with a ListBrowser. You can multiselect your worksheets in this script to update more then one.

PROCEDURE Example;
VAR
Listid,ListNum : INTEGER;
id,tmpint,cnt : INTEGER;
Bool : BOOLEAN;

{sub}
PROCEDURE MakeDialog;
BEGIN
	id:=CreateLayout('Some title',false,'Ok','Cancel');
	CreateLB(id,100,30,15);
	SetFirstLayoutItem(id,100);
END;
{sub}
PROCEDURE DialInst;
VAR
	CInt : INTEGER;
BEGIN
{make a column in the LB}
	CInt:=InsertLBColumn(id,100,1,'Name',190);
	Bool:=SetLBControlType(id,100,CInt,5);
	Bool:=SetLBItemDisplayType(id,100,CInt,3);
{fill that column with the WS}
	FOR cnt:=1 TO ListNum DO tmpint:=InsertLBItem(id,100,cnt-1,GetNameFromResourceList(Listid,cnt));
END;
{sub}
PROCEDURE HandOK;
VAR
	NumSelLB : INTEGER;
BEGIN
	NumSelLB:=GetNumSelectedLBItems(id,100);
	FOR cnt:=0 TO GetNumLBItems(id,100) DO IF IsLBItemSelected(id,100,cnt) THEN
	BEGIN
		RecalculateWS(GetResourceFromList(Listid,cnt+1));
	END;
END;
{sub}
PROCEDURE DialHand(VAR item,data:LONGINT);
BEGIN
	CASE item OF
		SetupDialogC: DialInst;
		1: HandOK;
	END;
END;
{sub}
PROCEDURE DialogWorkSheets;
BEGIN
	MakeDialog;
	IF VerifyLayout(id) THEN tmpint:=RunLayoutDialog(id,DialHand);
END;
{main}
BEGIN
Listid:=BuildResourceList(18,0,'',ListNum);
IF ListNum<>0 THEN DialogWorkSheets ELSE AlrtDialog('No worksheets where found in this drawing.');
END;
RUN(Example);

Link to comment

You're welcome :) .

This probable isn't the best example to study because it's a little bit to complex for what it does (i used the dialog from an other more complex script and took out what wasn't necessary but didn't strip it down to the basics).

But look the functions up in the online Function Reference, there are to the point examples with more information in it.

Link to comment

Hi, it's a bit tricky:

there is the Worksheet preference "autoRecalc". If that is TRUE, the worksheet will

* before VW 2011 or 10 (I should check) using the command "recalculate" would recalc ALL worksheets whose pref "AutoRecalc" was true. Both running "Recalculate" from inside an open Worksheet window or contextual menu.

* in the current version, the command "recalculate" will recalc all worksheets, unregarded if their option autorecalc is on or not.

I find this good, because too often I have about 50 worksheets and no wish whatsoever to miss one from recalcs which are tied to loads of referenced data. I am VERY happy that now "recalculate" fetches everything.

When you script this kind of action you should remember that worksheets will only recalculate by script upon running "RecalculateWS" if their autorecalc flag is active. So you need to

* fetch handle to worksheet definition

* check its autorecalc state using GetWSAutoRecalcState, store it

* if this returns FALSE, set it to true using SetWSAutoRecalcState

* RecalculateWS

* set SetWSAutoRecalcState back to previous value

* refresh worksheet images using ResetObject, because they won't always do it alone.

You use SetWSAutoRecalcState setting it to false a lot whenever you are changing lots of cells by script, otherwise you have a terrible performance issue. Really important.

BTW if you wish to learn more about List Browsers, there are a number of sub routines on Vectorlab and also a detailed article.

* article about LBs (in three parts)

* subroutines about LBs

orso

Edited by _c_
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...