Author Topic: How to change this LISP to irregular shape and draw the center line?  (Read 1508 times)

0 Members and 1 Guest are viewing this topic.

ga619091

  • Mosquito
  • Posts: 2
Now this function can only draw the 5MM center line in the rectangle
I hope to be able to draw a 5MM centerline with irregular graphic
Same function as this photo



Code: [Select]
(defun c:ss()
(setq cmd (getvar "cmdecho"))
(setq osm (getvar "osmode"))
(setvar "cmdecho" 0)
(command "undo" "be")
(If (progn
(princ "select:")
(setq ssa (ssget":S" '((0 . "lwpolyline") (90 . 4) (70 . 1))))
)
(progn
(setq dxf (entget (ssname ssa 0)))
(setq pts (mapcar 'cdr (vl-remove-if '(lambda(x)(/= (car x) 10)) dxf)))
(setq p1 (apply 'mapcar (cons 'min pts)))
(setq p3 (apply 'mapcar (cons 'max pts)))
(setq p2 (list (car p3) (cadr p1)))
(setq p4 (list (car p1) (cadr p3)))
(setq p14m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p1 p4))
(setq p14m2 (mapcar '+ p14m1 '(5 0)))
(setq p12m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p1 p2))
(setq p12m2 (mapcar '+ p12m1 '(0 5)))
(setq p23m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p2 p3))
(setq p23m2 (mapcar '+ p23m1 '(-5 0)))
(setq p34m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p3 p4))
(setq p34m2 (mapcar '+ p34m1 '(0 -5)))
(setvar "osmode" 0)
(mapcar '(lambda(pts)
(command "_line" (car pts) (cadr pts) "" "_chprop" (entlast) "" "c" 1 "")
)
(list (list p14m1 p14m2)
(list p12m1 p12m2)
(list p23m1 p23m2)
(list p34m1 p34m2)
)
)
(mapcar '(lambda(pt dxy)
(setq pt1 (mapcar '+ pt dxy))
)
(list p1 p2 p3 p4 )
(list ' (-8 8) '(8 -8))   
)
)
)
(command "undo" "e")
(setvar "osmode" osm)
(setvar "cmdecho" cmd)
(princ)
)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to change this LISP to irregular shape and draw the center line?
« Reply #1 on: November 24, 2020, 01:20:24 PM »
Remove:
Code: [Select]
(90 . 4) (70 . 1)
From the ssget filter list.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to change this LISP to irregular shape and draw the center line?
« Reply #2 on: November 24, 2020, 01:21:53 PM »
Or use the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cl ( / a b d e i l p s x )
  2.     (setq d 5.0)
  3.     (if (setq s (ssget '((0 . "LWPOLYLINE"))))
  4.         (repeat (setq i (sslength s))
  5.             (setq i (1- i)
  6.                   e (ssname s i)
  7.                   l (mapcar '(lambda ( x ) (trans (cdr x) e 1)) (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget e)))
  8.                   l (mapcar '(lambda ( x ) (apply 'mapcar (cons x l))) '(min max))
  9.                   l (list (car l) (list (caadr l) (cadar l)) (cadr l) (list (caar l) (cadadr l)))
  10.             )
  11.             (repeat 4
  12.                 (setq p (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (car l) (cadr l)))
  13.                 (entmake
  14.                     (list
  15.                        '(000 . "LINE")
  16.                         (cons 010 (trans p 1 0))
  17.                         (cons 011 (trans (polar p (+ (angle (car l) (cadr l)) (/ pi 2.0)) d) 1 0))
  18.                     )
  19.                 )
  20.                 (setq l (append (cdr l) (list (car l))))
  21.             )
  22.         )
  23.     )
  24.     (princ)
  25. )

ga619091

  • Mosquito
  • Posts: 2
Re: How to change this LISP to irregular shape and draw the center line?
« Reply #3 on: November 24, 2020, 07:59:34 PM »
Your LISP has been simplified a lot, let me learn a lot thanks
My LISP can only have one choice, yours can have multiple choices
On this basis, I added a round LISP,
how to modify it to Multiple choice in multiple closed graphics?
Multiple choices like the photo below


Code: [Select]
(defun c:ss()
(setq cmd (getvar "cmdecho"))
(setq osm (getvar "osmode"))
(setvar "cmdecho" 0)
(command "undo" "be")
(If (progn
(princ "select:")
(setq ssa (ssget":S" '((0 . "lwpolyline"))))
)
(progn
(setq dxf (entget (ssname ssa 0)))
(setq pts (mapcar 'cdr (vl-remove-if '(lambda(x)(/= (car x) 10)) dxf)))
(setq p1 (apply 'mapcar (cons 'min pts)))
(setq p3 (apply 'mapcar (cons 'max pts)))
(setq p2 (list (car p3) (cadr p1)))
(setq p4 (list (car p1) (cadr p3)))
(setq p14m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p1 p4))
(setq p14m2 (mapcar '+ p14m1 '(5 0)))
(setq p12m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p1 p2))
(setq p12m2 (mapcar '+ p12m1 '(0 5)))
(setq p23m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p2 p3))
(setq p23m2 (mapcar '+ p23m1 '(-5 0)))
(setq p34m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p3 p4))
(setq p34m2 (mapcar '+ p34m1 '(0 -5)))
(setvar "osmode" 0)
(mapcar '(lambda(pts)
(command "_line" (car pts) (cadr pts) "" "_chprop" (entlast) "" "c" 1 "")
)
(list (list p14m1 p14m2)
(list p12m1 p12m2)
(list p23m1 p23m2)
(list p34m1 p34m2)
)
)
(mapcar '(lambda(pt dxy)
(setq pt1 (mapcar '+ pt dxy))
(command "_Circle" pt1 1.55 "_chprop" (entlast) "" "c" 1 "")
(command "_Circle" pt1 1.80 "_chprop" (entlast) "" "c" 1 "")
)
(list p1 p3 )
(list '(8 8) '(-8 -8))   
)
)
)
(mapcar '(lambda(pt dxy)
(setq pt1 (mapcar '+ pt dxy))
(command "_Circle" pt1 1.50 "_chprop" (entlast) "" "c" 1 "")
)
(list p2 p4 )
(list '(-8 8) '(8 -8))
)
(command "undo" "e")
(setvar "osmode" osm)
(setvar "cmdecho" cmd)
(princ)
)