Author Topic: Help with a lisp : Building hatch lisp  (Read 1411 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help with a lisp : Building hatch lisp
« on: December 06, 2020, 05:07:50 AM »
This lisp add hach with offset 0.50 inside close polyline. I use it to add hach in buildings. I s it possible to add same changes?

1) The building are from lines so is it possible to pick a pointinside the building
2) create a boudary and offset it 0.50
3) add the hach
4)delete the create boudaries

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:OffsetMultiplePolylines
  3.     (/ ss offdist direction n en ed pt LL UR MP minpoint maxpoint
  4.        area1 area2 newpoly vtx ucsFlag enExtr)
  5. (COMMAND "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  6.   (command "._undo" "_begin")
  7.   (prompt "Select polyline(s): ")
  8.   (setq ss (ssget '((0 . "*POLYLINE"))))
  9.  
  10.   (initget 1)
  11.   (setq offdist "0.5")
  12.   (setq offdist2 "0.5")
  13.   (initget 1 "In Out")
  14.   (setq direction "in")
  15.  
  16.   (if (= direction "Out")
  17.       (progn  ;;OUT
  18.         (setq n 0)
  19.         (setq pt (list (1+ (car (getvar 'extmax)))
  20.                        (1+ (cadr (getvar 'extmax)))))
  21.         (repeat (sslength ss)
  22.           (setq en (ssname ss n))
  23.           (if (not (= 8 (logand 8 (cdr (assoc 70 (entget en))))));no 3Dp
  24.             (command "._offset" offdist en pt "")
  25.             )
  26.           (setq n (1+ n))
  27.           )
  28.         )
  29.        
  30.       (progn  ;;IN
  31.         (setq n 0)
  32.           (repeat (sslength ss)
  33.             (setq ucsFlag nil)
  34.             (setq en (ssname ss n))
  35.             (setq ed (entget en))
  36.             (if (not (= 8 (logand 8 (cdr (assoc 70 ed)))))
  37.                 (progn
  38.                   (setq enExtr (cadddr (assoc 210 ed)))
  39.                   (if (not (= enExtr (caddr (trans '( 0.0 0.0 1.0) 0 1))))
  40.                     (progn
  41.                       (setq     elev
  42.                          (cond
  43.                            ((= enType "LWPOLYLINE")
  44.                             (cdr (assoc 38 ed))
  45.                            )
  46.                            (T
  47.                             (caddr (cdr (assoc 10 ed)))
  48.                            )
  49.                          );cond
  50.                        )
  51.                       (command "._ucs" "_3point"
  52.                         (trans (list 0.0 0.0 elev) en 1)
  53.                         (trans (list 1.0 0.0 elev) en 1)
  54.                         (trans (list 0.0 1.0 elev) en 1)
  55.                         )
  56.                       (setq ucsFlag T)
  57.                     )
  58.                   )
  59.  
  60.                   (setq obj (vlax-ename->vla-object en))
  61.                   (vla-getboundingbox obj 'minpoint 'maxpoint)
  62.                   (setq LL (trans (vlax-safearray->list minpoint) 0 1)
  63.                         UR (trans (vlax-safearray->list maxpoint) 0 1)
  64.                         MP (list (/ (+ (car LL) (car UR)) 2.0)
  65.                                  (/ (+ (cadr LL) (cadr UR)) 2.0))
  66.                         )
  67.                   (command "._area" "_object" en)
  68.                   (setq area1 (getvar 'area))
  69.      ;;MP is approximate centroid of polyline - test if in fact inside
  70.                   (command "._offset" offdist en MP "")
  71.                   (setq newpoly (entlast))
  72.                   (command "._area" "_object" newpoly)
  73.                   (setq area2 (getvar 'area))
  74.      ;;if new polyline is outside the original, offset it
  75.      ;;twice the original distance in the other direction
  76.                   (if (> area2 area1)
  77.                     (progn
  78.                       (setq vtx (entnext (entnext en)))
  79.                       (setq pt
  80.                         (trans (cdr (assoc 10 (entget vtx))) 0 1))
  81.                       (command "._offset" (* 2.0 offdist) newpoly pt "")
  82.                       ;;(entdel newpoly)
  83.                       )
  84.                      )
  85.                     )
  86.                   )
  87.         (command "_hatch" "line" "0.125" "50" en newpoly "")
  88.         (setq newhatch (entlast))
  89.         (command "change" newpoly "" "P" "LA" "0" "")
  90.         ;(command "._offset" offdist2 newpoly MP "")
  91.         ;(setq newpoly2 (entlast))
  92.         ;(command "change" newpoly2 "" "P" "LA" "P-BUILDING-INT" "")
  93.         ;;(entdel newpoly)
  94.               (if ucsFlag (command "._ucs" "_p"))
  95.               (setq n (1+ n))
  96.             );;repeat
  97.           )
  98.       )
  99. (command "._undo" "_end")
  100. );;defun
  101.  
  102. (defun c:OFFSETBUILDING ()
  103.   (c:offsetmultiplepolylines)
  104.   )
  105.  
  106.  
  107.  

Thanks

PM

  • Guest
Re: Help with a lisp : Building hatch lisp
« Reply #1 on: December 06, 2020, 07:46:12 AM »
Any ideas?

BIGAL

  • Swamp Rat
  • Posts: 1429
  • 40 + years of using Autocad
Re: Help with a lisp : Building hatch lisp
« Reply #2 on: December 07, 2020, 01:30:16 AM »
BPOLY is your friend.
A man who never made a mistake never made anything

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: Help with a lisp : Building hatch lisp
« Reply #3 on: December 09, 2020, 03:19:16 PM »
I think this could be altered to suit your needs:
https://www.cadtutor.net/forum/topic/71618-lisp-required-to-make-continuous-offset/?do=findComment&comment=574276

You would just need to use (setq en2 (entlast)) again after the offset, run a hatch using this boundary en2, then delete the offset boundary saved in en2.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt