Gridbuff Posted April 5, 2016 Share Posted April 5, 2016 {I have done plenty of classic custom dialog boxes. I like the procedures and I'm comfortable with screen co-ordinates . However because these procedures have all been scrapped, I'm now trying to write a simple example script showing a custom modern dialog into which real values a & b are entered in order to draw a rectangle (See below). Once I've got this right, I can go on to do scripts for complex objects with many variables} Procedure DialogTest; Procedure SetUpDialog; VAR a,b:REAL; ID: LONGINT; Res:LONGINT; BEGIN ID:=CreateLayout('Parameters', False, 'OK', 'Cancel'); {Text fields} CreateStaticText( ID, 05, 'Value-a', 15); CreateStaticText( ID, 06, 'Value-b', 15); {Box fields} CreateEditReal( ID, 15, 1, 1.25, 10); CreateEditReal( ID, 16, 1, 2.64, 10); {Text layout} SetFirstLayoutItem( ID, 05); SetBelowItem( ID, 05, 06, 0, 0); {Box layout} SetRightItem( ID, 05, 15, 0, 0); SetRightItem( ID, 06, 16, 0, 0); Res:=RunLayoutDialog( ID, NIL); END; BEGIN SetUpDialog; {I now need to assign the field values entered for Value-a & Value-b to the declared variables a & b. The obvious step would be - a:=GetEditReal(ID, 15, 1, true); b:=GetEditReal(ID, 16, 1, true); rect(0, 0, a, b); END; Run(DialogTest); Dead simple and similar to the sort of script in version 2008. However this does not work, and I have tried numerous workarounds with no success. QUESTION: How do I put in this missing link? Any constructive advice most welcome!} Quote Link to comment
LarryO Posted April 13, 2016 Share Posted April 13, 2016 Does it matter that you have not declared your VAR globally in the function header as in the example shown here http://developer.vectorworks.net/index.php/VS:RunLayoutDialog Never tried using custom dialogs myself. L Quote Link to comment
Hippocode Posted April 13, 2016 Share Posted April 13, 2016 Have a look at the example dialogs provided by Vectorworks to get you started: http://www.vectorworks.net/support/custom/vscript/example Quote Link to comment
Miguel Barrera Posted April 13, 2016 Share Posted April 13, 2016 I believe you are missing the procedure that drives the dialog in Res:= RunLayoutDialog( ID, NIL), which most likely will give you an error. The following should get you going as you create more complicated dialogs. Procedure DialogTest; TYPE U_RECT = STRUCTURE a: REAL; b: REAL; END; VAR gRectObj: U_RECT; FUNCTION SetUpDialog(rectObj: U_RECT): LONGINT; VAR ID: LONGINT; BEGIN ID:= CreateLayout('Rect Dimensions',TRUE,'OK','Cancel'); {Text fields} CreateStaticText( ID, 05, 'Value-a', 15); CreateStaticText( ID, 06, 'Value-b', 15); {Box fields} CreateEditReal( ID, 15, 1, rectObj.a, 10); CreateEditReal( ID, 16, 1, rectObj.b, 10); {Text layout} SetFirstLayoutItem( ID, 05); SetBelowItem( ID, 05, 06, 0, 0); {Box layout} SetRightItem( ID, 05, 15, 0, 0); SetRightItem( ID, 06, 16, 0, 0); SetHelpText(ID, 1,'Click to accept values'); SetHelpText(ID, 2,'Click to cancel operation'); SetHelpText(ID, 15,'Enter width'); SetHelpText(ID, 16,'Enter height'); SetUpDialog:= ID; END; FUNCTION GetRect(VAR rectObj: U_RECT): BOOLEAN; VAR a,b: REAL; ID,dlogResult: LONGINT; PROCEDURE DriveDialog(VAR item:LONGINT; data:LONGINT); VAR i,choiceNo: INTEGER; foundName: BOOLEAN; BEGIN CASE item OF SetupDialogC: BEGIN END; 1: {OK} BEGIN IF GetEditReal(ID,15,1,a) THEN rectObj.a:= a; IF GetEditReal(ID,16,1,b) THEN rectObj.b:= b; END; 2: {Cancel} BEGIN END; END; END; BEGIN GetRect:= FALSE; ID:= SetUpDialog(rectObj); IF VerifyLayout(ID) THEN BEGIN dlogResult:= RunLayoutDialog(ID,DriveDialog); IF dlogResult = 1 THEN GetRect:= TRUE; END ELSE AlrtDialog('Cannot create the dialog'); END; BEGIN gRectObj.a:= 1.25; gRectObj.b:= 2.64; IF GetRect(gRectObj) THEN BEGIN Rect(0,0,gRectObj.a,gRectObj.b); END; END; Run(DialogTest); Quote Link to comment
Gridbuff Posted April 14, 2016 Author Share Posted April 14, 2016 Thanks Larry. I'll keep that in mind. Quote Link to comment
Gridbuff Posted April 14, 2016 Author Share Posted April 14, 2016 Many thanks for that, Miguel. Just what I was needing to get started. Much appreciated:-) The user manuals seem to be ok on examples of standalone boxes, but one that actually works in practice is quite another matter. This gives me what I need to get going on a box for multiple inputs, when I'm scripting windows, spiral staircases etc. The old custom boxes work fine in VW2013, but i'll have to upgrade sooner or later. Again many thanks for your help. Gridbuff 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.