Jump to content
Developer Wiki and Function Reference Links ×

Cancel Button not working


EduardoS

Recommended Posts

I'm trying a simple script, just a rectangle where the mouse is clicked. What am I doing wrong? The cancel button does not work.

 

PROCEDURE Retangulo;

VAR
    Largura, Altura, LAR, ALT :INTEGER;
    pX, pY :REAL;
    id, result :LONGINT;
    
PROCEDURE Dialogo(VAR item :LONGINT; data :LONGINT);

    BEGIN
    IF GetEditInteger(id,5,Largura)    
    AND GetEditInteger(id,7,Altura) THEN
    LAR:=Largura;
    ALT:=Altura;
    END;
    
BEGIN
    id:=CreateLayout('Retângulo',FALSE,'OK','Cancel');
            
        CreateStaticText(id,4,'Largura:',8);
        CreateEditInteger(id,5,0,6);
        CreateStaticText(id,6,'Altura:',8);
        CreateEditInteger(id,7,0,6);
        
        SetFirstLayoutItem(id,4);
        SetRightItem(id,4,5,0,0);
        SetBelowItem(id,4,6,0,0);
        SetRightItem(id,6,7,0,0);

    result:=RunLayoutDialog(id,Dialogo);
    
    GetPt(pX, pY);
    Rect(pX, pY, LAR, ALT);
END;

RUN (Retangulo);

Link to comment

Your dialog handler needs to be a bit more complex. See http://developer.vectorworks.net/index.php/VS:Creating_a_Custom_Dialog_Box

 

The item passed to the handler is the ID of the dialog element with which the user has interacted. SetupDialogC is a universal constant that gets passed to the handler before the dialog appears, so this is where you can do things like set universal values. The ok button is 1 and the cancel button is 2. 

 

You may be working on this script as a test or proof of concept, but if not, did you know that double-clicking on the rectangle tool will present a dialog for creating a rectangle?

Link to comment

Thanks for your reply!

I saw the http://developer.vectorworks.net/index.php/VS:Creating_a_Custom_Dialog_Box and understood nothing. Searched for more information about it and found almost nothing. The GetPt has no index to interact with. Tried the If Did Not Cancel then GetPt did not work also. If I click the Cancel button the script still wants me to click somewhere to draw a rectangle.

Yes it is just a test to create something where I click, I am just studying, and I know a lot of  tools can be double clicked.

Link to comment

I modified the dialog handler, but the script still requires me to click somewhere after I click the Cancel button. Why?

 

PROCEDURE Retangulo;

VAR
    Largura, Altura, LAR, ALT :INTEGER;
    pX, pY :REAL;
    id, result :LONGINT;
    
PROCEDURE mDialogo(VAR item :LONGINT; data :LONGINT);

BEGIN
    CASE item OF
        SetupDialogC: BEGIN
        END;

        1: BEGIN
            IF GetEditInteger(id,5,Largura)    
            AND GetEditInteger(id,7,Altura) THEN
            LAR:=Largura;
            ALT:=Altura;
        END;
        2: BEGIN
        END;
    END;
END;

BEGIN
    id:=CreateLayout('Retângulo',FALSE,'OK','Cancel');
        CreateStaticText(id,4,'Largura:',8);
        SetFirstLayoutItem(id,4);
        CreateEditInteger(id,5,0,6);
        SetRightItem(id,4,5,0,0);
        CreateStaticText(id,6,'Altura:',8);
        SetBelowItem(id,4,6,0,0);
        CreateEditInteger(id,7,0,6);
        SetRightItem(id,6,7,0,0);

    result:=RunLayoutDialog(id,mDialogo);
    
    GetPt(pX, pY);
    Rect(pX-LAR/2, pY-ALT/2, pX+LAR/2, pY+ALT/2);
END;

RUN (Retangulo);

Link to comment
9 minutes ago, EduardoS said:

twk, creating the rectangle before the GetPt, If I cancel it still wants a click and If I click Ok the rectangle in not draw where I click.

 

You want GetPt before creating the rectangle, otherwise your point will awakes be 0,0.  Here is what you want:

result:=RunLayoutDialog(id,mDialogo);

IF result = 1 THEN BEGIN
    GetPt(pX, pY);
    Rect(pX-LAR/2, pY-ALT/2, pX+LAR/2, pY+ALT/2);
END;

 

  • Like 1
Link to comment

I need more help, if someone can assist me.

