Jump to content

Loop? While


j_spawn_h

Recommended Posts

I think I know I need the "while" but not sure where to put it and what I am missing for it to work. I tried a few places but nothing seems to be right. I looked at all the other posts and sites. I understand what it does but I must not be using it correctly. I want it to repeat the drawing and labeling the beam until I exit.

 

 

;Version 1.02
(defun C:bd(/ width depth membr suffix suffixs prx tsz dpth wdth label label2 label1)

(setq     lsttsz ' ("11x17" "24x36")
         lstmembr '("Flush Beam" "Header/Drop Beam")
         lstprx '("1 ply" "2 ply" "3 ply")
         lstwidth '("1.5" "1.75" "3" "3.5" "4.5" "5.25" "7" "2.5")
         lstdepth '("5.5" "6" "7.25" "8" "9.25" "9.5" "10" "11.25" "11.875" "12" "14" "16" "18" "24")
         lstsuffix '("PSL" "LVL" "LSL")
  lstsuffixs '("FRB" "UWA" "UCA" "nothing"));end setq

(or tsz (setq tsz (car lsttsz))) 
(or membr (setq membr (car lstmembr)))
(or prx (setq prx (car lstprx)))
(or width (setq width (car lstWidth)))
(or depth (setq depth (car lstDepth)))
(or suffix (setq suffix (car lstsuffix)))
(or suffixs (setq suffixs (car lstsuffixs)))

(setq dcl_id (load_dialog "beam.dcl"))                      
(if (not (new_dialog "beam" dcl_id)) (exit))                        
   (progn
       (set_tile tsz "1")
       (set_tile membr "1")
       (set_tile prx "1")
       (set_tile width "1")
       (set_tile depth "1")
       (set_tile suffix "1")
       (set_tile suffixs "1")
     (action_tile "tsz" "(setq tsz $value)")
     (action_tile "membr" "(setq membr $value)")
     (action_tile "prx" "(setq prx $value)")
     (action_tile "width" "(setq width $value)")
     (action_tile "depth" "(setq depth $value)")
     (action_tile "suffix" "(setq suffix $value)")
     (action_tile "suffixs" "(setq suffixs $value)"));end progn

       (start_dialog)
       (unload_dialog dcl_id)

;;;----set variables -------------------------------------
 ;(setvar expert 1)
 (setq layerset (getvar "clayer")
orthoset (getvar "orthomode")
polyset  (getvar "plinewid")
);setq
;------------What size text for border  -------------------
(if(= tsz "11x17") (setq tsz1 "6"))
(if(= tsz "24x36")(setq tsz1 "4.5"))

;------------Which layer it draws the beam on-------------------
(if(= membr "Flush Beam") (setq layer_name "S-FRM-BEAM"))
(if(= membr "Header/Drop Beam")(setq layer_name "S-FRM-HEADER"))
 (command "expert" "1" "")
;-------------Creat layers for beam-------------------------------  
(command "_.layer" "M" layer_name "c" "12" layer_name "S" layer_name "")

;-----------------draw beams -------------------------  
 (command "pline" pause "w" width width pause "")
;----------change thickness of polyline----------------  
 (command "chprop" "l" "" "t" depth "")
;----------change text size and style-------------------  
   (command "textsize" tsz1 "")
(command "_.style" "romans" "romans" "0" "0.80" "" "" "" "")
;-------------Creat layers for text-------------------------------  
(command "_.layer" "M" "S-ANNO-TEXT" "c" "1" "S-ANNO-TEXT" "S" "S-ANNO-TEXT" "")

(and (setq ss (ssget "L" '((0 . "*polyline"))))
       (while (setq en (ssname ss 0))
           (setq ed (entget en))
           (setq p10 (cdr (assoc 10 ed)))
           (setq p9 (reverse ed))
           (setq p11 (cdr (assoc 10 p9)))
          (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
           (setq ltype (cdr (cond
    ((assoc 6 ed)))))
           (setq dpth (cdr (cond
    ((assoc 39 ed)))))
           (setq wdth (cdr (cond
    ((assoc 40 ed)))))

;---------How many plys the member has----------
(cond 
    ((= prx "1 ply") (and (< width "1.75")(setq label2 "")))
    ((= prx "2 ply")(setq label2 "2~"))
    ((= prx "3 ply")(setq label2 "3~")));end cond
;----------Width of the member---------       
(cond
    ((= wdth 1.5)(setq label "2x"
      suffix ""))
    ((= wdth 1.75)(setq label "1.75x"))
    ((= wdth 2.5)(setq label "I-JOIST/BEAM"
                     label2 ""
       dpth 0
       suffix ""))
    ((= wdth 3)(setq label "2x"
     suffix "" ))       
    ((= wdth 3.5)(setq label "3.5x"
       label2 ""))
    ((= wdth 4.5)(setq label "2x"
       suffix ""))
    ((= wdth 5.25)(setq label "5.25x"
        label2 ""))
    ((= wdth 7)(setq label "7x"
     label2 "")));end cond
;----------Depth of the Member-------------       
(cond
 ((= dpth 5.5)(setq label1 (rtos dpth 2 1)))
 ((= dpth 6)(setq label1 (rtos dpth 2 0)))
 ((= dpth 7.25)(setq label1 (rtos dpth 2 2)))
 ((= dpth 9.25)(setq label1 (rtos dpth 2 2)))
 ((= dpth 9.5)(setq label1 (rtos dpth 2 1)))
 ((= dpth (setq label1 (rtos dpth 2 0)))
 ((= dpth 10)(setq label1 (rtos dpth 2 0)))
 ((= dpth 11.25)(setq label1 (rtos dpth 2 2)))
 ((= dpth 12)(setq label1 (rtos dpth 2 0)))
 ((= dpth 11.875)(setq label1 (rtos dpth 2 3)))
 ((= dpth 14)(setq label1 (rtos dpth 2 0)))
 ((= dpth 16)(setq label1 (rtos dpth 2 0)))
 ((= dpth 18)(setq label1 (rtos dpth 2 0)))
 ((= dpth 24)(setq label1 (rtos dpth 2 0)))       
 ((= dpth 0)(setq label1 "")));end cond




 (defun radians->degrees (r)(cvunit r "radian" "degree"))

;-------TEXT JUSTIFICATION----------------------------------------     
(setq lan (angle p10 p11))
      (setq ad (radians->degrees lan))
      (if (and (> ad 90.1) (<= ad 270.1)) 
        (progn
          (setq ptemp p10
                p10 p11
                p11 ptemp
                lan (angle p10 p11)  
                ad (radians->degrees lan))))

      (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))


                  (setq r3(entmake (list (cons 0 "TEXT")
                          (cons 8 (getvar "CLAYER"))
                          (cons 7 (getvar "TEXTSTYLE"))
                          (cons 40 (getvar "TEXTSIZE"))
                          (cons 41 0.80)
     (cons 72 4)
            (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
                                   ;(getvar "TEXTSIZE")))))
                          (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
                                  (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
                          (setq gg(cons 50 lan))
                         (setq rg(cons 1 (strcat label2 label label1 suffix suffixs))))))



                  (ssdel en ss)))
;---------------------reset vars-----------
(setvar "clayer" layerset)
(setvar "orthomode" orthoset)  
(setvar "plinewid"  polyset)
(command "expert" "0" "") 


 (princ)
)

 

beam : dialog {
label = "Pick a Member";
     : row {
       : boxed_radio_row {key = "tsz";
         label = "Text Size";
         : radio_button {
           label = "11x17";
           key = "11x17";
         }
         : radio_button {
           label = "24x36";
           key = "24x36";
           }}} 
     : row {
       : boxed_radio_row {key = "membr";
         label = "Member";
         : radio_button {
           label = "Flush Beam";
           key = "Flush Beam";
         }
         : radio_button {
           label = "Header/Drop Beam";
           key = "Header/Drop Beam";
           }}}

            : row {
       : boxed_radio_row {key = "prx";
         label = "Preffix";
         : radio_button {
           label = "1 Ply";
           key = "1 ply";
         }

         : radio_button {
           label = "2 Ply";
           key = "2 ply";
         }

         : radio_button {
           label = "3 Ply";
           key = "3 ply";
         }}}


     : row {
       : boxed_radio_row {key = "width";
         label = "Width";
          : radio_button {
           label = "1.5 (SGL 2x)";
           key = "1.5";
         }
         : radio_button {
           label = "1.75";
           key = "1.75";
         }
           : radio_button {
           label = "3 (DBL 2x)";
           key = "3";
         } 
         : radio_button {
           label = "3.5";
           key = "3.5";
         }
          : radio_button {
           label = "4.5 (TPL 2x)";
           key = "4.5";
         }
         : radio_button {
           label = "5.25";
           key = "5.25";
         }
         : radio_button {
           label = "7";
           key = "7";
         }
         : radio_button {
           label = "I-JOIST/BEAM";
           key = "2.5";
         }}}


      : row {
       : boxed_radio_row {key = "depth";
         label = "Depth";
         : radio_button {
           label = "5.5";
           key = "5.5";
         }
          : radio_button {
           label = "2x6";
           key = "6";
         }
         : radio_button {
           label = "7.25";
           key = "7.25";
         }
          : radio_button {
           label = "2x8";
           key = "8";
         }
         : radio_button {
           label = "9.25";
           key = "9.25";
         }

          : radio_button {
           label = "9.5";
           key = "9.5";
         }
          : radio_button {
           label = "2x10";
           key = "10";
         }

         : radio_button {
           label = "11.25";
           key = "11.25";
         }

         : radio_button {
           label = "11.875";
           key = "11.875";
         }
          : radio_button {
           label = "2x12";
           key = "12";
         }          
         : radio_button {
           label = "14";
           key = "14";
         }

         : radio_button {
           label = "16";
           key = "16";
         }

         : radio_button {
           label = "18";
           key = "18";
         }
          : radio_button {
           label = "24";
           key = "24";
         }}}

    : row {
       : boxed_radio_row {key = "suffix";
         label = "Suffix";
         : radio_button {
           label = "PSL";
           key = " PSL";
         }
         : radio_button {
           label = "LVL";
           key = " LVL";
         }
         : radio_button {
           label = "LSL";
           key = " LSL";
         }
         }}
  : row {
       : boxed_radio_row {key = "suffixs";
         label = "Suffixs";
         : radio_button {
           label = "FRB";
           key = " FRB";
         }
           : radio_button {
           label = "UWA";
           key = " UWA";
         }
         : radio_button {
           label = "UCA";
           key = " UCA";
         }
         : radio_button {
           label = "NOTHING";
           key = "";
         }
         }}


     : row {
       : button {
         label = "&OK";
         key = "accept";       
         fixed_width = true;
         is_default = true;
         alignment = centered;
       }  
       : button {
         label = "&Cancel";
         key = "cancel";        
         fixed_width = true;
         is_cancel = true;
         alignment = centered;
       }}

     : paragraph {

      :text_part {
      label = "PTS Inc.";
      alignment = centered;       
      }
       :text_part {
      label = "Version 1.02";
      alignment = centered;       
      }}

}

Link to comment
Share on other sites

;...
       (while (setq en (ssname ss 0))
;...

I'm not too sure of this one. The while basically has a structure like this:
(while condition
 operation1
 operation2
 ...
 operationN
)

If the condition returns anything but nil, then all the operations will be run. Only when the condition=nil does the loop stop.

 

In your example I think the condition never returns nil - so the loop never ends. I think the problem is that you're always extracting the 1st item from the selection set. You should use a counter variable to extract the next, then the next, etc. until there are no more and the ssname --> nil --> stops the while.

Link to comment
Share on other sites

Right at the bottom he/she has:

(ssdel en ss)

Though, this is a very inefficient way to iterate over a Selection Set, since the indexes of all remaining entities must be updated for every entity processed.

Link to comment
Share on other sites

Oh! The indenting threw me a bit. Didn't go count all the parentheses to figure where the loop starts and stops - so when I didn't see it where I expected it to be, I thought that's the issue.

 

Anyhow, to be a bit more clear on what the OP wanted: Do you want the dialog to open each time until you click the Cancel button? Then you may have to get the return value from the start_dialog call and check if 1 - probably add this into the condition portion of the while loop (move the unload_dialog outside right at the end), then continue the while loop around everything else up to just before the reset variables.

 

BTW, you might have to look into error handling since you're setting some sysvars. Especially if you're going to press Esc to "stop" this routine.

Link to comment
Share on other sites

Irnbe,

I would like for the box not to come up again. Just keep drawing and labeling the beams.

 

Lee,

I am new at this so that part of the code I got from someone else here in this forum awhile back. I asked for help with multi labeling a line with its length. So is there away to do this and change that part. And is there a way you could explain it to me so I can do it my self and learn, or is it to much to type? I am hoping one day I can come here and help some one else instead of getting help. I try and do it myself for days before I come and ask for help. I am doing every thing I can to find new material to read and learn from. Like your site, this forums post, other forums, other people sites, and books.

 

Thanks both of y'all for the info I will keep looking for another way.

 

Also I'm a he. lol

Link to comment
Share on other sites

So is there away to do this and change that part. And is there a way you could explain it to me so I can do it my self and learn, or is it to much to type?

 

There are several ways to iterate over all objects in a Selection Set, some methods are more intuitive, others are more efficient.

 

Below I will provide some examples to demonstrate a variety of different methods and I'll try my best to give a brief explanation on how each method works and the efficiency of its operation.

 

And so I present:

 

An Introduction to Selection Set Processing...

By Lee Mac

 

In all of the following examples, the user will be prompted to make a selection of objects and the example program will iterate over the selection set, printing the entity type of each entity, (or object name of the VLA-Object in the case of the Visual LISP example).

 

Many of the examples have been expanded to use several variables for simplicity and readability and could subsequently be shortened by nesting expressions, but that is not the intention of this tutorial.

 

Method 1: while

 

The following function utilises a while loop to iterate over the selection set. A counter variable i is initialised at 0, and a limiting variable n is set to the size of the selection set.

 

The test condition for the while loop will evaluate to T providing the counter is less than the number of items in the set.

 

The counter variable is then sequentially incremented within the while loop, ensuring termination of the loop when all entities have been processed.

 

Note that all selection sets have a zero-based index, and hence the first entity in the selection resides at index 0, with the last entity at index sslength - 1

 

([color=BLUE]defun[/color] c:test1 ( [color=BLUE]/[/color] e i n s x )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] i 0
                 n ([color=BLUE]sslength[/color] s)
           )
           ([color=BLUE]while[/color] ([color=BLUE]<[/color] i n)
               ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color] s i)
                     x ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e)))
                     i ([color=BLUE]1+[/color] i)
               )
               ([color=BLUE]print[/color] x)
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Method 1a: Reverse while

 

