Code Red > AutoLISP (Vanilla / Visual)

Label and diameter lengths

(1/4) > >>

Romero:
Hello everyone.

Could someone help me with this great request?  :idea:
I have a huge problem with a task that I need immensely; Maybe someone here can help me. I'll be very greatful.

Description of the problem: Basically I have to label miles of sections of copper wire with their diameter and length.

The labeling will be by means of a mleader with a double line text: In the upper part I have to place the diameter and in the lower part the length.



The diameter is obtained from a list with the different options: I can think of an initget maybe.
Add the prefix: Cu ∅ = and the suffix: "



The length will be obtained from the properties of the selected object (Line, Lwpline, Arc)
- I would like the length to be rounded to one decimal place and if possible show the text two decimal places.
Also add the Prefix: L = and the suffix: m

Create a While to repeat until the user cancels.

If possible, the leaders are created in a layer named Cu_Length in color 3

Any help will be greatly appreciated. I know it's a very complex thing and I can't solve it. I hope someone tells me the way

So far it only occurred to me to do the initget and I don't know how to proceed  :reallysad:


--- Code - Auto/Visual Lisp: ---(defun c:culen ()  (vl-load-com)  (initget "A B C D E F G H I J K")  (setq diam         (cond           ((getkword              "\nWhat diameter will you use?: [A  1\\4/B  3\\8/C  1\\2/D  3\\4/E 1/F  1 1\\4/G  1 1\\2/H  2/I  3/J  4/K  5] <D  3\\4>: "            )           )           ("3\\4")         )  )  (setq diam (cond ((= diam "A") "1\\4")                   ((= diam "B") "3\\8")                   ((= diam "C") "1\\2")                   ((= diam "D") "3\\4")                   ((= diam "E") "1")                   ((= diam "F") "1 1\\4")                   ((= diam "G") "1 1\\2")                   ((= diam "H") "2")                   ((= diam "I") "3")                   ((= diam "J") "4")                   ((= diam "K") "5")             )  ))

Attached dwg example.

BIGAL:
This replaces initget it is a library function it can be used in any code. It uses a dcl for choice.


--- Code: ---(defun c:culen ()
(vl-load-com)
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but nil)(setq but 1))
;(setq diam (ah:butts but "h"  ( list "choose size"  "1/4" "3/8"   "1/2"    "3/4"    "1"   "1 1/4"      "1 1/2"   "2"   "3"  "4"  "5"))) ; horizontal
(setq diam (ah:butts but "v"  ( list "choose size"  "1/4" "3/8"   "1/2"    "3/4"    "1"   "1 1/4"   "1 1/2"   "2"   "3"  "4"  "5"))) ; vertical
)

--- End code ---

BIGAL:
Here is a bit more.


--- Code: ---(defun C:LTLL (/ ss total); = Leader with Total Length of Lines
(while (setq pt1 (getpoint "Pick line or  pline"))
(setq ss (ssget pt1 '((0 . "LINE,lwpolyline"))))
(setq len (vla-get-Length (vlax-ename->vla-object (ssname ss 0))))
(command "_.leader" pt1 (getpoint pt1) "" (rtos len 2 1) "" )
(setq ss nil)
)
(princ)
); defun

--- End code ---

Romero:

--- Quote from: BIGAL on August 17, 2019, 08:45:41 PM ---Here is a bit more.

--- End quote ---


BIGAL Thank you very much for the initget replacement code.
and also by the LTLL code. The truth is that it meets an objective that is to show the length, however, even if they do not meet many more, since the mleader style and text heights are not like the example, I can not add the diameter according to the table and not I can add suffixes or desired prefixes. I still have problems adapting it to my needs. Even so, it is very good help to get started. I thank you for the help provided.

Dlanor:
Try this. You may need to refine it.


--- Code - Auto/Visual Lisp: ---(vl-load-com)(defun AH:Butts (AHdef verhor butlst / fo fname x  k )(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))(write-line  "AHbutts : dialog  {" fo)(write-line  (strcat "  label =" (chr 34) (nth 0 butlst) (chr 34) " ;" )fo)(write-line "   : row   {" fo)(if (=  (strcase verhor) "V")(progn(write-line "   : boxed_radio_column    {" fo)(write-line  (strcat " width = " (rtos (+ (strlen (nth 0 butlst)) 10) 2 0) " ;")  fo)           ; increase 10 if label does not appear)(write-line "   : boxed_radio_row       {" fo))(setq x 1)(repeat (- (length butlst) 1) (write-line "   : radio_button  {" fo)(write-line  (strcat "key = "  (chr 34) "Rb" (rtos x 2 0)  (chr 34) ";") fo)(write-line  (strcat "label = " (chr 34) (nth x  butlst) (chr 34) ";") fo)(write-line "   }" fo)(write-line "spacer_1 ;" fo)(setq x (+ x 1)))(write-line "   }" fo)(write-line "   }" fo)(write-line "spacer_1 ;" fo)(write-line "   ok_only;" fo)(write-line "   }" fo)(close fo)(setq dcl_id (load_dialog fname))(if (not (new_dialog "AHbutts" dcl_id) )(exit))(setq x 1)(repeat (- (length butlst) 1)(setq k (strcat "Rb" (rtos x 2 0)))(action_tile k  (strcat "(setq but "  (rtos x 2 0) ")" "(done_dialog)"))(if (= ahdef x)(set_tile k "1"))(setq x (+ x 1)))(action_tile "accept" (strcat "(setq but "  (rtos ahdef 2 0) ")" "(done_dialog)"))(start_dialog)(unload_dialog dcl_id)(vl-file-delete fname)(1- but))  (defun c:test ( / a_lst b_lst obj len pt idx mtxt)(setq a_lst (list "Wire Size" "1/4" "3/8" "1/2" "3/4" "1" "1 1/4" "1 1/2" "2" "3" "4" "5"))(setq b_lst (list "1#4" "3#8" "1#2" "3#4" "1" "1 1#4" "1 1#2" "2" "3" "4" "5"))(setq obj (vlax-ename->vla-object (car (entsel "\nSelect Line : ")))      len (rtos (vlax-get-property obj 'length) 2 3))(setq pt (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (vlax-get obj 'startpoint) (vlax-get obj 'endpoint)))(setq idx (ah:butts 1 "v"  a_lst)) (cond ( (vl-position idx '(0 1 2 3)) (setq mtxt (strcat "Cu Ø= {\\H0.7x;\\S" (nth idx b_lst) ";}\"\\PL = " len)))      ( (vl-position idx '(5 6)) (setq mtxt (strcat "Cu Ø= " (substr (nth idx b_lst) 1 1) "{\\H0.7x;\\S" (substr (nth idx b_lst) 3) ";}\"\\PL = " len)))      (t (setq mtxt (strcat "Cu Ø=" (nth idx b_lst) "\"\\PL = " len))))(command "_mleader" pt pause mtxt)) 
You'll need to run it in the drawing you posted so the correct textstyle and mleader styles are set.

Navigation

[0] Message Index

[#] Next page

Go to full version