Going further I was trying whit radio boxes to draw a rectangle or an oval at the mouse ckick, but I can't make it work.

That is what I am doing, what is wrong or missing?

 

PROCEDURE EsteScript;

VAR
    ALT, LAR, AltR, LarR, AltO, LarO :INTEGER;
    pX, pY :REAL;
    id, result :LONGINT;
    
PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);

BEGIN
    CASE item OF
        SetupDialogC: BEGIN
            END;
            1: BEGIN
            IF GetEditInteger(id,6,AltR)
            AND GetEditInteger(id,8,LarR) THEN
            ALT:=AltR;
            LAR:=LarR;
            IF GetEditInteger(id,11,AltO)
            AND GetEditInteger(id,13,LarO) THEN
            ALT:=AltO;
            LAR:=LarO;
            END;
            2: BEGIN
            END;
        END;
    END;
BEGIN
    id:=CreateLayout('Retângulo ou Oval',FALSE,'OK','Cancel');
                
        CreateRadioButtonGroupBox(id,4,'Retângulo',TRUE);
        SetFirstLayoutItem(id, 4);
        CreateStaticText(id,5,'Altura:',8);
        SetFirstGroupItem(id, 4, 5);
        CreateEditInteger(id,6,0,6);
        SetRightItem(id,5,6,0,0);
        CreateStaticText(id,7,'Largura:',8);
        SetBelowItem(id, 5, 7, 0, 0);
        CreateEditInteger(id,8,0,6);
        SetRightItem(id,7,8,0,0);
        
        CreateRadioButtonGroupBox(id,9,'Oval',TRUE);
        SetRightItem(id,4,9,0,0);
        CreateStaticText(id,10,'Altura:',8);
        SetFirstGroupItem(id, 9, 10);
        CreateEditInteger(id,11,0,6);
        SetRightItem(id,10,11,0,0);
        CreateStaticText(id,12,'Largura:',8);
        SetBelowItem(id, 10, 12, 0, 0);
        CreateEditInteger(id,13,0,6);
        SetRightItem(id,12,13,0,0);

    result:=RunLayoutDialog(id,Dialog_Handler);


    IF result = 1 THEN BEGIN
    GetPt(pX, pY);
    Rect(pX-LAR/2, pY-ALT/2, pX+LAR/2, pY+ALT/2);
    Oval(pX-LAR/2, pY-ALT/2, pX+LAR/2, pY+ALT/2);
    END;
END;

RUN (EsteScript);

Link to comment

Olá Eduardo,

 

   In your code for the  OK button (where item = 1), you have 4 statements where you really want 2. I've numbered them here:

			1: BEGIN
{1}				IF GetEditInteger(id, 6, AltR)
				AND GetEditInteger(id, 8, LarR) THEN
					ALT := AltR;
				
{2}				LAR := LarR;
				
{3}				IF GetEditInteger(id, 11, AltO)
				AND GetEditInteger(id, 13, LarO) THEN
					ALT := AltO;
					
{4}				LAR := LarO;
			END;

 

The structure you are trying to achieve requires more BEGIN / END statements, as such:

			1: BEGIN
{1}				IF GetEditInteger(id, 6, AltR)
				AND GetEditInteger(id, 8, LarR) THEN BEGIN
					ALT := AltR;
					LAR := LarR;
				END;		{ first IF }
				
{2}				IF GetEditInteger(id, 11, AltO)
				AND GetEditInteger(id, 13, LarO) THEN BEGIN
					ALT := AltO;	
					LAR := LarO;
				END;		{ second IF }
				
			END;		{ OK button }

BUT... This won't work either, as both IF statements will evaluate to TRUE (even the boxes you don't type into will return 0) and ALT and LAR will have AltO and  LarO in them.

 

To get the right set of values into ALT and LAR you will have to test the RADIO BUTTONS, as such:

VAR
...
	RectOval, Boo :BOOLEAN;		{ add these to your global variable list }

...
			1: BEGIN		{ OK button code }
				GetBooleanItem(id, 4, RectOval);		{ get RADIO BUTTON selection }
				
				IF RectOval THEN BEGIN				{ test RADIO BUTTON selection here }
					Boo := GetEditInteger(id, 6, ALT);
					Boo := GetEditInteger(id, 8, LAR);
				END		{ Rectangle }
				ELSE BEGIN
					Boo := GetEditInteger(id, 11, ALT);
					Boo := GetEditInteger(id, 13, LAR);
				END;		{ Oval }
				
			END;		{ OK button }