This example uses the same logic as the preceding example, except the counter variable is initialised at the last index in the set, and decremented within the loop until it reaches zero.

 

This approach removes the need for the 'restricting variable' required by the previous example.

 

([color=BLUE]defun[/color] c:test1a ( [color=BLUE]/[/color] e i s x )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] ([color=BLUE]sslength[/color] s)))
           ([color=BLUE]while[/color] ([color=BLUE]<=[/color] 0 i)
               ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color] s i)
                     x ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e)))
                     i ([color=BLUE]1-[/color] i)
               )
               ([color=BLUE]print[/color] x)
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Method 2: repeat

 

The following function also uses a counter variable i which is incremented within the repeat loop to iterate over the set, however, since the number of items in the set can be determined before the loop is executed (using sslength), this more efficient repeat loop may be utilised to iterate over the set a number of times equal to the number of items in the set.

 

Why more efficient? Because there is no longer a test condition to be evaluated on each pass of the loop.

 

([color=BLUE]defun[/color] c:test2 ( [color=BLUE]/[/color] e i n s x )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] i 0
                 n ([color=BLUE]sslength[/color] s)
           )
           ([color=BLUE]repeat[/color] n
               ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color] s i)
                     x ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e)))
                     i ([color=BLUE]1+[/color] i)
               )
               ([color=BLUE]print[/color] x)
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Method 2a: Reverse repeat

 

