Author Topic: Center line and layer settings  (Read 364 times)

0 Members and 1 Guest are viewing this topic.

myloveflyer

  • Newt
  • Posts: 135
Center line and layer settings
« on: November 13, 2019, 04:03:26 AM »
The left side is the original graphic, the right side is the completed one, the straight line is connected between the center of the circle, and the layer is set according to the similar text, who can help to see how this program is written!
Never give up !

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Center line and layer settings
« Reply #1 on: November 13, 2019, 10:33:41 AM »
Not the fastest, but give this a try:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ a d el l mp p s tmp tx)
  2.   ;; RJP 2019-11-13
  3.   (cond
  4.     ((and (setq d (getdist "\nPick a max distance to use: "))
  5.           (setq s (ssget '((0 . "circle,text"))))
  6.      )
  7.      (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  8.        (setq p (cdr (assoc 10 (setq el (entget x)))))
  9.        (if (= "TEXT" (cdr (assoc 0 el)))
  10.          (setq tx (cons (list p (cdr (assoc 1 el)) (rem (cdr (assoc 50 el)) pi)) tx))
  11.          (setq l (cons p l))
  12.        )
  13.      )
  14.      (while (cadr l)
  15.        (setq p (car l))
  16.        (setq l (cdr l))
  17.        (foreach p2 l
  18.          (cond ((<= (distance p p2) d)
  19.                 (setq a (rem (angle p p2) pi))
  20.                 (setq mp (mapcar '/ (mapcar '+ p p2) '(2 2 2)))
  21.                 (setq tmp nil)
  22.                 (foreach x tx
  23.                   (if (equal (last x) a 1e-3)
  24.                     (setq tmp (cons (cons x (distance (car x) mp)) tmp))
  25.                   )
  26.                 )
  27.                 (and (setq tmp (caar (vl-sort tmp '(lambda (r j) (< (cdr r) (cdr j))))))
  28.                      (entmakex (list '(0 . "line") (cons 8 (cadr tmp)) (cons 10 p) (cons 11 p2)))
  29.                      (setq tx (vl-remove tmp tx))
  30.                      (grdraw (car tmp) mp 3)
  31.                 )
  32.                )
  33.          )
  34.        )
  35.      )
  36.     )
  37.   )
  38.   (princ)
  39. )


Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

myloveflyer

  • Newt
  • Posts: 135
Re: Center line and layer settings
« Reply #2 on: November 14, 2019, 04:12:46 AM »
Not the fastest, but give this a try:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ a d el l mp p s tmp tx)
  2.   ;; RJP 2019-11-13
  3.   (cond
  4.     ((and (setq d (getdist "\nPick a max distance to use: "))
  5.           (setq s (ssget '((0 . "circle,text"))))
  6.      )
  7.      (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  8.        (setq p (cdr (assoc 10 (setq el (entget x)))))
  9.        (if (= "TEXT" (cdr (assoc 0 el)))
  10.          (setq tx (cons (list p (cdr (assoc 1 el)) (rem (cdr (assoc 50 el)) pi)) tx))
  11.          (setq l (cons p l))
  12.        )
  13.      )
  14.      (while (cadr l)
  15.        (setq p (car l))
  16.        (setq l (cdr l))
  17.        (foreach p2 l
  18.          (cond ((<= (distance p p2) d)
  19.                 (setq a (rem (angle p p2) pi))
  20.                 (setq mp (mapcar '/ (mapcar '+ p p2) '(2 2 2)))
  21.                 (setq tmp nil)
  22.                 (foreach x tx
  23.                   (if (equal (last x) a 1e-3)
  24.                     (setq tmp (cons (cons x (distance (car x) mp)) tmp))
  25.                   )
  26.                 )
  27.                 (and (setq tmp (caar (vl-sort tmp '(lambda (r j) (< (cdr r) (cdr j))))))
  28.                      (entmakex (list '(0 . "line") (cons 8 (cadr tmp)) (cons 10 p) (cons 11 p2)))
  29.                      (setq tx (vl-remove tmp tx))
  30.                      (grdraw (car tmp) mp 3)
  31.                 )
  32.                )
  33.          )
  34.        )
  35.      )
  36.     )
  37.   )
  38.   (princ)
  39. )
HI,ronjonp,Thanks You!
Now there is still a question, can you change the name of the corresponding layer of the text according to the right data table, see the attached picture.
Never give up !

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Center line and layer settings
« Reply #3 on: November 14, 2019, 10:25:51 AM »
Are you sure your 4-2 is correct? In the rest of your table all the *-2 are 2M20.

Easy to do with consistent logic:
Code - Auto/Visual Lisp: [Select]
  1. ( if (wcmatch txt "*-1") "2M24" "2M20" )

Looking closer I don't see a pattern  .. research creating an association list then apply the name to the key found (cdr (assoc key lst)).
« Last Edit: November 14, 2019, 10:34:54 AM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

myloveflyer

  • Newt
  • Posts: 135
Re: Center line and layer settings
« Reply #4 on: November 14, 2019, 11:02:00 AM »
Are you sure your 4-2 is correct? In the rest of your table all the *-2 are 2M20.

Easy to do with consistent logic:
Code - Auto/Visual Lisp: [Select]
  1. ( if (wcmatch txt "*-1") "2M24" "2M20" )

Looking closer I don't see a pattern  .. research creating an association list then apply the name to the key found (cdr (assoc key lst)).
Hi,ronjonp!
I am sure that "4-2" is correct. I may not explain it clearly. "4-2" corresponds to "2M24" in the table, then the layer name of the line corresponding to "4-2" is "4M24" or " 4-M24", for example, "3-1" corresponds to "2M24" in the table, then the layer name of the line corresponding to "3-1" is "3M24" or "3-M24", all the straight lines connected by the center The layers are all based on the combination of the alphanumeric characters corresponding to the same line in the table. For example, "2-12" corresponds to "2M20" in the table, then the layer name of the line corresponding to 2-12 is "" 2M20" ("2" in this line layer name "2M20" is the first item in "2-12", and "M20" is "2-12" in the corresponding "2M20" in the table. ") Or directly give the layer name "2-M20", which is easier to understand, see the connection method of the layer name shown in the figure.
« Last Edit: November 14, 2019, 11:18:57 AM by myloveflyer »
Never give up !

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Center line and layer settings
« Reply #5 on: November 14, 2019, 12:43:13 PM »
As stated above look into creating an association list of your values. I've already given you a fish, now you have to gut it.  :wink:.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

BIGAL

  • Bull Frog
  • Posts: 359
  • 30 + years of using Autocad
Re: Center line and layer settings
« Reply #6 on: November 16, 2019, 12:34:37 AM »
You haven't caught it yet your just trying to land it. May have to play with it for a while.
A man who never made a mistake never made anything