Enabling and Disabling Tiles in DCL

Enabling and Disabling Tiles in DCL

Anonymous
Not applicable
3,454 Views
21 Replies
Message 1 of 22

Enabling and Disabling Tiles in DCL

Anonymous
Not applicable
Dear pbejse,
Can you please check my attached lisp and DCL file .... It also has the same problem not working for first time.. but ok in 2nd time...

when selecting radio button "yes", edit box "clear height" must highlight but it's not.. Hope you help definitely..
0 Likes
Accepted solutions (3)
3,455 Views
21 Replies
Replies (21)
Message 2 of 22

doaiena
Collaborator
Collaborator

This style of coding is just a nightmare. It would be impossible to edit and maintain. I don't have the time, nor patience to go through such code, but i can give you some general advice.


- when you have repeating actions, you are better off creating a list of variables and apply the action in a loop. Or you can create a function, that accepts a list as an input, or use mapcar and lambda if you don't need a function

- "cond" is used when you have multiple options to choose from. When you have only one option, you should use "if"

- shorten the code by removing unnecessary lines:
(action_tile "rbd" "(setq rbd $value)")
(setq rbd (atof rbd))

can be written as:

(action_tile "rbd" "(setq rbd (atof $value))")

 

- localize your variables and give them meaningfull names (el51 and p92 mean nothing to me in the ocean of variables, which makes future edits harder)

 

- save and restore user settings, when you need to change them (snap, ortho ...)

 

And again, most importantly, learn how to use loops. If you have the same operation over and over again, or even similar operations, you can often group them in a single loop. It would greatly reduce the size of your code and make it editable. I'm sure that your 730 lines of code can be shrunk to 30-40 lines.

0 Likes
Message 3 of 22

pbejse
Mentor
Mentor

@doaiena wrote:

This style of coding is just a nightmare. It would be impossible to edit and maintain. I don't have the time, nor patience to go through such code..


@doaiena

Thank you for your valuable input and suggestions. 

Notice that other posters are just asking for a lisp code without even trying to write one, so don't be too hard on the OP  doaien.

 

As for the OP, please be patient and try not to double post, 

 

 

0 Likes
Message 4 of 22

doaiena
Collaborator
Collaborator

It wasn't my intention to be hard on the OP. I'm sorry if it sounded that way. My frustration was aimed at the style of coding. I myself was doing the same thing when i started coding and i've wasted countless hours of my life trying to maintain that type of code.

I applaud @Anonymous's effort and i wanted to give some advices on how to change his style of coding.

0 Likes
Message 5 of 22

pbejse
Mentor
Mentor

@doaiena wrote:

It wasn't my intention to be hard on the OP...  i wanted to give some advices on how to change his style of coding.


That's good to know. thumbsup.gif

 

 

0 Likes
Message 6 of 22

Anonymous
Not applicable
Thank you so much... It's my first lisp with dialogue boxes...In lisp count it is number 3 so please understand I wanna learn everything step by step slowly and steadily that is the only reason... Thank you so much for ur suggestions and hope you help me a lot
in future
0 Likes
Message 7 of 22

Anonymous
Not applicable
Can I really shrink that code into 30 to 40lines... Ohh no I definitely need ur advice...
0 Likes
Message 8 of 22

Anonymous
Not applicable

@doaiena Please, tell me the solution for my problem and give some ideas.. If you don't mind...I stopped at my problem.

0 Likes
Message 9 of 22

ВeekeeCZ
Consultant
Consultant
Accepted solution

Hi, I've tried that make it work. You'll never short it down to 40 lines. Maybe 200. The drawing is too complex.

 

-  fix your program, there is a lot of places where you compare string to real. Eg.

 (COND ((= EBD "16") (SETQ OST 230) (SETQ OB 70)))

16 must be real or integer.

 