Analogous to the reversed example of the while loop (Method 1a), this rather more concise (but perhaps less readable) example will initialise the counter variable i at the number of items in the set, whilst using the return of this setq expression to supply the repeat function with the number of iterations for the loop.

 

The counter variable is then immediately decremented within the loop (so as to start the processing at the (sslength - 1)th entity), and again, the return of this setq expression is supplied to the ssname function.

 

This example has a negligible difference in efficiency to the previous example, but is more concise.

 

([color=BLUE]defun[/color] c:test2a ( [color=BLUE]/[/color] e i s x )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))
           ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))
                 x ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e)))
           )
           ([color=BLUE]print[/color] x)
       )
   )
   ([color=BLUE]princ[/color])
)

Method 3: ssnamex

 

The ssnamex function can be used to return information about how a selection set was collected. This information also includes all of the entity names in the selection.

 

The following example will iterate over the list returned by ssnamex and process the entities contained therein.

 

However, do not be deceived into thinking that this method is efficient simply because it looks more concise than the previous examples...

 

The ssnamex function is process intensive function and is slow to evaluate, furthermore, the foreach loop may iterate a number of times greater than the number of items in the set as the ssnamex function includes additional information about any window selections (or other selection methods) that the user may have used.

 

([color=BLUE]defun[/color] c:test3 ( [color=BLUE]/[/color] s )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
       ([color=BLUE]foreach[/color] e ([color=BLUE]ssnamex[/color] s)
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ([color=BLUE]cadr[/color] e)))
               ([color=BLUE]print[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ([color=BLUE]cadr[/color] e)))))
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Method 4: ssdel

 

