Jump to content

Recommended Posts

Posted

Dear team, 

I want to make hatching in multiple closed polyline with layer

 

Hatch pattern: any default but not a solid one

 

After selection/ pick all pline , draw hatch and after I press enter or escape button , hatch pattern in AutoCAD return to default solid pattern, not that one used recently.

 

So I need a lisp for that.

 

Thanks 

Posted

What do you mean: polyline with layer?

 

Anyway,  command MPH (for Hatch Multiple Polylines)

the pattern is ANSI31; you can change it in the function hatch_closed_polyline

 


;; Hatch Multiple Polylines
(defun c:hmp ( / ss sc i)
	(setq sc (getreal "\nScale: "))
	;; or do: (setq sc 1.0) ;; or whatever factor
	
	(prompt "\nSelect Closed Polylines to Hatch: ")
	
	(setq ss (ssget (list (cons 0 "*POLYLINE")  )))		;;(cons 70 1) 
	;;(hatch_closed_polyline ss sc)
	(setq i 0)
	(repeat (sslength ss)
		(hatch_closed_polyline (ssadd (ssname ss i)) sc)
		(setq i (+ i 1))
	)
)


;; slightly modified from this code:
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/entmake-hatch-with-base-point-or-object-polyline-entity-name/m-p/8703197#M383362
 
(defun hatch_closed_polyline (ss sc /  cnt e hList pat)

	(setq pat "ANSI31")	;; adapt to your needs
	
	(if (= 0.0 sc)
		(setq sc 1.0)
	)
		
	(setq cnt (sslength ss))
	(while (<= 0 (setq cnt (1- cnt)))
	  (setq e (ssname ss cnt))
	  (if (setq tmp (CreateHatchList e))
		(setq hList (cons tmp hList))
	  );if
	);while
	(setq hList (reverse hList))
	(if (entmakex-hatch hList 0.0 pat sc)		
	  (prompt "\nSuccess!")
	  (prompt "\n...Failure.")
	);if
	(princ)
	);defun

	(defun CreateHatchList (e / i j pList found)
	(foreach i (entget e)
	  (if (= 10 (car i))
		(progn
		  (setq pList (cons i pList))
		  (setq found nil j (member i (entget e)))
		  (while (and (not found) (< 0 (length j)))
		(if (= 42 (car (car j)))
		  (setq pList (cons (car j) pList) found t)
		);if
		(setq j (cdr j))
		  );while
		);progn
	  );if
	);foreach
	(reverse pList)
);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun entmakex-hatch (l a n s)
 ;; By ElpanovEvgeniy
 ;; L - list point
 ;; A - angle hatch
 ;; N - name pattern
 ;; S - scale
 ;; return - hatch ename
 (entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH") '(100 . "AcDbEntity") '(410 . "Model") '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0) '(210 0.0 0.0 1.0)
          (cons 2 n)
          (if (= n "SOLID")
           '(70 . 1)
           '(70 . 0)
          ) ;_  if
          '(71 . 0)
          (cons 91 (length l))
    ) ;_  list
    (apply 'append
           (mapcar '(lambda (a)
                     (apply 'append
                            (list (list '(92 . 7) '(72 . 1) '(73 . 1) (cons 93 (/ (length a) 2)))
				  (mapcar '(lambda (b) b) a)
                                  '((97 . 0))
                            ) ;_  list
                     ) ;_  apply
                    ) ;_  lambda
                   l
           ) ;_  mapcar
    ) ;_  apply
    (list '(75 . 0) '(76 . 1) (cons 52 a) (cons 41 s) '(77 . 0) '(78 . 1) (cons 53 a)
          '(43 . 0.) '(44 . 0.) '(45 . 1.) '(46 . 1.) '(79 . 0) '(47 . 1.) '(98 . 2)
          '(10 0. 0. 0.0) '(10 0. 0. 0.0) '(451 . 0) '(460 . 0.0) '(461 . 0.0) '(452 . 1)
          '(462 . 1.0) '(453 . 2) '(463 . 0.0) '(463 . 1.0) '(470 . "ANSI31")
    ) ;_  list
   ) ;_  list
  ) ;_  apply
 ) ;_  entmakex
) ;_  defun

 

  • Like 1
Posted

Thanks, almost as I want,

Just please provide,

1. Hatch pattern name on command prompt also to change:

Like scale is coming,

 

2. Hatching must be in separate layer ex: hatching

 

3: provide also, pick point option for hatching,

Currently asking select closed polyline to hatch, select objects:

Thanks 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...