Note: I do not have to test Radio Button 9, since the dialog handler makes sure the buttons are in opposite states, and both buttons cannot be TRUE at the same time. Testing RADIO BUTTON 4 implies the state of RADIO BUTTON 9 will be in the opposite state RADIO BUTTON 4.

 

 

LASTLY, after you exit your dialog, you need to decide which object to draw. Again, test the global variable RectOval to draw the right shape, like this:

	IF (result = 1) THEN BEGIN
		GetPt(pX, pY);
		if RectOval then
			Rect(pX-LAR/2, pY-ALT/2, pX+LAR/2, pY+ALT/2)
		else
			Oval(pX-LAR/2, pY-ALT/2, pX+LAR/2, pY+ALT/2);
    END;

 

For a robust script, you should add code to handle what to do if bad data is entered into one of the INTEGER fields, but for the most part this should get you up and running.

 

Hope to see you back with more questions.

 

Happy scripting,

Raymond

 

Link to comment

I have another question Raymond.

If I am working with Radio Buttons in Tabs how I control them?
Got to check which TAB is selected an which Radio Button in that TAB is selected?
Something like:

1: BEGIN {ok button}
GetBooleanItem(id, This TAB, TAB_1);
    IF TAB_1 THEN BEGIN {Left TAB is selected}
        GetBooleanItem(id, This Radio Button, RB_1);
            IF RB_1 THEN BEGIN {One Radio Button in this TAB is selected}
                Boolean:= GetEditInteger(This Field data input);
                Boolean:= GetEditInteger(This Field data input);
            END
            ELSE BEGIN {Use the other Radio Button in this TAB}
                Boolean:= GetEditInteger(This Field data input);
                Boolean:= GetEditInteger(This Field data input);
            END
    END
    ELSE BEGIN {Use the Right TAB}
        GetBooleanItem(id, This Radio Button, RB_1);
            IF RB_1 THEN BEGIN {One Radio Button in this TAB is selected}
                Boolean:= GetEditInteger(This Field data input);
                Boolean:= GetEditInteger(This Field data input);
            END
            ELSE BEGIN {Use the other Radio Button in this TAB}
                Boolean:= GetEditInteger(This Field data input);
                Boolean:= GetEditInteger(This Field data input);
            END
    END
END;
AND?

Link to comment

Eduardo,

  Create a GROUP for each set of Radio Buttons.

 

CreateGroupBox(dialogID :LONGINT; itemID :LONGINT; text :STRING; hasFrame :BOOLEAN);

 

The dialog mechanism will treat the radio buttons in each group as individual sets and toggle them independently of each other. Here's a quick example, 

PROCEDURE ExampleRadioButtonGroups;
{ Example of Radio Button groups in a Modern Dialog. }
{ Radio Buttons placed within a Modern Dialog act as single set. To have }
{ multiple sets of Radio Buttons, place each set in its own GroupBox. }
{  }
{ This script does nothing but toggle 4 sets of radio buttons independently. }
{ The indentation used in this code is not necessary, but only shows the }
{ logical grouping of the dialog elements. }
{ 01 Sep 2018 - Raymond J Mullin }

VAR
	id, result :LONGINT;


	PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);
	BEGIN
	END;		{ Dialog_Handler }