This method iterates over a selection set by sequentially removing the first entity from the set and exploiting the inherent behaviour of the selection set.

 

A selection set may be viewed as an array of entities. Each entity occupies a position, or index, in the array, with the first entity occupying index 0.

 

When an entity is removed from the selection set, so as not to have a 'gap' in the array, all entities occupying the positions above the removed entity are shifted down to occupying the lower positions, thus filling the 'gap' created by the removed entity.

 

In this way, there will always be an entity occupying index 0 for as long as the selection set is not empty.

 

However, the process of continually shifting the entities to new indexes in the selection set is unnecessary and largely inefficient and so this method should be avoided when processing selection sets containing many objects.

 

([color=BLUE]defun[/color] c:test4 ( [color=BLUE]/[/color] e s )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
       ([color=BLUE]while[/color] ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color] s 0))
           ([color=BLUE]print[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e))))
           ([color=BLUE]ssdel[/color] e s)
       )
   )
   ([color=BLUE]princ[/color])
)

Method 5: Visual LISP

 

This method is useful when the program needs to operate on the VLA-Object representations of the entities in the selection, and avoids the need to use vlax-ename->vla-object to convert each entity to its associated VLA-Object.

 

The method will retrieve the ActiveSelectionSet Collection from the SelectionSets Collection in the drawing and iterate over the VLA-Objects found therein.

 

