JoshRula Posted June 22, 2023 Share Posted June 22, 2023 I have been reading with vectorscript documentation and some examples from the the forum, I can't seem to grasp how to correctly build the dialog handler and pass my collected data to variables outside it. this is what I put together for the uid, but all of my attempts at writing my own dialog handler or modifying others I have found have borne no fruit. I would like help with the code, but more importantly I would like to understand it. Teach a man to fish and all... {CABINET BUILDER V0.1} PROCEDURE CabinetBuilderDialogBox; VAR builderDialog:LONGINT; result:LONGINT; BEGIN builderDialog:=CreateLayout('Cabient Builder',false,'Build','Exit'); CreateStaticText( builderDialog ,1,'CABINET BUILDER V0.1',-1); SetFirstLayoutItem( builderDialog , 1); { ********** TAB CONTROL ********** } { Tab Group 1} CreateGroupBox(builderDialog , 5 , 'Cabinet Specs' , FALSE); CreateStaticText(builderDialog , 6, 'WIDTH',8); SetFirstGroupItem(builderDialog ,5,6); CreateEditReal(builderDialog, 7, 1, 0, 4); SetRightItem(builderDialog , 6,7,0,0); CreateStaticText(builderDialog , 8, 'HEIGHT',8); SetBelowItem(builderDialog , 6,8,0,0); CreateEditReal( builderDialog , 9, 1, 0, 4); SetRightItem(builderDialog , 8,9,0,0); CreateStaticText(builderDialog , 10, 'DEPTH',8); SetBelowItem(builderDialog , 8,10,0,0); CreateEditReal( builderDialog , 11, 1, 0, 4); SetRightItem(builderDialog , 10,11,0,0); CreateStaticText(builderDialog , 12, 'KICK',8); SetBelowItem(builderDialog , 10,12,0,0); CreateEditReal( builderDialog , 13, 1, 0, 4); SetRightItem(builderDialog , 12,13,0,0); CreateStaticText(builderDialog , 14, 'DOOR(S)',8); SetBelowItem(builderDialog , 12 ,14,0,0); CreateEditInteger( builderDialog , 15, 2, 3); SetRightItem(builderDialog , 14,15,0,0); {Tab Group 2} CreateGroupBox(builderDialog , 16 , 'Material Specs' , FALSE); CreateStaticText(builderDialog , 17, 'Material Thickness',8); SetFirstGroupItem(builderDialog ,16,17); CreateEditReal(builderDialog, 18, 3, 19mm, 8); SetRightItem(builderDialog , 17,18,0,0); CreateStaticText(builderDialog , 19, 'Laminate Thickness',8); SetBelowItem(builderDialog , 17,19,0,0); CreateEditReal( builderDialog , 20, 3, 0.039in, 8); SetRightItem(builderDialog , 19,20,0,0); CreateStaticText(builderDialog , 21, 'Kick Set Back',8); SetBelowItem(builderDialog , 19,21,0,0); CreateEditReal( builderDialog , 22, 3, 4in, 8); SetRightItem(builderDialog , 21,22,0,0); CreateStaticText(builderDialog , 23, 'Door Gap',8); SetBelowItem(builderDialog , 21,23,0,0); CreateEditReal( builderDialog , 24, 3, 0.125, 8); SetRightItem(builderDialog , 23,24,0,0); { Create tab control } CreateTabControl( builderDialog , 100); SetBelowItem( builderDialog , 1, 100, 0, 0); { Add the tab panes } CreateTabPane( builderDialog , 100, 5); CreateTabPane( builderDialog , 100, 16); result:=RunLayoutDialog(builderDialog,NIL); END; RUN(CabinetBuilderDialogBox); Quote Link to comment
Vectorworks, Inc Employee Vlado Posted June 22, 2023 Vectorworks, Inc Employee Share Posted June 22, 2023 @JoshRula Here is your code, modified, working to show how to get two values out from the dialog on OK: {CABINET BUILDER V0.1} PROCEDURE CabinetBuilder; CONST kRealType = 1; kDimType = 3; VAR dialogID : LONGINT; width, height : REAL; {dialog data} FUNCTION CreateDialog : LONGINT; VAR builderDialog:LONGINT; BEGIN builderDialog:=CreateLayout('Cabient Builder',false,'Build','Exit'); CreateStaticText( builderDialog ,1,'CABINET BUILDER V0.1',-1); SetFirstLayoutItem( builderDialog , 1); { ********** TAB CONTROL ********** } { Tab Group 1} CreateGroupBox(builderDialog , 5 , 'Cabinet Specs' , FALSE); CreateStaticText(builderDialog , 6, 'WIDTH',8); SetFirstGroupItem(builderDialog ,5,6); CreateEditReal(builderDialog, 7, kRealType, 0, 4); SetRightItem(builderDialog , 6,7,0,0); CreateStaticText(builderDialog , 8, 'HEIGHT',8); SetBelowItem(builderDialog , 6,8,0,0); CreateEditReal( builderDialog , 9, kRealType, 0, 4); SetRightItem(builderDialog , 8,9,0,0); CreateStaticText(builderDialog , 10, 'DEPTH',8); SetBelowItem(builderDialog , 8,10,0,0); CreateEditReal( builderDialog , 11, 1, 0, 4); SetRightItem(builderDialog , 10,11,0,0); CreateStaticText(builderDialog , 12, 'KICK',8); SetBelowItem(builderDialog , 10,12,0,0); CreateEditReal( builderDialog , 13, 1, 0, 4); SetRightItem(builderDialog , 12,13,0,0); CreateStaticText(builderDialog , 14, 'DOOR(S)',8); SetBelowItem(builderDialog , 12 ,14,0,0); CreateEditInteger( builderDialog , 15, 2, 3); SetRightItem(builderDialog , 14,15,0,0); {Tab Group 2} CreateGroupBox(builderDialog , 16 , 'Material Specs' , FALSE); CreateStaticText(builderDialog , 17, 'Material Thickness',8); SetFirstGroupItem(builderDialog ,16,17); CreateEditReal(builderDialog, 18, 3, 19mm, 8); SetRightItem(builderDialog , 17,18,0,0); CreateStaticText(builderDialog , 19, 'Laminate Thickness',8); SetBelowItem(builderDialog , 17,19,0,0); CreateEditReal( builderDialog , 20, 3, 0.039", 8); SetRightItem(builderDialog , 19,20,0,0); CreateStaticText(builderDialog , 21, 'Kick Set Back',8); SetBelowItem(builderDialog , 19,21,0,0); CreateEditReal( builderDialog , 22, 3, 4", 8); SetRightItem(builderDialog , 21,22,0,0); CreateStaticText(builderDialog , 23, 'Door Gap',8); SetBelowItem(builderDialog , 21,23,0,0); CreateEditReal( builderDialog , 24, 3, 0.125, 8); SetRightItem(builderDialog , 23,24,0,0); { Create tab control } CreateTabControl( builderDialog , 100); SetBelowItem( builderDialog , 1, 100, 0, 0); { Add the tab panes } CreateTabPane( builderDialog , 100, 5); CreateTabPane( builderDialog , 100, 16); CreateDialog := builderDialog; END; PROCEDURE HandleDialog(VAR item : LONGINT; data :LONGINT); VAR ok : BOOLEAN; BEGIN IF item = 1 {OK button} THEN BEGIN ok := GetEditReal( dialogID, 7, kRealType, width ); ok := GetEditReal( dialogID, 9, kRealType, height ); END; END; BEGIN dialogID := CreateDialog; IF RunLayoutDialog(dialogID,HandleDialog) = 1 {OK} THEN BEGIN { the dialog was closed with ok} AlrtDialog( Concat( 'Width=', width, ' Height=', height ) ); END; END; RUN(CabinetBuilder); 1 Quote Link to comment
Vectorworks, Inc Employee Vlado Posted June 22, 2023 Vectorworks, Inc Employee Share Posted June 22, 2023 Some explanations: First, a Layout Manager dialog in Vectorworks is composed of two parts: 1. Creation -- code that creates the controls and their layout by defining what lies below or to the right; 2. Handling -- code that defines what the dialog does, i.e. receives messages from the controls So typically, you'll have two functions for the two parts, and typically you'll have constants for the variables so you can follow the two parts easier. You can see, the example above catches the event from the OK button (which has always index of 1) and retrieves the values from the controls. Note, here you used Real control, but maybe it would be better to use a 'dimension' control, which is aware of units. Notice how the edit control has a type of what the real value actually is: https://developer.vectorworks.net/index.php/VS:CreateEditReal Also see here for another example: https://developer.vectorworks.net/index.php/VS:RunLayoutDialog 3 Quote Link to comment
Vectorworks, Inc Employee Vlado Posted June 22, 2023 Vectorworks, Inc Employee Share Posted June 22, 2023 Also you might be better off using Python as a language instead of Pascal. It's just more modern syntax and it has the exact same functions available anyway. Also, it might be easier to use the Dialog Builder to create the Layout (#1 above) as it gives you a way to test and fine tune the layout, especially when it becomes more comples: https://developer.vectorworks.net/index.php/SDK:Dialog_Builder Here is some basic information on the dialog builder: https://developer.vectorworks.net/index.php/SDK:Dialog_Builder_Samples 3 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.