BEGIN
	id := CreateLayout('Radio Button Groups', FALSE, 'OK', 'Cancel');
							
        CreateRadioButtonGroupBox(id, 4, 'Retângulo', TRUE);
		CreateGroupBox(id, 5, 'Group 1', FALSE);
		CreateRadioButton(id, 6, 'RB 1');
		CreateRadioButton(id, 7, 'RB 2');
		CreateRadioButton(id, 8, 'RB 3');
		CreateRadioButton(id, 9, 'RB 4');

		CreateGroupBox(id, 10, 'Group 2', FALSE);
		CreateRadioButton(id, 11, 'RB 5');
		CreateRadioButton(id, 12, 'RB 6');
		CreateRadioButton(id, 13, 'RB 7');
		CreateRadioButton(id, 14, 'RB 8');

        CreateRadioButtonGroupBox(id, 15, 'Oval', TRUE);
		CreateGroupBox(id, 16, 'Group 3', TRUE);
		CreateRadioButton(id, 17, 'RB A');
		CreateRadioButton(id, 18, 'RB B');
		CreateRadioButton(id, 19, 'RB C');
		CreateRadioButton(id, 20, 'RB D');

		CreateGroupBox(id, 21, 'Group 4', TRUE);
		CreateRadioButton(id, 22, 'RB E');
		CreateRadioButton(id, 23, 'RB F');
		CreateRadioButton(id, 24, 'RB G');
		CreateRadioButton(id, 25, 'RB H');


		SetFirstLayoutItem(id, 4);			{ RadioButtonGroupBox 1 }
			SetFirstGroupItem(id, 4, 5);			{ GroupBox  1 }
				SetFirstGroupItem(id, 5, 6);	
					SetBelowItem(id, 6, 7, 0, 0);
					SetBelowItem(id, 7, 8, 0, 0);
					SetBelowItem(id, 8, 9, 0, 0);
		
			SetRightItem(id, 5, 10, 0, 0);			{ GroupBox  2 }
				SetFirstGroupItem(id, 10, 11);
					SetBelowItem(id, 11, 12, 0, 0);
					SetBelowItem(id, 12, 13, 0, 0);
					SetBelowItem(id, 13, 14, 0, 0);
					
		SetRightItem(id, 4, 15, 0, 0);			{ RadioButtonGroupBox 2 }
			SetFirstGroupItem(id, 15, 16);			{ GroupBox  3 }
				SetFirstGroupItem(id, 16, 17);	
					SetBelowItem(id, 17, 18, 0, 0);
					SetBelowItem(id, 18, 19, 0, 0);
					SetBelowItem(id, 19, 20, 0, 0);
		
			SetRightItem(id, 16, 21, 0, 0);			{ GroupBox  4 }
				SetFirstGroupItem(id, 21, 22);
					SetBelowItem(id, 22, 23, 0, 0);
					SetBelowItem(id, 23, 24, 0, 0);
					SetBelowItem(id, 24, 25, 0, 0);
					
	result := RunLayoutDialog(id, Dialog_Handler);

	IF (result = 1) THEN BEGIN
	END;
END;
RUN (ExampleRadioButtonGroups);

 

Have fun,

Raymond

 

Link to comment

Raymond, in this exemple there are groups of 4 Radio Button, how to handle them? With 2 if one is selected the other is not, with 4 each of them has to be checked with GetBooleanItem(id, this RB id, This Boolean); if it is true then do something?

And how to retrieve data from the RB's 1, 7, A and H presuming they have an input data (an edit integer) to use them in some calculation?

Link to comment

Eduardo, 

   You can construct any grouping you want. The two RadioButtonGroupBoxes split your dialog in half. If you want all four groups active at once, then don't use RadioButtonGroupBoxes. Use GroupBoxes instead. One GroupBox for each set of buttons that need to toggle independently from the others. Remember, only one RadioButton can be set in one group at one time. The dialog handler will take care of turning them off as you turn others on. Only you know how many groups you need. That is part of designing the dialog. Sketch it out on paper first if that helps you visualize it.

 

   To read a RadioButton's state, use GetBooleanItem(). If you want independent operation of all the buttons, perhaps you want to use CheckBoxes instead. With CheckBoxes, more than one can be set at a time. You also read them with GetBooleanItem(). 

 

HTH,

Raymond

Link to comment

Raymond, I'm just studying.

What I'm trying is to draw 2 rectangles or 2 ovals. And I want to control the distance between them or the distance they are in.

So I will have formulas like

Rect or Oval(pX-LAR-ESP/2, pY-ALT/2, pX-ESP/2, pY+ALT/2);

Rect or Oval(pX+ESP/2, pY-ALT/2, pX+LAR+ESP/2, pY+ALT/2);

Or

Rect or Oval(pX-TAM/2, pY-ALT/2, pX-TAM/2+LAR, pY+ALT/2);

Rect or Oval(pX+TAM/2-LAR, pY-ALT/2, pX+TAM/2, pY+ALT/2);

Is it possible to do?

TIA

Eduardo

Screen Shot 2018-09-03 at 07.21.41 PM.png

Link to comment

Raymond, I did it! At least it works.

Here is it:

 

PROCEDURE EsteScript;

VAR
    ESP, TAM, ALT, LAR :INTEGER;
    pX, pY :REAL;
    EouT, RouO, Boo :BOOLEAN;
    id, result :LONGINT;
    
PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);