Note however, that when using this method, the SelectionSet Object should be deleted from the SelectionSets Collection after use, as there is a limit to the number of SelectionSets permitted in this Collection.

 

([color=BLUE]defun[/color] c:test5 ( [color=BLUE]/[/color] s )
   ([color=BLUE]if[/color] ([color=BLUE]ssget[/color])
       ([color=BLUE]progn[/color]
           ([color=BLUE]vlax-for[/color] o ([color=BLUE]setq[/color] s ([color=BLUE]vla-get-activeselectionset[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))))
               ([color=BLUE]print[/color] ([color=BLUE]vla-get-objectname[/color] o))
           )
           ([color=BLUE]vla-delete[/color] s)
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color])
([color=BLUE]princ[/color])

I hope that this post provides a clear and comprehensible explanation for many of the techniques used to iterate over a Selection Set that you will find in most programs that you encounter.

 

Of course, if you have any questions about the content of this post, please ask and I will try my best to clarify the explanation.

 

Lee

Link to comment
Share on other sites

Irnbe,

I would like for the box not to come up again. Just keep drawing and labeling the beams.

OK, in your supplied code it is a bit difficult to choose a position. You might have to rearrange it a bit. Though I'm still not too sure where you want it to start looping. At a guess though just before you pick the first point for the polyline.

 

To make it easier for yourself, start VLIDE (just type it into acad). Then open the LSP file. Move the cursor to the first (unload_dialog) in that defun and press F9 to place a breakpoint. Load the lisp into the DWG by pressing Ctrl+Alt+E (or Tools --> Load Text in Editor). Swap windows to acad and start the BD command. VLIDE should now open and highlight the portion of the lisp which is executing at the moment when it reaches the breakpoint. Use F8 to step to the next portion of the code ... each time the code is asking for user input it should swap back to the acad window (if not just use Alt+Tab for that). When you think it should start looping you should be very close to the position in that code.

 

Anyhow. I do think however it's not as simple as just wrapping a portion of the code in a while loop. You might have to first obtain a point into a variable using getpoint (note use this as the condition of the while, so you can press Enter/Space to stop) then replace the first pause while drawing the pline with that variable. Also you might want to take the while loop a bit further back to also include the portions which set the relevant layer for the polyline (otherwise the next PL might be drawn on the text layer).

 

Edit: Lee, great explanation. I think that might be a very good tut for your site! I think you've covered all the bases.

Link to comment
Share on other sites

Edit: Lee, great explanation. I think that might be a very good tut for your site! I think you've covered all the bases.

 

Thanks Irné! I shall definitely add it to my site when I get a chance :)

Link to comment
Share on other sites

Wow! I asked for it and boy did I get it. Thank you very much.. I will take that info and study it and see if I can learn how to use it. Man someone is going to think it is Christmas in this Thread..

Link to comment
Share on other sites

  • 3 weeks later...

Ok Lee,

I read your thread and I kinda get it but it seems when I put it to use on this big routine I get lost what is what. I added the while in and it loops, but it does not stop and finish the rest of the routine when I hit enter. And hitting esc gets it out but also does not finish the routine. So big question looking at what I have what am I missing? When I tried a few ways it just stopped looping.

(defun C:bdd (/); width depth membr suffix suffixs prx tsz depth width label label2 label1)

