Need help with LISP code Hatch Creation

Need help with LISP code Hatch Creation

Hannan1
Advocate Advocate
1,347 Views
20 Replies
Message 1 of 21

Need help with LISP code Hatch Creation

Hannan1
Advocate
Advocate

Hello everyone,

I need help with the code to create rectangle hatch with associated polyline and it should be place it with "inspt" of hatch origin point, I'm trying to access Origin point unfortunately exactly DXF code is not there, how we can place it in the center of rectangle.

 

(defun c:RectHatch ()
  (prompt "\nRectangle with Hatch and Associated Boundary\n")

  (setq len (getreal "\nEnter the length of the rectangle: "))
  (setq wid (getreal "\nEnter the width of the rectangle: "))

  (setq inspt (getpoint "\nSpecify the insertion point: "))

  (setq pt1 inspt)
  (setq pt2 (polar pt1 0 len))       
  (setq pt3 (polar pt2 (/ pi 2) wid)) 
  (setq pt4 (polar pt1 (/ pi 2) wid)) 

  (setq pl (entmakex
    (list
      '(0 . "LWPOLYLINE")
      '(100 . "AcDbEntity")
      '(100 . "AcDbPolyline")
      (cons 90 4)
      '(70 . 1)
      (cons 10 pt1)
      (cons 10 pt2)
      (cons 10 pt3)
      (cons 10 pt4)
    )
  ))

  (if pl
    (progn
      (setq hatch (entmakex
        (list
          '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(100 . "AcDbHatch")
          '(cons 10 inspt)
          '(70 . 1)
          '(71 . 0)
          '(75 . 1)
          '(76 . 1)
          '(45 . 0.0)
          '(2 . "ANSI31")
          '(91 . 1)
          (list
            '(92 . 2)
            (cons -1 pl)
          )
        )
      ))

      (if hatch
        (progn
          (redraw pl 3)
          (redraw hatch 3)
          (princ "\nRectangle with Hatch created successfully.")
        )
        (princ "\nError: Failed to create hatch.")
      )
    )
    (princ "\nError: Failed to create polyline.")
  )
  (princ)
)

 

0 Likes
Accepted solutions (4)
1,348 Views
20 Replies
Replies (20)
Message 21 of 21

Hannan1
Advocate
Advocate

Yeah, that's check point alert, I can see a hatch is not associated with the boundary.

0 Likes