Author Topic: Label and diameter lengths  (Read 5859 times)

0 Members and 1 Guest are viewing this topic.

Romero

  • Newt
  • Posts: 25
Label and diameter lengths
« on: August 14, 2019, 11:35:36 PM »
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: [Select]
  1. (defun c:culen ()
  2.   (initget "A B C D E F G H I J K")
  3.   (setq diam
  4.          (cond
  5.            ((getkword
  6.               "\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>: "
  7.             )
  8.            )
  9.            ("3\\4")
  10.          )
  11.   )
  12.   (setq diam (cond ((= diam "A") "1\\4")
  13.                    ((= diam "B") "3\\8")
  14.                    ((= diam "C") "1\\2")
  15.                    ((= diam "D") "3\\4")
  16.                    ((= diam "E") "1")
  17.                    ((= diam "F") "1 1\\4")
  18.                    ((= diam "G") "1 1\\2")
  19.                    ((= diam "H") "2")
  20.                    ((= diam "I") "3")
  21.                    ((= diam "J") "4")
  22.                    ((= diam "K") "5")
  23.              )
  24.   )
  25. )


Attached dwg example.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Label and diameter lengths
« Reply #1 on: August 17, 2019, 06:35:02 AM »
This replaces initget it is a library function it can be used in any code. It uses a dcl for choice.

Code: [Select]
(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
)
« Last Edit: August 17, 2019, 06:38:26 AM by BIGAL »
A man who never made a mistake never made anything

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Label and diameter lengths
« Reply #2 on: August 17, 2019, 08:45:41 PM »
Here is a bit more.