(setq     lsttsz ' ("11x17" "24x36")
         lstmembr '("Flush Beam" "Header" "Drop Beam")
  lstprxs '("CANT" "NOTHING")
         lstprx '("1 ply" "2 ply" "3 ply")
  lstmatrl '("6" "8" "10" "12")
         lstwidth '("1.5" "1.75" "3" "3.5" "4.5" "5.25" "7" "2.5")
         lstdepth '("5.5" "7.25" "9.25" "9.5" "11.25" "11.875" "14" "16" "18" "24" "I-JOIST/BEAM" "BBO")
         lstsuffix '("PSL" "LVL" "LSL")
  lstsuffixs '("FRB" "UWA" "UCA" "NOTHING" " W/ 2~5/8x16 STEEL PLATES (FLITCH BEAM)"));end setq
           
(or tsz (setq tsz (car lsttsz))) 
(or membr (setq membr (car lstmembr)))
(or prxs (setq prxs (car lstprxs)))
(or prx (setq prx (car lstprx)))
(or matrl (setq matrl (car lstmatrl)))  
(or width (setq width (car lstWidth)))
(or depth (setq depth (car lstDepth)))
(or suffix (setq suffix (car lstsuffix)))
(or suffixs (setq suffixs (car lstsuffixs)))
 
(setq dcl_id (load_dialog "linebeam.dcl"))                      
(if (not (new_dialog "linebeam" dcl_id)) (exit))                        
   (progn
       (set_tile tsz "1")
       (set_tile membr "1")
       (set_tile prxs "1")
       (set_tile prx "1")
       (set_tile matrl "1")
       (set_tile width "1")
       (set_tile depth "1")
       (set_tile suffix "1")
       (set_tile suffixs "1")
     (action_tile "tsz" "(setq tsz $value)")
     (action_tile "membr" "(setq membr $value)")
     (action_tile "prxs" "(setq prxs $value)")
     (action_tile "prx" "(setq prx $value)")
     (action_tile "matrl" "(setq matrl $value)")
     (action_tile "width" "(setq width $value)")
     (action_tile "depth" "(setq depth $value)")
     (action_tile "suffix" "(setq suffix $value)")
     (action_tile "suffixs" "(setq suffixs $value)"));end progn
     
       (start_dialog)
       (unload_dialog dcl_id)
   
;;;----set variables -------------------------------------
 
 (setq layerset (getvar "clayer")
orthoset (getvar "orthomode")
polyset  (getvar "plinewid"))
;ex(getvar "expert"));setq
(command "expert" "1")
;------------What size text for border  -------------------
(while 
 (if(= tsz "11x17") (setq tsz1 "6"))
(if(= tsz "24x36")(setq tsz1 "4.5"))
 
;;;;;;;;;------------------------Which layer it draws the beam on----------------------;;;;;;;;;;;;;;;;;;;
(if(= membr "Flush Beam") (progn
;-------------Creat layers for beam-------- 
        (command "_.layer" "M" "S-FRM-BEAM" "c" "12" "S-FRM-BEAM" "S" "S-FRM-BEAM" "")
;-----------------draw beams -------
(command "line" pause pause "")
     (setq ln (ssget "_l" ' ((0 . "ARC,CIRCLE,ELLIPSE,*LINE"))))
        (command "_.offset" "2" ln pause "")
 );end progn
        );end if
 (if(= membr "Drop Beam") (progn
;-------------Creat layers for beam----------- 
        (command "_.layer" "M" "S-FRM-HEADER" "c" "12" "S-FRM-HEADER" "S" "S-FRM-HEADER" "")
;-----------------draw beams --------------- 
(command "line" pause pause "")
     (setq ln (ssget "_l" ' ((0 . "ARC,CIRCLE,ELLIPSE,*LINE"))))
        (command "_.offset" "2" ln pause "")
 );end progn
        );end if
(if (= membr "Header") (progn
;-------------Creat layers for beam------------ 
        (command "_.layer" "M" "S-FRM-HEADER" "c" "12" "S-FRM-HEADER" "S" "S-FRM-HEADER" "")
        (command "_.line" pause pause "")
        );end progn
 );end cond
 
;----------change text size and style-------------------  
   (command "textsize" tsz1 "")
(command "_.style" "romans" "romans" "0" "0.80" "" "" "" "")
;-------------Creat layers for text-------------------------------  
(command "_.layer" "M" "S-ANNO-TEXT" "c" "1" "S-ANNO-TEXT" "S" "S-ANNO-TEXT" "")
   
(and (setq ss (ssget "L" '((0 . "*line"))))
       (while (setq en (ssname ss 0))
           (setq ed (entget en))
           (setq p10 (cdr (assoc 10 ed)))
           (setq p11 (cdr (assoc 11 ed)))
          (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
           ;(setq ltype (cdr (cond
   ; ((assoc 6 ed)))))
           ;(setq depth (cdr (cond
   ; ((assoc 39 ed)))))
           ;(setq width (cdr (cond
   ; ((assoc 40 ed)))))
;---------Prxs ----------
(cond
((= prxs "CANT ")(setq label3 "CANT "))
((= prxs "")(setq label3 ""))
);end cond
;---------How many plys the member has----------
(cond 
    ((= prx "1 ply") (and (< width "1.75")(setq label2 "")))
    ((= prx "2 ply")(setq label2 "2~"))
    ((= prx "3 ply")(setq label2 "3~"))
    
    );end cond
;---------2x material---------------------------
(cond
   ((= matrl "6")(setq label4 "2x6"
  suffix ""));(rtos depth 2 0)))
   ((= matrl "8")(setq label4 "2x8"
  suffix ""));(rtos depth 2 0)))
   ((= matrl "10")(setq label4 "2x10"
   suffix ""));(rtos depth 2 0)))
   ((= matrl "12")(setq label4 "2x12"
   suffix ""));(rtos depth 2 0)))
   ;((= matrl "0")(setq label4 ""))
   );end cond
;----------Width of the member---------       
(cond
    ;((= width "1.5")(setq label "2x"
      ;suffix ""))
    ((= width "1.75")(setq label "1.75x"))
    ((= width "2.5")(setq label "I-JOIST/BEAM"
                     label2 ""
       depth "0"
       suffix ""
  label4 ""))
   ; ((= width "3")(setq label "2x"
     ;suffix "" ))       
    ((= width "3.5")(setq label "3.5x"
       label2 ""
     label4 ""))
    ;((= width "4.5")(setq label "2x"
      ; suffix ""))
    ((= width "5.25")(setq label "5.25x"
        label2 ""
      label4 ""))
    ((= width "7")(setq label "7x"
     label2 ""
   label4 ""))
    ((= width "2")(setq label "BBO"
                     label2 ""
       depth "0"
       suffix ""
   label4 ""))
    ((= width "0")(setq label ""))
    );end cond
;----------Depth of the Member-------------       
(cond
 ((= depth "5.5")(setq label1 "5.5"
  matrl ""));(rtos depth 2 1)))
 
 ((= depth "7.25")(setq label1 "7.25"
   matrl ""));(rtos depth 2 2)))
 ((= depth "9.25")(setq label1 "9.25"
   matrl ""));(rtos depth 2 2)))
 ((= depth "9.5")(setq label1 "9.5"
                        matrl ""));(rtos depth 2 1)))
   ((= depth "11.25")(setq label1 "11.25"
      matrl ""));(rtos depth 2 2)))
 
 ((= depth "11.875")(setq label1 "11.875"
     matrl ""));(rtos depth 2 3)))
 ((= depth "14")(setq label1 "14"
        matrl ""));(rtos depth 2 0)))
 ((= depth "16")(setq label1 "16"
        matrl ""));(rtos depth 2 0)))
 ((= depth "18")(setq label1 "18"
        matrl ""));(rtos depth 2 0)))
 ((= depth "24")(setq label1 "24"
        matrl "")) ;(rtos depth 2 0)))       
 ((= depth "0")(setq label1 ""
       matrl "")));end cond