- Be aware that a dividing between two integers is still integer. (/ 10 2) = 4 !! In most cases in your program you have at least one real. So you're good to go.  But if you're not sure, better make the integer real: (/ var 2.) (see the dot, now this is a real and you're save). This (FLOAT(/ WIDTH 2)) is unnecesary since the width is a real: (SETQ WIDTH (ATOF WIDTH)). So 2 can be an integer, but I usually use 2. anyway - no need to ever thing about it.

 

- Since you have such a monster DCL to input your data, you may consinder to adjust your program to allow a "testing" mode to be possible run without dcl.

eg. 

(or EBD  ; if you cancel DCL (= nil)

       (setq EBD "40"))  ; set EBD

 

- you're using the (cond) function wrong way. You may use the (or) function, or better the (member). Sorry for a screenshot, I've been experiencing some difficulties.

image.png

 

 

- If the program works for you, I would probrably not bother to re-write it. But if I do, I would probably pick 5 major points and all the parts calculate using just those. And you should solve one part after another and clearly separate it (describe). 

 

- as a programmer, you should test the input values and not allow values out of valid range!!!

 

- sorry to not answering your question (don't know dcl much)

 

Message 10 of 22

doaiena
Collaborator
Collaborator
Accepted solution

I didn't go through the whole code, but mostly the DCL part. I've also set default values, so if the others want to help you with the code, they can get it started easily.

Have in mind that the variables are still NOT localized and there is no error trap.

0 Likes
Message 11 of 22

pbejse
Mentor
Mentor

@doaiena wrote:

I didn't go through the whole code, but mostly the DCL part. I've also set default values, so if the others want to help you with the code, they can get it started easily....


Nice work doaiena. beer.gif

 

0 Likes
Message 12 of 22

Anonymous
Not applicable
@doaiena thank you so much...I will try it..
0 Likes
Message 13 of 22

pbejse
Mentor
Mentor

So how did it go deepakcad15? Did it work for you?

 

0 Likes
Message 14 of 22

Anonymous
Not applicable

NOPE..  😞 

I wanna disable clear height tile, when selecting NO radio button that's not working ... Initially that was only problem... 

0 Likes
Message 15 of 22

doaiena
Collaborator
Collaborator
Accepted solution

Here is a quick fix for that.

0 Likes
Message 16 of 22

scot-65
Advisor
Advisor

@Anonymous wrote:

NOPE..  😞 

I wanna disable clear height tile, when selecting NO radio button that's not working ... Initially that was only problem... 


When working with mode_tile and radio_buttons, one has to work with all radio_buttons.

This involves using action_tile for all radio_buttons (in a group).

 

I have not the chance to view your code.

I will assume the "clear height tile" is an edit_box?

 

Here is a simplified example block of code (using 3 radio buttons and 1 edit box):

 ...new_dialog
;*** Initialize Section ***
;*** Set Tile Section ***
(set_tile "Rad00" "Rad01") ;<-- Rad00 is the key of the container [radio_column]
(set_tile "Edi01" "")
;*** Mode Tile Section ***
(mode_tile "Edi01" 1)
;*** Action Tile Section ***
(action_tile "Rad01" "(MyMode 1)")
(action_tile "Rad02" "(MyMode 0)")
(action_tile "Rad03" "(MyMode 0)")
...
...start_dialog

Where:

(defun MyMode ( a / )
 (mode_tile "Edi01" a)
);end

As far as your first post "works the second time around", it seems as if you

are not properly initializing the tiles (located between the new_dialog and

the start_dialog statements). If you do not want certain tiles initialized,

then initialize them as mode_tile = 1 and provide a action_tile somewhere

that will make mode_tile = 0 as well as initializing the tile.

 

Again, I am guessing.

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 17 of 22

scot-65
Advisor
Advisor

depakcad15,

 

I took the liberty of running thru the DCL code.

There are a few advanced tricks to reduce the character count.

If you want to learn by example, then this might tickle your fancy...

// constants
swh0 :spacer {width=0.0; height=0.0;}
swh1 :spacer {width=1.0; height=1.0;}
ebx2 :edit_box {edit_width=2;}
ebx3 :edit_box {edit_width=3;}
ebx4 :edit_box {edit_width=4;}
ebx6 :edit_box {edit_width=6;}
//
PEB1
:dialog {label="Place Name of Program Here";
 swh0;
 :text {label="Please fill out the following information"; alignment=centered;}
 swh0;
 :row {
  :column {
   :boxed_column {label="Clear Height";
    :row {
     :toggle {key="CLR"; label=" Clear Height Required";}
     :ebx6 {key="CHT";}
    }
    swh0;
   }
   :boxed_column {label="Base";
    :ebx6 {key="W"; label="WIDTH OF THE BUILDING:";}
    :ebx6 {key="H"; label="HEIGHT OF THE BUILDING:";}
    :ebx3 {key="S"; label="SLOPE OF THE BUILDING (I in.):";}
    :ebx3 {key="P"; label="PURLIN DEPTH:";}
    :ebx3 {key="G"; label="GIRT DEPTH:";}
    swh0;
   }
  }
  :boxed_column {label="Built Up";
   :ebx4 {key="CW";  label="MAJOR COLUMN WEB DEPTH:";}
   :ebx4 {key="MCW"; label="MINOR COLUMN WEB DEPTH:";}
   :ebx2 {key="CFT"; label="COLUMN FLANGE THICK:";}
   :ebx4 {key="RW";  label="RAFTER WEB DEPTH:";}
   :ebx2 {key="RFT"; label="RAFTER FLANGE THICK:";}
   :ebx2 {key="EST"; label="EAVE SPLICE THICK:";}
   :ebx2 {key="RST"; label="RIDGE SPLICE THICK:";}
   swh0;
  }
  :column {
   :boxed_column {label="Extra";
    :ebx4 {key="BPW"; label="BASE PLATE WIDTH:";}
    :ebx4 {key="BPT"; label="BASE PLATE THICK:";}
    :ebx2 {key="BBD"; label="BASE BOLT DIA.:";}
    :ebx2 {key="EBD"; label="EAVE BOLT DIA.:";}
    :ebx2 {key="RBD"; label="RIDGE BOLT DIA.:";}
    swh0;
   }
   swh1;
   ok_cancel;
   swh0;
  }
 }
}
//

Test-PEB1.jpg

 

Character count went from 2836 to 1657 - a reduction of almost 42%!

I did make changes to the radio buttons and replaced with a toggle.

 

The copy of your DCL file did not have the carriage return on the last line

(making the cursor go to the next line, which is blank).

This has been known to cause problems. I usually end my code with

the comment symbol "//" just to be sure.

 

Where there are radio buttons, one must wrap these buttons inside a

radio row or column container. By assigning a key to the container,

one can now "talk" to the buttons (set_tile and get_tile).

 

Labels are typically of varying length. Referencing the key when short

term memory is failing, locate "key=" as the first attribute of the tile.

 

Hope this helps.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 18 of 22

scot-65
Advisor
Advisor

deepakcad15,


I see that many of the edit_boxes (if not all) can be changed
to a popup_list. The concern here is to limit user input
errors when manipulating the dialog.

As a continuation for the change from radio buttons to a toggle,
here is the corresponding mode_tile switching:

 (action_tile "CLR" "(mode_tile \"CHT\" (- 1 (atoi $value)))")

 

However, one may want to take it to the next level...

 (action_tile "CLR" "(MyMode1 $value)")


Where:

(defun MyMode1 ( val / )
 (mode_tile "CHT" (- 1 (atoi val)))
 (if (= val "1")
  (mode_tile "CHT" 2)
 );if
);end


Don't forget to initialize all tiles (via LSP) and mode_tile "CHT" as well.

Don't bother trying to initialize tiles inside the DCL.
It is cause for headaches further down the road...

 

Hope this helps.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 19 of 22

Anonymous
Not applicable

@scot-65

what's the use of (rtos 0 2 0) in this case...

 

 

 

(setq rmks (get_tile "jo"))

(action_tile "be" "(setq rmks (rtos 0 2 0))")

0 Likes
Message 20 of 22

Anonymous
Not applicable

both jo and be tiles are radio buttons

0 Likes