Jump to content
michaelk

dialog handler

Recommended Posts

It has finally happened.  Some of the very first scripts I wrote in December of 2012 have stopped working in 2019.

 

I learned just barely enough to get the old fashioned dialog to work and then forgot how it worked :-).

 

I ran the enable dialog builder script and got the new palette.  But I can't find anything about it in the language guide.

 

I'd appreciate any help anyone can give.  Speak slowly, please.

 

 

This is one of the scripts I'm trying to update:

 

Procedure CellBorder_Outline;
{Badly scripted by Michael Klaers}

VAR
	
	WSHand		: Handle; 				{Handle to Worksheet}

	topRow,leftColumn,bottomRow,rightColumn,fontIndex,fontSize,fontStyle  :INTEGER;
	currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow   :INTEGER;
	
	
	lineStyle,lineWeight : INTEGER;			{for SetWSCellBottom/Top/Left/RightBorder}
	lineColor : LONGINT;
	
	DialogID :INTEGER;
	DialogResult  :INTEGER;




PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);		{Dialog Handler - Line Weight}
	BEGIN
		CASE item OF
			SetupDialogC:
				BEGIN
				SetLineWeightChoice(DialogID, 5,20);
				SetLineStyleChoice(DialogID, 7,0);
				SetColorChoice(DialogID, 9, 255);
				END;
	
			1:
			BEGIN
				GetLineWeightChoice(DialogID, 5, DialogResult);
				lineWeight :=  DialogResult;
				GetLineStyleChoice(DialogID, 7, DialogResult);
				lineStyle :=  DialogResult;
				GetColorChoice(DialogID, 9, DialogResult);
				lineColor :=  DialogResult;


			END;
		END;
	END;







BEGIN

{Get WORKSHEET cell range}

	WSHand:=GetTopVisibleWS;
	
	GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow);
	
	


{DIALOG BOX unified line weight, style, color}

	DialogID := CreateLayout('Speedy Outline Cell Borders!', TRUE, 'Set Cell Outline Borders', 'Never Mind...');
	CreateStaticText(DialogId,4,'Select a Line Weight',-1); 
	CreateLineWeightPopup(DialogID, 5);
	CreateStaticText(DialogId,6,'If you`re feeling fancy, Select a Line Style',-1); 
	CreateLineStylePopup(DialogID, 7);
	CreateStaticText(DialogId,8,'Select a Line Color',-1); 
	CreateColorPopup(DialogID, 9, 24);

	
	
	SetFirstLayoutItem(DialogID, 4);
	SetBelowItem (DialogId,4,5,0,0); 
	SetBelowItem (DialogId,5,6,0,2); 
	SetBelowItem (DialogId,6,7,0,0); 
	SetBelowItem (DialogId,7,8,0,2); 
	SetBelowItem (DialogId,8,9,0,0); 

	
	
	SetHelpText(DialogId,1,'Select line weight, style and color for cell border'); 
	SetHelpText(DialogId,2,'Cancel the operation and exit.'); 
	SetHelpText(DialogId,4,'Select a Line Weight'); 
	SetHelpText(DialogId,5,'Select a Line Weight'); 
	SetHelpText(DialogId,6,'Select a Line Style, Mr. Fancy Pants'); 
	SetHelpText(DialogId,7,'Select a Line Style, Mr. Fancy Pants'); 
	SetHelpText(DialogId,8,'Select a Line Color'); 
	SetHelpText(DialogId,9,'Select a Line Color'); 





	
	DialogResult := RunLayoutDialog(DialogID, Dialog_Handler);
	
	





{style	Border line style to be set.(0 = None; 2 = Solid, -1..-32 (dash style index) = Dash)
weight	Border line weight to be set.(in Mils)
color	Border line color to be set. (color index: 0..255)}


{Set WORKSHEET CELL BORDERS}
	SetWSCellOutlineBorder(WSHand,topRangeRow,leftRangeColumn,bottomRangeRow,rightRangeColumn,lineStyle,lineWeight,lineColor);
	
END;

RUN(CellBorder_Outline);

 

Share this post


Link to post

Line style handling is actually what changed in 2019.  There should be new WS calls for these.  Also check if the dialog LineStyle calls have updates.  Generally the new calls are fairly straight forwards.  Without looking up the API:

 

SetWSCellOutlineBorder => SetWSCellOutlineBorderN

Share this post


Link to post

Josh

 

Great catch.  But that still doesn't fix it.  I'm getting errors on the dialog lines.  Which is what made me suspect the dialog to begin with.

 

This is one of the reasons I wanted to organize a VS session around the design summit is I wanted someone to show me how to do this!

 

 

Screen Shot 2018-10-09 at 5.11.56 PM.png

Share this post


Link to post

Swap out the dialog LIneStyleChoice commands as well.  In VS, if you have one line throwing an error (the first one in the error message here), subsequent lines won't compile correctly either.

Share this post


Link to post

OK.  Not trying to be dense.  

 

I'm not seeing a replacement for LineStyleChoice.

 

(Even after I realized I was looking up the 2016 script reference)

 

 

Share this post


Link to post

Three code changes to get it to compile and execute.

 

SetLineStyleChoice -> SetLineTypeChoice

GetLineStyleChoice -> GetLineTypeChoice

SetWSCellOutlineBorder -> SetWSCellOutlineBN

 

And one bad bug that prevents it from running. It appears that the GetWSSelection command is returning bad values for the subrows. The following very simple script gives the same runtime error as yours.

 

Procedure Test;

Var
    WSHand:Handle;
    currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow:Integer;


Begin
    WSHand:=GetTopVisibleWS;
    GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow);
    Message(currentCellRow,'  ',currentCellColumn);
End;