;(cond
 ;((= suffixs "36")(setq suffixs " W/ 2~5/8x"label1 "STEEL PLATES (FLITCH BEAM)"))
 ;end cond
    
     
  
 (defun radians->degrees (r)(cvunit r "radian" "degree"))
      
;-------TEXT JUSTIFICATION----------------------------------------     
(setq lan (angle p10 p11))
      (setq ad (radians->degrees lan))
      (if (and (> ad 90.1) (<= ad 270.1)) 
        (progn
          (setq ptemp p10
                p10 p11
                p11 ptemp
                lan (angle p10 p11)  
                ad (radians->degrees lan))))
                 
      (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))
          
      
                  (setq r3(entmake (list (cons 0 "TEXT")
                          (cons 8 (getvar "CLAYER"))
                          (cons 7 (getvar "TEXTSTYLE"))
                          (cons 40 (getvar "TEXTSIZE"))
                          (cons 41 0.80)
     (cons 72 4)
            (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
                                   ;(getvar "TEXTSIZE")))))
                          (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
                                  (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
                          (setq gg(cons 50 lan))
                         (setq rg(cons 1 (strcat label3 label2 label label4 label1 suffix suffixs))))))
     
      
       
                  (ssdel en ss)));end and

 );end while
 

;---------------------reset vars-----------
(setvar "clayer" layerset)
(setvar "orthomode" orthoset)  
(setvar "plinewid"  polyset)
 ;(setvar "expert" ex)
