Jump to content

Help with text placement.


j_spawn_h

Recommended Posts

This lisp does just what I want. I wrote it and rewrote it until I got it to do what I want. Thanks to the help of you guys here it started from some lisp y'all wrote. What it does is labels poly lines by their width and thickness. The issue I can not solve is to make the text go above the line to clear the text. When I draw a 5.25" or a 7" poly line the text is hidden part way. I tried every thing I knew that could move it but only made it go down or turn.

 

(defun C:bd(/)

(setq     lstWidth '( "1.75" "3.5" "5.25" "7")
       lstDepth '("5.5" "6" "7.25" "8" "9.25" "9.5" "10" "11.25" "11.875" "12" "14" "16" "18" "24")
         lstmembr '("Flush Beam" "Header/Drop Beam")
  lstSuffix '("PSL" "UWA" "UCA" "LVL" "LSL")
  LSTSuffixs '("FRB" "UWA" "UCA")
  lstPreffix '("1 ply" "2 ply" "3 ply"))

(or membr (setq membr (car lstmembr)))
(or preffix (setq preffix (car lstPreffix)))  
(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 membr "1")
       (set_tile preffix "1")
       (set_tile width "1")
       (set_tile depth "1")
       (set_tile suffix "1")
       (set_tile suffixs "1")

      (action_tile "kmembr" "(setq membr $value)")
     (action_tile "kpreffix" "(setq preffix $value)")
     (action_tile "kWidth" "(setq width $value)")
       (action_tile "kDepth" "(setq depth $value)")
     (action_tile "kSuffix" "(setq suffix $value)")
     (action_tile "kSuffixs" "(setq suffixs $value)")
       (start_dialog)
       (unload_dialog dcl_id)
   ))

(if(= membr "Flush Beam") (setq layer_name "S-FRM-BEAM"))

(if(= membr "Header/Drop Beam")(setq layer_name "S-FRM-HEADER"))
;(if (= depth "1")(setq depth ""))  


(command "_.layer" "M" layer_name "c" "12" layer_name "S" layer_name "")
  (command "pline" pause "w" width width pause "")
 (command "chprop" "l" "" "t" depth "")
    (command "textsize" "6" "")
(command "_.style" "jaytxt" "romans" "0" "0.80" "" "" "" "")

(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----------
(if (= preffix "1.5") (and (= wdth 1.75)(setq label2 "2~")))
(if (= preffix "1.5") (and (> wdth 1.75)(setq label2 "2x")))
(if (= preffix "3")(setq label2 "2~2x"))
(if (= preffix "4.5")(setq label2 "3~2x"))
(if (= preffix "1")(setq label2 ""))
;----------Width of the member---------       
(if (= wdth 1.75)(setq label "1.75x"))
(if (= wdth 2.5)(setq label "I-JOIST/BEAM"))       
(if (= wdth 3.5)(setq label "3.5x"))
(if (= wdth 5.25)(setq label "5.25x"))
(if (= wdth 7)(setq label "7x"))
;----------Depth of the Member-------------       
(if (= dpth 5.5)(setq label1 (rtos dpth 2 1)))
(if (= dpth 6)(setq label1 (rtos dpth 2 0)))
(if (= dpth 7.25)(setq label1 (rtos dpth 2 2)))
(if (= dpth 9.25)(setq label1 (rtos dpth 2 2)))
(if (= dpth 9.5)(setq label1 (rtos dpth 2 1)))
(if (= dpth (setq label1 (rtos dpth 2 0)))
(if (= dpth 10)(setq label1 (rtos dpth 2 0)))
(if (= dpth 11.25)(setq label1 (rtos dpth 2 2)))
(if (= dpth 12)(setq label1 (rtos dpth 2 0)))
(if (= dpth 11.875)(setq label1 (rtos dpth 2 3)))
(if (= dpth 14)(setq label1 (rtos dpth 2 0)))
(if (= dpth 16)(setq label1 (rtos dpth 2 0)))
(if (= dpth 18)(setq label1 (rtos dpth 2 0)))
(if (= dpth 24)(setq label1 (rtos dpth 2 0)))       
(if (= dpth 0)(setq label1 ""))       




 (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)
          (setq p10 p11)
          (setq p11 ptemp)
          (setq lan (angle p10 p11))       
          (setq 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 (setq r1(polar mpt (dir lan (+ 1)) 
                                   (getvar "TEXTSIZE")))))
                          (setq hg(cons 11 (setq r2(polar mpt (dir lan (+ 1)) 
                                   (getvar "TEXTSIZE")))))
                          (setq gg(cons 50 lan))
                         (setq rg(cons 1 (strcat label2 label label1 suffix suffixs))))))



                  (ssdel en ss)))
 (command "_.layer" "on" "*" "" "")