Run(Test);

Procedure Test;

Var
	WSHand:Handle;
	currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow:Integer;

Begin
	WSHand:=GetTopVisibleWS;
GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow);
	Message(currentCellRow,'  ',currentCellColumn);
End;

Run(Test);

Until VW fixes the bug in GetWSSelection, you are out of luck on this script.

 

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?

Brian Kernaghan"The Elements of Programming Style", 2nd edition, chapter 2.

Share this post


Link to post

Aha!!

 

Now it runs.  It just doesn't do anything!

 

Thanks Pat and Josh

 

Share this post


Link to post

Check that.

 

It does run and work EXCEPT it's taking a solid line as no line.

 

hmmmm

 

 

Share this post


Link to post

HA!  Got it.  The old script used line style choice 0 to get a solid line.  line type choice 1 fixes it.  I'll have to go dig into the new functions.

 

Thanks for your help gentlemen.  I was looking at an old VS reference and didn't even know that the WS line functions had changed.

 

Here's the script that works.  Not sure why you're getting an error, Pat.

 

Procedure CellBorder_Outline;
{Badly scripted by Michael Klaers}

VAR
	
	WSHand		: Handle; 				{Handle to Worksheet}

	topRow,leftColumn,bottomRow,rightColumn,fontIndex,fontSize,fontStyle  :INTEGER;
	currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow   :INTEGER;
	
	
	lineStyle,lineWeight : INTEGER;			{for SetWSCellBottom/Top/Left/RightBorder}
	lineColor : LONGINT;
	
	DialogID :INTEGER;
	DialogResult  :INTEGER;


PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);		{Dialog Handler - Line Weight}
	BEGIN
		CASE item OF
			SetupDialogC:
				BEGIN
				SetLineWeightChoice(DialogID, 5,20);
				SetLineTypeChoice(DialogID, 7,1);
				SetColorChoice(DialogID, 9, 255);
				END;
	
			1:
			BEGIN
				GetLineWeightChoice(DialogID, 5, DialogResult);
				lineWeight :=  DialogResult;
				GetLineTypeChoice(DialogID, 7, DialogResult);
				lineStyle :=  DialogResult;
				GetColorChoice(DialogID, 9, DialogResult);
				lineColor :=  DialogResult;


			END;
		END;
	END;







BEGIN

{Get WORKSHEET cell range}

	WSHand:=GetTopVisibleWS;
	
	GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow);
	
	


{DIALOG BOX unified line weight, style, color}

	DialogID := CreateLayout('Speedy Outline Cell Borders!', TRUE, 'Set Cell Outline Borders', 'Never Mind...');
	CreateStaticText(DialogId,4,'Select a Line Weight',-1); 
	CreateLineWeightPopup(DialogID, 5);
	CreateStaticText(DialogId,6,'If you`re feeling fancy, Select a Line Style',-1); 
	CreateLineStylePopup(DialogID, 7);
	CreateStaticText(DialogId,8,'Select a Line Color',-1); 
	CreateColorPopup(DialogID, 9, 24);

	
	
	SetFirstLayoutItem(DialogID, 4);
	SetBelowItem (DialogId,4,5,0,0); 
	SetBelowItem (DialogId,5,6,0,2); 
	SetBelowItem (DialogId,6,7,0,0); 
	SetBelowItem (DialogId,7,8,0,2); 
	SetBelowItem (DialogId,8,9,0,0); 

	
	
	SetHelpText(DialogId,1,'Select line weight, style and color for cell border'); 
	SetHelpText(DialogId,2,'Cancel the operation and exit.'); 
	SetHelpText(DialogId,4,'Select a Line Weight'); 
	SetHelpText(DialogId,5,'Select a Line Weight'); 
	SetHelpText(DialogId,6,'Select a Line Style, Mr. Fancy Pants'); 
	SetHelpText(DialogId,7,'Select a Line Style, Mr. Fancy Pants'); 
	SetHelpText(DialogId,8,'Select a Line Color'); 
	SetHelpText(DialogId,9,'Select a Line Color'); 





	
	DialogResult := RunLayoutDialog(DialogID, Dialog_Handler);
	
	





{style	Border line style to be set.(0 = None; 2 = Solid, -1..-32 (dash style index) = Dash)
weight	Border line weight to be set.(in Mils)
color	Border line color to be set. (color index: 0..255)}


{Set WORKSHEET CELL BORDERS}
	SetWSCellOutlineBN(WSHand,topRangeRow,leftRangeColumn,bottomRangeRow,rightRangeColumn,lineStyle,lineWeight,lineColor);
	
	Message('TOP: ',topRangeRow,chr(13),
			'LEFT: ',leftRangeColumn,chr(13),
			'BOTTOM: ',bottomRangeRow,chr(13),
			'RIGHT: ',rightRangeColumn,chr(13),
			'LINE STYLE: ',lineStyle,chr(13),
			'LINE WEIGHT: ',lineWeight,chr(13),
			'LINE COLOR: ',lineColor);
END;

RUN(CellBorder_Outline);

 

Share this post


Link to post

STILL want someone to walk me through the dialog builder!

 

Maybe in Phoenix I can buy someone enough drinks at the bar to get through it?

  • Laugh 1

Share this post


Link to post

The online reference is almost always the best place to look for current functions: http://developer.vectorworks.net/index.php/Vectorworks_Scripting

 

Dialog Build will generate the layout portion of your code using a graphical interface.  You arrange elements in a node-like fashion — you can see that Marionette's roots come from DB.  It's a great tool for testing and tweaking your user interface, and if you need localizable code it automatically generates string resources for you.  It does not generate the vs or py for the dialog handler, which can often be the most time consuming part of implementing a dialog.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×