(command "expert" "0" "") 
 
  
 
 (princ)
)
(Princ "\nType BDD [Enter] to run. Version:3.00")
(princ)

 

 

 

linebeam : dialog {
label = "Pick a Member" "                          " "Version 3.00";
: row {
     : row {
     fixed_width = true;
       : boxed_radio_row {key = "tsz";
         label = "Text Size";
         : radio_button {
           label = "11x17 (6)";
           key = "11x17";
         }
         : radio_button {
           label = "24x36 (4.5)";
           key = "24x36";
           }}} 
     : row {
     fixed_width = true;
       : boxed_radio_row {key = "membr";
         label = "Type of Member";
         : radio_button {
           label = "Flush Beam";
           key = "Flush Beam";
         }
         : radio_button {
           label = "Drop Beam";
           key = "Drop Beam";
         }
         : radio_button {
           label = "Header";
           key = "Header";
           }}}}
         : row {
                 
              : row {
       : boxed_radio_row {key = "prxs";
         label = "Preffix";
         : radio_button {
           label = "CANT";
           key = "CANT ";
         }
         : radio_button {
           label = "NOTHING";
           key = "";
         }}}
           
        : row {    
       : boxed_radio_row {key = "prx";
         label = "Plys";
           : radio_button {
           label = "1 Ply";
           key = "1 ply";
         }
         : radio_button {
           label = "2 Ply";
           key = "2 ply";
         }
         : radio_button {
           label = "3 Ply";
           key = "3 ply";
         }}}}
    : row {
          : boxed_radio_row {key = "matrl";
         label = "2x Material";
          fixed_width = true;
          : radio_button {
           label = "2x6";
           key = "6";
         }
           : radio_button {
           label = "2x8";
           key = "8";
         }
         : radio_button {
           label = "2x10";
           key = "10";
         }
          : radio_button {
           label = "2x12";
           key = "12";
         }  }}
      : row {   
       : boxed_radio_row {key = "width";
         label = "Width";
          fixed_width = true;
         : radio_button {
           label = "1.75";
           key = "1.75";
         }
         : radio_button {
           label = "3.5";
           key = "3.5";
         }
         : radio_button {
           label = "5.25";
           key = "5.25";
         }
         : radio_button {
           label = "7";
           key = "7";
         }
         : radio_button {
           label = "I-JOIST/BEAM";
           key = "2.5";
         }
         : radio_button {
           label = "BBO";
           key = "2";
         }}}
      : row {
      fixed_width = true;
       : boxed_radio_row {key = "depth";
         label = "Depth";
        : radio_button {
           label = "5.5";
           key = "5.5";
         }
        : radio_button {
           label = "7.25";
           key = "7.25";
         }
        : radio_button {
           label = "9.25";
           key = "9.25";
         }
        : radio_button {
           label = "9.5";
           key = "9.5";
         }          
        : radio_button {
           label = "11.25";
           key = "11.25";
         }          
        : radio_button {
           label = "11.875";
           key = "11.875";
         }
        : radio_button {
           label = "14";
           key = "14";
         }
         : radio_button {
           label = "16";
           key = "16";
         }
         : radio_button {
           label = "18";
           key = "18";
         }
          : radio_button {
           label = "24";
           key = "24";
         }}}
       : boxed_radio_row {key = "suffix";
         label = "Product";
         fixed_width = true;
         : radio_button {
           label = "PSL";
           key = " PSL";
         }
         : radio_button {
           label = "LVL";
           key = " LVL";
         }
         : radio_button {
           label = "LSL";
           key = " LSL";
         }      }
        : row {
        : boxed_radio_row {key = "suffixs";
         label = "Suffix";
         fixed_width = true;
         : radio_button {
           label = "FRB";
           key = " FRB";
         }
           : radio_button {
           label = "UWA";
           key = " UWA";
         }
         : radio_button {
           label = "UCA";
           key = " UCA";
         }
         : radio_button {
           label = "FLITCH BEAM";
           key = " W/ 2~5/8x16 STEEL PLATES (FLITCH BEAM)";
         }
         : radio_button {
           label = "NOTHING";
           key = "";
         }}}
         
         
         
     : row {
     
       : button {
         label = "&OK";
         key = "accept";
         fixed_width = true;
         is_default = true;
         }
         : paragraph {   
      :text_part {
      label = "PTS Inc.";
      fixed_width = true;
      alignment = centered;       
      }
      :text_part{  
      label = "                                                                              "; 
      }}
       : button {
         label = "&Cancel";
         key = "cancel";
         fixed_width = true;
         is_cancel = true;
       }}     
             
}

Link to comment
Share on other sites

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...