Code: [Select]
(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
A man who never made a mistake never made anything

Romero

  • Newt
  • Posts: 25
Re: Label and diameter lengths
« Reply #3 on: August 18, 2019, 08:02:39 PM »
Here is a bit more.


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

  • Bull Frog
  • Posts: 263
Re: Label and diameter lengths
« Reply #4 on: August 19, 2019, 05:11:47 AM »
Try this. You may need to refine it.

Code - Auto/Visual Lisp: [Select]
  1. (defun AH:Butts (AHdef verhor butlst / fo fname x  k )
  2. (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
  3. (write-line  "AHbutts : dialog  {" fo)
  4. (write-line  (strcat "  label =" (chr 34) (nth 0 butlst) (chr 34) " ;" )fo)
  5. (write-line "   : row   {" fo)
  6. (if (=  (strcase verhor) "V")
  7. (write-line "   : boxed_radio_column    {" fo)
  8. (write-line  (strcat " width = " (rtos (+ (strlen (nth 0 butlst)) 10) 2 0) " ;")  fo)           ; increase 10 if label does not appear
  9. )
  10. (write-line "   : boxed_radio_row       {" fo)
  11. )
  12. (setq x 1)
  13. (repeat (- (length butlst) 1)
  14. (write-line "   : radio_button  {" fo)
  15. (write-line  (strcat "key = "  (chr 34) "Rb" (rtos x 2 0)  (chr 34) ";") fo)
  16. (write-line  (strcat "label = " (chr 34) (nth x  butlst) (chr 34) ";") fo)
  17. (write-line "   }" fo)
  18. (write-line "spacer_1 ;" fo)
  19. (setq x (+ x 1))
  20. )
  21. (write-line "   }" fo)
  22. (write-line "   }" fo)
  23. (write-line "spacer_1 ;" fo)
  24. (write-line "   ok_only;" fo)
  25. (write-line "   }" fo)
  26. (close fo)
  27. (setq dcl_id (load_dialog fname))
  28. (if (not (new_dialog "AHbutts" dcl_id) )
  29. )
  30. (setq x 1)
  31. (repeat (- (length butlst) 1)
  32. (setq k (strcat "Rb" (rtos x 2 0)))
  33. (action_tile k  (strcat "(setq but "  (rtos x 2 0) ")" "(done_dialog)"))
  34. (if (= ahdef x)(set_tile k "1"))
  35. (setq x (+ x 1))
  36. )
  37. (action_tile "accept" (strcat "(setq but "  (rtos ahdef 2 0) ")" "(done_dialog)"))
  38. (unload_dialog dcl_id)
  39. (1- but)
  40. )
  41.  
  42.  
  43. (defun c:test ( / a_lst b_lst obj len pt idx mtxt)
  44. (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"))
  45. (setq b_lst (list "1#4" "3#8" "1#2" "3#4" "1" "1 1#4" "1 1#2" "2" "3" "4" "5"))
  46. (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Line : ")))
  47.       len (rtos (vlax-get-property obj 'length) 2 3)
  48. )
  49. (setq pt (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (vlax-get obj 'startpoint) (vlax-get obj 'endpoint)))
  50. (setq idx (ah:butts 1 "v"  a_lst))
  51. (cond ( (vl-position idx '(0 1 2 3)) (setq mtxt (strcat "Cu Ø= {\\H0.7x;\\S" (nth idx b_lst) ";}\"\\PL = " len)))
  52.       ( (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)))
  53.       (t (setq mtxt (strcat "Cu Ø=" (nth idx b_lst) "\"\\PL = " len)))
  54. )
  55. (command "_mleader" pt pause mtxt)
  56. )
  57.  

You'll need to run it in the drawing you posted so the correct textstyle and mleader styles are set.
« Last Edit: August 19, 2019, 05:18:55 AM by Dlanor »

Romero

  • Newt
  • Posts: 25
Re: Label and diameter lengths
« Reply #5 on: August 19, 2019, 12:16:14 PM »
Try this. You may need to refine it.
You'll need to run it in the drawing you posted so the correct textstyle and mleader styles are set.


Thank you very much Dlanor for your code.

The truth is that it works well.

I just want to know if there is a possibility to correct some details.




It currently works for lines. Maybe they can help me to make it work so that it also works with polylines; here the challenge would be to determine only the length of the section where the polyline is selected and not the total length of it.



Currently ¼ is the default option. How do I make ¾ the default? Since in most cases it is the diameter I use most.



Currently the text returns the real length. I would like to round to a decimal, but show 2 as shown in the green text; also add the suffix "m".



Currently everything is created in the current layer; I would like it to be set in a layer named "Cu_Length" in color 3

I would be very grateful if these modifications could be made. Dlanor, you still did an excellent job, you helped me a lot. Thank you.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Label and diameter lengths
« Reply #6 on: August 19, 2019, 04:55:40 PM »
I'm a bit busy at the moment, work wise; but will have a bit of time to code on Wednesday, but lwpolyline and arc are already in hand.

The default in the dcl can be change by altering this line :

Code - Auto/Visual Lisp: [Select]
  1. (setq idx (ah:butts 1 "v"  a_lst))

Change the 1 to 4

To display the length to 2 decimal places change the last 3 to a 2 in the len (rtos) line below


Code - Auto/Visual Lisp: [Select]
  1. (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Line : ")))
  2.       len (rtos (vlax-get-property obj 'length) 2 3)
  3. )

To add the suffix change these three lines so that there is a "m" after the len as indicated below

Code - Auto/Visual Lisp: [Select]
  1. (cond ( (vl-position idx '(0 1 2 3)) (setq mtxt (strcat "Cu Ø= {\\H0.7x;\\S" (nth idx b_lst) ";}\"\\PL = " len "m")))
  2.       ( (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 "m")))
  3.       (t (setq mtxt (strcat "Cu Ø=" (nth idx b_lst) "\"\\PL = " len "m")))
  4. )

Will add the layer requirements.

Romero

  • Newt
  • Posts: 25
Re: Label and diameter lengths
« Reply #7 on: August 19, 2019, 05:58:30 PM »
Dlanor, thank you very much for continuing on the subject. Apply the corrections as directed

but lwpolyline and arc are already in hand.
Unfortunately it doesn't work for me with polylines or arcs and throws the following text on the command line: ; error: ActiveX Server returned the error: unknown name: "STARTPOINT"





I managed to round to 1 decimal place however the text I would like to be displayed with two digits after the length. I don't know if that could be possible?





Another important aspect that I had not mentioned is that when creating the mleader it creates the opening of text just where I select the line. I would like first to choose where to place the text; since it does not always go along the line.





Dlanor, I really appreciate the help provided. You have horrendous me hours of intense work.


Dlanor

  • Bull Frog
  • Posts: 263
Re: Label and diameter lengths
« Reply #8 on: August 20, 2019, 04:09:36 AM »

Unfortunately it doesn't work for me with polylines or arcs and throws the following text on the command line: ; error: ActiveX Server returned the error: unknown name: "STARTPOINT"


I know, I haven't written that bit yet. Wednesday.


I managed to round to 1 decimal place however the text I would like to be displayed with two digits after the length. I don't know if that could be possible?


Again that is "in hand" and will be sorted on Wednesday.


Another important aspect that I had not mentioned is that when creating the mleader it creates the opening of text just where I select the line. I would like first to choose where to place the text; since it does not always go along the line.


At present it will start the mleader in the middle of the line, you just need to select the text end of the mleader. Once you have selected the wire diameter, move the mouse to see the mleader stretch. This will also happen with the arc/polyline segment once they are implimented. Where the text goes is up to you and is dependant on your mleader style constraints (45 degrees) . If you are restricted to 90 degrees try turning ortho mode off (F8) and if so do you want this done automatically by the lisp and restored on exit?

Or do you mean you want the leader to start where you select the line entity?
« Last Edit: August 20, 2019, 10:47:31 AM by Dlanor »

Romero

  • Newt
  • Posts: 25
Re: Label and diameter lengths
« Reply #9 on: August 20, 2019, 02:35:26 PM »
I know, I haven't written that bit yet. Wednesday.

Again that is "in hand" and will be sorted on Wednesday.

Dlanor, thanks for your help and sorry for being here on the lookout. I will wait for when you have some free time.

and if so do you want this done automatically by the lisp and restored on exit?

yes, I would like ortho mode to be deactivated and reset at the end

Or do you mean you want the leader to start where you select the line entity?

Exact. I would like the leader's arrow to start where the line was selected.
I really appreciate your help.


Dlanor

  • Bull Frog
  • Posts: 263
Re: Label and diameter lengths
« Reply #10 on: August 21, 2019, 03:19:28 PM »
Attached is complete lisp.

Points to note :

The Line Entity Selection is in a while loop. This is so you can continue to select entities until you wish to stop. To exit the loop make a null selection (left clisk on an empty bit of the drawing) or right click or press enter.

Sets the correct layer (if not present creates it and sets it), mleader style and orthomode. The entry state is restored on exiting the lisp.

Important. All the actions are with a undo group. A single undo will undo everything, so if you do a whole bunch and something is wrong erase it rather than undo unless that is what you want.

The MLeader Style still has the first vertex restriction of multiples of 45 degrees. This is easier toggled through the mleader style manager.

Let me know if there are any problems.
« Last Edit: August 21, 2019, 03:54:57 PM by Dlanor »

Dlanor

  • Bull Frog
  • Posts: 263
Re: Label and diameter lengths
« Reply #11 on: August 21, 2019, 03:56:00 PM »
Updated above attachment to solve the low " (inches)

Romero

  • Newt
  • Posts: 25
Re: Label and diameter lengths
« Reply #12 on: August 21, 2019, 06:22:12 PM »
Attached is complete lisp.
Let me know if there are any problems.

Dlanor. Your code works perfectly.  :yay!: I really appreciate the time you spent making it possible. Man you are a master, I wish I could be like you someday. Look you saved me hours of hard work. My most sincere gratitude for all your effort. Cheers. :-D

Dlanor

  • Bull Frog
  • Posts: 263
Re: Label and diameter lengths
« Reply #13 on: August 21, 2019, 06:39:44 PM »
No problem.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Label and diameter lengths
« Reply #14 on: August 22, 2019, 02:33:36 AM »
Dlanor you do not need to include multi radio buttons.lsp in the code it was developed as a library routine you only need 2 lines in any code to use it. The example of how was in the original code. You are correct any button can be set as the default, the idea behind that was to set the button to last picked so just reset the "but" variable. Same method Multi getvals.lsp

Code: [Select]
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but nil)(setq but 4)) ; user request

A man who never made a mistake never made anything