(setvar "clayer" layerset)
 (command "filedia" "1") 



 (princ)
)

Edited by j_spawn_h
Link to comment
Share on other sites

It were useful to post also the dialog box definition; however to move the label from polyline based on his width try:

...
(setq fg (cons 10 [color=red]'(0.0 0.0)[/color]))
(setq hg (cons 11 (setq r2 (polar mpt (dir lan (+ 1)) 
                                [color=red] (+ width (* 0.5 [/color](getvar "TEXTSIZE")[color=red]))[/color]))))
...

And some comments after a quick glance on the code:

- Instead of multiple IF's, check the COND function:

(cond
((= wdth 1.75)
 (setq label "1.75x"))
((= wdth 2.5)
 (setq label "I-JOIST/BEAM"))       
((= wdth 3.5)
 (setq label "3.5x"))
((= wdth 5.25)
 (setq label "5.25x"))
((= wdth 7)
 (setq label "7x"))
)

- The PREFIX variable took value from this list:

'("1 ply" "2 ply" "3 ply")

but later is compared with some unrelated stuff:

(= preffix "1.5") ... (= preffix "1.5") ... (= preffix "3") ...

- You try to restore the current layer, but the LAYERSET variable is never assigned.

(setvar "clayer" layerset)

- You assign values to a lot of variables, FG, R1, HG and so, that are never used.

- Try to use localized variables to avoid further conflicts.

- Why reset FILEDIA? It doesn't interfere with custom dialogs.

- Try more consistency in code - you have a function definition at the middle of routine; also hard to follow formatting.

 

 

By using code tags instead of HTML, will shrink the post for better appearance.

Edited by MSasu
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the help, but the code to move the text did not work. I did change the ifs to conds. The reason for the extra variables was for me to check things in different locations so I can figure out where I was having the problem. The layerset was left in and not finished. Also the filedia taken out I did not need it it was just left in by mistake.

Link to comment
Share on other sites

This was working correctly until I add a few lines of code then now it is stuck. The width, depth, suffix, suffixs are stuck on the same answer no matter what I select. I know it is a small error in my code but I spent all day yesterday and could not find it.

(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 -------------------------------------
 (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"))
;-------------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 (setq r1(polar mpt (dir lan (+ 1))
                                   (getvar "TEXTSIZE")))))
                          (setq hg(cons 11 (setq r2(polar mpt (dir lan (+ 1))
                                  (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)
 
 
  
 (princ)
)

 

dcl code

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;
       }}
                 
}

Link to comment
Share on other sites

Not sure why you started a new thread for this. Anyway, to address your issue, please take care that the DCL keys are case sensitive:

key = "[color=red]W[/color]idth";
(action_tile "[color=red]w[/color]idth" "(setq [color=black]width[/color] $value)")

 

On label placement, if you decide to follow my previous advice, please take care that the width variable is in fact a string (since first time you didn't posted the dialog definition, I wasn't aware of this). Below you have the fixed code:

...
(setq fg (cons 10 '(0.0 0.0)))
(setq hg (cons 11 (setq r2 (polar mpt (dir lan (* 0.5 pi)) 
                                 (+ (* 0.5 [color=red](atof [/color]width[color=red])[/color][color=black])[/color] (* 0.8 (getvar "TEXTSIZE")))))))
...

Link to comment
Share on other sites

Msasu,

Thank you very much it worked great. I thought since I had a different question about the lisp that I needed a new thread, so it would not get looked over. I knew about the case sensitive but did't notice I changed it in my code. I was looking to loop this so I could keep drawing the same beam and labeling it until I hit esc or something. I was trying to do it but I was not getting any where. I was using "while" but was not sure if that was correct. I added it in a few places but nothing happined. Could I get some in schooling on where that would go?

 

jspawnh

Edited by j_spawn_h
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...