BEGIN
    CASE item OF
        SetupDialogC: BEGIN
            END;
            1: BEGIN
            GetBooleanItem(id, 5, EouT);
            IF EouT THEN BEGIN
            Boo:= GetEditInteger(id,6,ESP);
            END
            ELSE BEGIN
            Boo:= GetEditInteger(id,8,TAM);
            END;
            GetBooleanItem(id, 10, RouO);
            IF RouO THEN BEGIN
            Boo:= GetEditInteger(id,12,ALT);
            Boo:= GetEditInteger(id,14,LAR);
            END
            ELSE BEGIN
            Boo:= GetEditInteger(id,17,ALT);
            Boo:= GetEditInteger(id,19,LAR);
            END;
            END;
            2: BEGIN
            END;
        END;
    END;

BEGIN
    id:=CreateLayout('Teste',FALSE,'OK','Cancel');
                
        CreateGroupBox(id,4,'Espaçamento ou Tamanho',True);
        SetFirstLayoutItem(id, 4);
        CreateRadioButtonGroupBox(id,5,'Espaçamento',TRUE);
        SetFirstGroupItem(id, 4, 5);
        CreateEditInteger(id,6,0,6);
        SetFirstGroupItem(id, 5, 6);
        CreateRadioButtonGroupBox(id,7,'Tamanho',TRUE);
        SetRightItem(id,5,7,0,0);
        CreateEditInteger(id,8,0,6);
        SetFirstGroupItem(id, 7, 8);
        
        CreateGroupBox(id,9,'Retângulo ou Oval',TRUE);
        SetBelowItem(id, 4, 9, 0, 0);
        CreateRadioButtonGroupBox(id,10,'Retângulo',TRUE);
        SetFirstGroupItem(id, 9, 10);
        CreateStaticText(id,11,'Altura:',8);
        SetFirstGroupItem(id, 10, 11);
        CreateEditInteger(id,12,0,6);
        SetRightItem(id,11,12,0,0);
        CreateStaticText(id,13,'Largura:',8);
        SetBelowItem(id, 11, 13, 0, 0);
        CreateEditInteger(id,14,0,6);
        SetRightItem(id,13,14,0,0);
        CreateRadioButtonGroupBox(id,15,'Oval',TRUE);
        SetRightItem(id,10,15,0,0);
        CreateStaticText(id,16,'Altura:',8);
        SetFirstGroupItem(id, 15, 16);
        CreateEditInteger(id,17,0,6);
        SetRightItem(id,16,17,0,0);
        CreateStaticText(id,18,'Largura:',8);
        SetBelowItem(id, 16, 18, 0, 0);
        CreateEditInteger(id,19,0,6);
        SetRightItem(id,18,19,0,0);
        
    result:=RunLayoutDialog(id,Dialog_Handler);
    
    IF result = 1 THEN BEGIN
    GetPt(pX, pY);
    IF EouT THEN BEGIN
    
        IF RouO THEN BEGIN
        Rect(pX-LAR-ESP/2, pY-ALT/2, pX-ESP/2, pY+ALT/2);
        Rect(pX+ESP/2, pY-ALT/2, pX+LAR+ESP/2, pY+ALT/2);
        END
        ELSE BEGIN
        Oval(pX-LAR-ESP/2, pY-ALT/2, pX-ESP/2, pY+ALT/2);
        Oval(pX+ESP/2, pY-ALT/2, pX+LAR+ESP/2, pY+ALT/2);
        END
        END
    
    ELSE BEGIN
    
        IF RouO THEN BEGIN
        Rect(pX-TAM/2, pY-ALT/2, pX-TAM/2+LAR, pY+ALT/2);
        Rect(pX+TAM/2-LAR, pY-ALT/2, pX+TAM/2, pY+ALT/2);
        END
        ELSE BEGIN
        Oval(pX-TAM/2, pY-ALT/2, pX-TAM/2+LAR, pY+ALT/2);
        Oval(pX+TAM/2-LAR, pY-ALT/2, pX+TAM/2, pY+ALT/2);
        END
        END;
    END;
END;

RUN (EsteScript);

Link to comment

Congratulations, Eduardo. Your persistence has definitely paid off. If you continue scripting you will find you can make wonderfully custom tools that work exactly the way you want them. For me, the scripting facet of VW is its most important asset. When you use something again, it pays dividends on all the effort you put into it.

 

All the very best,

Raymond

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...