C_bonaker_1976 Posted October 16, 2003 Share Posted October 16, 2003 If you select a field in a dialog so that you can type over the current information, how do you make it so that when you hit the enter key, it automatically acts as if the ok button has been selected. I'm trying my hand at writing a tool that will allow me to update a record field attached to an object just by selecting the object and running the script. That part works. I've fed the field with the old information as a reference, then selected the field so that all you have to do is type the new value. But you have to click ok, which is much slower than just hitting return. It would be great if you typed the new number, then could hit enter to send the info. Here is the code I've started from for the dialog: PROCEDURE Dialogstart; VAR item: Integer; cancel, done : Boolean; BEGIN BeginDialog(1,1,100,100,300,300); AddButton('OK',1,1,110,175,180,190); AddButton('Cancel',2,1,20,175,90,190); AddField('test',3,1,15,20,180,40); AddField('test',4,2,15,60,180,80); EndDialog; GetDialog(1); SetTitle('Test'); cancel := False; done := False; SelField (4); REPEAT DialogEvent(item); IF item = 2 THEN cancel := True; IF item = 1 THEN done := True; UNTIL cancel | done; END; RUN(Dialogstart); Any Ideas? Thanks for any help. Quote Link to comment
Alexandre Villares Posted October 16, 2003 Share Posted October 16, 2003 Thanks Fuge! [ 10-19-2003, 09:10 PM: Message edited by: Alexandre B A Villares ] Quote Link to comment
Fuge Posted October 17, 2003 Share Posted October 17, 2003 Here's something I put together using the modern dialog commands for creating a layer and sheet in one shot. You should be able to modify it to fit your needs, the structure is there. The "return" key (carriage return) will act the same as hitting the OK button as you want. HTH Dave OK, here it is, sorry fella's... Procedure Createlayersheet; CONST kOK = 1; kCancel = 2; VAR LayerName ,TempLayerName :STRING; Layerhd :HANDLE; dialogOK,Done: Boolean; dlogID, dialogResult : LONGINT; newname:DYNARRAY[] of CHAR; startname:DYNARRAY[] of CHAR; LayerVis :INTEGER; PROCEDURE DriveDialog(VAR item:LONGINT; data:LONGINT); VAR L1 : ARRAY [ 1..256 ] OF STRING; i : INTEGER; BEGIN CASE item OF SetupDialogC:BEGIN SetField(3,'Enter Name'); BEGIN Layerhd := FLayer; i := 1; WHILE Layerhd <> NIL DO BEGIN L1 := GetLName(Layerhd); i := i + 1; Layerhd := NextObj (Layerhd ); END; END; END; {end dialog init} SetdownDialogC:BEGIN { dialog cleanup } END; 3:BEGIN newname:= GetField(3); END; END; {end CASE} FOR i := 1 TO NumLayers DO BEGIN i := 1; If ( GetField(3) = L1 ) THEN BEGIN AlrtDialog('That name is already exists!'); SetField(3,'enter different name'); End; i := i + 1; End; IF(GetField(3) ='') THEN { Checks for blank field } BEGIN AlrtDialog('Please enter a name!'); sysbeep; END; END; BEGIN { Create Dialog } ALLOCATE newname[1..29]; ALLOCATE startname[1..29]; dlogID := CreateLayout ('Create Name', TRUE, 'Ok', 'Cancel'); CreateGroupBox( dlogID, 13,'Layer & Sheet Name', TRUE); SetFirstLayoutItem( dlogID, 13 ); CreateEditText( dlogID, 3, '', 29); SetFirstGroupItem( dlogID, 13, 3); SetHelpString( 3 , 'Enter a name for layer & sheet.'); SetHelpString( kOK, 'OK'); SetHelpString( kCancel, 'Cancel'); AlignItemEdge( dlogID, 5, 2, 30, 1); AlignItemEdge( dlogID, 20, 2, 30, 1); dialogOK := VerifyLayout( dlogID); IF dialogOK THEN { Check Dialog is Good } BEGIN dialogResult := RunLayoutDialog( dlogID, DriveDialog ); IF dialogResult = 1 THEN BEGIN VSave('Temp Sheet'); TempLayerName:= GetLName(ActLayer); Layerhd := FLayer; WHILE Layerhd <> NIL DO BEGIN LayerName:= GetLName(Layerhd); Layer ( LayerName ); If LayerName = 'Page Border' THEN ShowLayer ELSE HideLayer; Layerhd := NextObj (Layerhd ); END; Layer ( newname ); SaveSheet( newname , False , False, True ); HideLayer; VRestore('Temp Sheet'); VDelete('Temp Sheet'); END; END; END; RUN ( Createlayersheet ); [ 10-16-2003, 11:12 PM: Message edited by: Fuge ] Quote Link to comment
C_bonaker_1976 Posted October 19, 2003 Author Share Posted October 19, 2003 Thank-you very much for the help. It turns out that I found a much simplier way to do what I was trying to do. I used this amazing function dialogint. I then converted the number to a string and updated the field. I would never have looked at that command had you not posted your help. That dialog somehow has the ability to take input and then exit with a return. *shrug* My question now is how do I take my script that works great when I double click it on my custom palette, but won't work when I try to create a tool or menu command. What is the difference between a script created on the resource palette, and one cut and pasted (same one) into a tool or menu command on the plug-in editor. I have Vectorworks 9.02 until the funding comes through. Any ideas. Thanks again for the help. Quote Link to comment
ccroft Posted October 19, 2003 Share Posted October 19, 2003 As I understand it (which may or may not be accurate) a script can't be run by simply selecting a tool icon...it requires some interaction with the drawing. It's a tool for drawing. A script like yours that gets it's input only from a dialog should be a menu command. You can assign a key short-cut to it so that no mousing is needed. Hit the key combo, enter the info and hit return or enter (on mac anyway). I have a few such commands. They were simply copied and pasted as you describe, and they behave exactly as they did when they were run from the script palette. You do have some other options to explore in plug-in editor under properties. As to the funcionality of the return key/ok button, I think it's supposed to be automatic with a button who's ID is 1. On mac, this button will also get the familiar look that all "OK" buttons have in all programs. So I guess it's an operating systems thing. Or maybe it's built into DialogEvent(). I think it's beyond our control in v-script. Why your first script didn't work right is beyond me. What's your platform? In any case, you may want to look at "Dialog Builder" under the "tools" section of the v-script area of the main site: http://www.nemetschek.net/support/custom/vscript/vstool.html This has always served me well and creates cross-platform dialogs that work the way I want them to whether they're run as simple scripts,tools,or menu commands. It does create a script with a rather different structure than your first one. Maybe the answer is somewhere in this dif. [ 10-19-2003, 02:23 PM: Message edited by: ccroft ] 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.