Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

create a boundary around solid hatch

8 REPLIES 8
Reply
Message 1 of 9
jtm2020hyo
1772 Views, 8 Replies

create a boundary around solid hatch

I need to create a boundary around all solid hatch inside the drawing (nested/dynamic/regular blocks and external solid hatch)

8 REPLIES 8
Message 2 of 9
scott_bolton
in reply to: jtm2020hyo

Can't remember where this came from originally but it should get you started:

      (setq HATCH_ss (ssgetfirst)
	    HATCH_ss (cadr HATCH_ss)
	    )
      (setq A2k (>= (substr (getvar "ACADVER") 1 2) "15"))
      (if A2k
	(progn
	  (defun list->variantArray (ptsList / arraySpace sArray)
	    (setq arraySpace
		   (vlax-make-safearray
		     vlax-vbdouble
		     (cons 0 (- (length ptsList) 1))
		     )
		  )
	    (setq sArray (vlax-safearray-fill arraySpace ptsList))
	    (vlax-make-variant sArray)
	    )
	  (defun areaOfObject (en / curve area)
	    (if en
	      (if A2k
		(progn
		  (setq curve (vlax-ename->vla-object en))
		  (if
		    (vl-catch-all-error-p
		      (setq
			area
			 (vl-catch-all-apply 'vlax-curve-getArea (list curve))
			)
		      )
		    nil
		    area
		    )
		  )
		(progn
		  (command "._area" "_O" en)
		  (getvar "area")
		  )
		)
	      )
	    )
	  (defun 3dPoint->2dPoint (3dpt)
	    (list (float (car 3dpt)) (float (cadr 3dpt)))
	    )
	  )
	)
      (defun errexit (s)
	(princ "\nError:  ")
	(princ s)
	(restore)
	)
      (defun undox ()
	(command "._ucs" "_p")
	(command "._undo" "_E")
	(setvar "cmdecho" oldcmdecho)
	(setq *error* olderr)
	(princ)
	)
      (setq olderr  *error*
	    restore undox
	    *error* errexit
	    )
      (setq oldcmdecho (getvar "cmdecho"))
      (setvar "cmdecho" 0)
      (command "._UNDO" "_BE")
      (if A2k
	(progn
	  (vl-load-com)
	  (setq *ModelSpace* (vla-get-ModelSpace
			       (vla-get-ActiveDocument (vlax-get-acad-object))
			       )
		*PaperSpace* (vla-get-PaperSpace
			       (vla-get-ActiveDocument (vlax-get-acad-object))
			       )
		)
	  )
	)
      (if HATCH_ss
	(setq ss2 HATCH_ss)
	(setq ss2 (ssget '((0 . "HATCH"))))
	)
      (if ss2
	(progn
	  (setq i 0)
	  (setq area 0)
	  (setq bMoreLoops nil)
	  (while (setq ent (ssname ss2 i))
	    (setq ed1 (entget ent))
	    (if (not (equal (assoc 210 ed1) '(210 0.0 0.0 1.0))) (princ "\nHatch not in WCS!"))
	    (setq xv (cdr (assoc 210 ed1)))
	    (command "._ucs" "_w")
	    (setq loops1 (cdr (assoc 91 ed1))) ; number of boundary paths (loops)
	    (if
	      (and
		A2k
		(= (strcase (cdr (assoc 410 ed1))) "MODEL")
		)
	      (setq space *ModelSpace*)
	      (setq space *PaperSpace*)
	      )
	    (repeat loops1
	      (setq ed1 (member (assoc 92 ed1) ed1))
	      (setq bptf (cdr (car ed1))) ; boundary path type flag
	      (setq ic (cdr (assoc 73 ed1))) ; is closed
	      (setq noe (cdr (assoc 93 ed1))) ; number of edges
	      (setq bot (cdr (assoc 92 ed1))) ; boundary type
	      (setq hst (cdr (assoc 75 ed1))) ; hatch style
	      (setq ed1 (member (assoc 72 ed1) ed1))
	      (setq bul (cdr (car ed1))) ; bulge
	      (setq plist nil)
	      (setq blist nil)
	      (cond
		((> (boole 1 bptf 2) 0) ; polyline
		 (repeat noe
		   (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
		   (setq plist (append plist (list (cdr (assoc 10 ed1)))))
		   (setq blist (append blist
				       (if (> bul 0)
					 (list (cdr (assoc 42 ed1)))
					 nil
					 )
				       )
			 )
		   )
		 (if A2k
		   (progn
		     (setq polypoints
			    (apply 'append
				   (mapcar '3dPoint->2dPoint plist)
				   )
			   )
		     (setq VLADataPts (list->variantArray polypoints))
		     (setq obj (vla-addLightweightPolyline space VLADataPts))
		     (setq nr 0)
		     (repeat (length blist)
		       (if (/= (nth nr blist) 0)
			 (vla-setBulge obj nr (nth nr blist))
			 )
		       (setq nr (1+ nr))
		       )
		     (if (= ic 1)
		       (vla-put-closed obj T)
		       )
		     )
		   (progn
		     (if (= ic 1)
		       (entmake '((0 . "POLYLINE") (66 . 1) (70 . 1)))
		       (entmake '((0 . "POLYLINE") (66 . 1)))
		       )
		     (setq nr 0)
		     (repeat (length plist)
		       (if (= bul 0)
			 (entmake (list (cons 0 "VERTEX")
					(cons 10 (nth nr plist))
					)
				  )
			 (entmake (list (cons 0 "VERTEX")
					(cons 10 (nth nr plist))
					(cons 42 (nth nr blist))
					)
				  )
			 )
		       (setq nr (1+ nr))
		       )
		     (entmake '((0 . "SEQEND")))
		     )
		   )
		 )
		(t ; not polyline
		 (setq lastent (entlast))
		 (setq lwp T)
		 (repeat noe
		   (setq et (cdr (assoc 72 ed1)))
		   (cond
		     ((= et 1) ; line
		      (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
		      (if A2k
			(vla-AddLine
			  space
			  (vlax-3d-point (cdr (assoc 10 ed1)))
			  (vlax-3d-point (cdr (assoc 11 ed1)))
			  )
			(entmake
			  (list
			    (cons 0 "LINE")
			    (list 10 (cadr (assoc 10 ed1)) (caddr (assoc 10 ed1)) 0)
			    (list 11 (cadr (assoc 11 ed1)) (caddr (assoc 11 ed1)) 0)
			    ;  (cons 210 xv)
			    )
			  )
			)
		      (setq ed1 (cddr ed1))
		      )
		     ((= et 2) ; circular arc
		      (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
		      (setq ang1 (cdr (assoc 50 ed1)))
		      (setq ang2 (cdr (assoc 51 ed1)))
		      (setq cw (cdr (assoc 73 ed1)))
		      (if (and (equal ang1 0 0.00001) (equal ang2 6.28319 0.00001))
			(progn
			  (if A2k
			    (vla-AddCircle
			      space
			      (vlax-3d-point (cdr (assoc 10 ed1)))
			      (cdr (assoc 40 ed1))
			      )
			    (entmake (list (cons 0 "CIRCLE")
					   (assoc 10 ed1)
					   (assoc 40 ed1)
					   )
				     )
			    )
			  (setq lwp nil)
			  )
			(if A2k
			  (vla-AddArc
			    space
			    (vlax-3d-point (cdr (assoc 10 ed1)))
			    (cdr (assoc 40 ed1))
			    (if (= cw 0)
			      (- 0 ang2)
			      ang1
			      )
			    (if (= cw 0)
			      (- 0 ang1)
			      ang2
			      )
			    )
			  (entmake (list (cons 0 "ARC")
					 (assoc 10 ed1)
					 (assoc 40 ed1)
					 (cons 50
					       (if (= cw 0)
						 (- 0 ang2)
						 ang1
						 )
					       )
					 (cons 51
					       (if (= cw 0)
						 (- 0 ang1)
						 ang2
						 )
					       )
					 )
				   )
			  )
			)
		      (setq ed1 (cddddr ed1))
		      )
		     ((= et 3) ; elliptic arc
		      (setq ed1 (member (assoc 10 (cdr ed1)) ed1))
		      (setq ang1 (cdr (assoc 50 ed1)))
		      (setq ang2 (cdr (assoc 51 ed1)))
		      (setq cw (cdr (assoc 73 ed1)))
		      (if A2k
			(progn
			  (setq obj (vla-AddEllipse
				      space
				      (vlax-3d-point (cdr (assoc 10 ed1)))
				      (vlax-3d-point (cdr (assoc 11 ed1)))
				      (cdr (assoc 40 ed1))
				      )
				)
			  (vla-put-startangle obj (if (= cw 0) (- 0 ang2) ang1))
			  (vla-put-endangle obj (if (= cw 0) (- 0 ang1) ang2))
			  )
			(princ "\nElliptic arc not supported!")
			)
		      (setq lwp nil)
		      )
		     ((= et 4) ; spline
		      (setq ed1 (member (assoc 94 (cdr ed1)) ed1))
		      (setq knot-list nil)
		      (setq controlpoint-list nil)
		      (setq kn (cdr (assoc 95 ed1)))
		      (setq cn (cdr (assoc 96 ed1)))
		      (setq pos (vl-position (assoc 40 ed1) ed1))
		      (repeat kn
			(setq knot-list (cons (cons 40 (cdr (nth pos ed1))) knot-list))
			(setq pos (1+ pos))
			)
		      (setq pos (vl-position (assoc 10 ed1) ed1))
		      (repeat cn
			(setq controlpoint-list (cons (cons 10 (cdr (nth pos ed1))) controlpoint-list))
			(setq pos (1+ pos))
			)
		      (setq knot-list (reverse knot-list))
		      (setq controlpoint-list (reverse controlpoint-list))
		      (entmake (append
				 (list '(0 . "SPLINE"))
				 (list (cons 100 "AcDbEntity"))
				 (list (cons 100 "AcDbSpline"))
				 (list (cons 70 (+ 1 8 (* 2 (cdr (assoc 74 ed1))) (* 4 (cdr (assoc 73 ed1))))))
				 (list (cons 71 (cdr (assoc 94 ed1))))
				 (list (cons 72 kn))
				 (list (cons 73 cn))
				 knot-list
				 controlpoint-list
				 )
			       )
		      (setq ed1 (member (assoc 10 ed1) ed1))
		      (setq lwp nil)
		      )
		     ) ; end cond
		   ) ; end repeat noe
		 (if lwp
		   (progn
		     (setq en1 (entnext lastent))
		     (setq ss (ssadd))
		     (ssadd en1 ss)
		     (while (setq en2 (entnext en1))
		       (ssadd en2 ss)
		       (setq en1 en2)
		       )
		     (if (= (getvar "peditaccept") 1)
		       (command "_.pedit" (entlast) "_J" ss "" "")
		       (command "_.pedit" (entlast) "_Y" "_J" ss "" "")
		       )
		     )
		   )
		 ) ; end t
		) ; end cond
	      ;	Tries to get the area on islands but it's not clear how to know if an island is filled or not
	      ;	and if it should be substracted or added to the total area.
	      ;	(if (or (= bot 0) (= (boole 1 bot 1) 1)) (setq area (+ area (areaOfObject (entlast)))))
	      ;	(if (and (/= hst 1) (/= bot 0) (= (boole 1 bot 1) 0)) (setq area (- area (areaOfObject (entlast)))))
	      ;	(princ "\n") (princ bot) (princ "\n") (princ hst) (princ "\n")
	      ;	(princ (areaOfObject (entlast)))
	      ) ; end repeat loops1
	    (if (= loops1 1)
	      (setq area (+ area (areaOfObject (entlast))))
	      (setq bMoreLoops T)
	      )
	    (setq i (1+ i))
	    )
	  )
	)
      ;;;  (if (and area (not bMoreLoops))
      ;;;    (progn
      ;;;      (princ "\nTotal Area = ")
      ;;;      (princ area)
      ;;;      )
      ;;;  )
Message 3 of 9
ronjonp
in reply to: scott_bolton

Some answers here to the same question although it's a bit of a moving target...

Message 4 of 9
jtm2020hyo
in reply to: ronjonp


@ronjonp wrote:

Some answers here to the same question although it's a bit of a moving target...


 

until now I did not find an answer in "Autodesk lisp forum" or THESWAMP

 

"Solids" are not the same that "hatch solid"?

Message 5 of 9
ronjonp
in reply to: jtm2020hyo

Post a sample drawing.

Message 6 of 9
jtm2020hyo
in reply to: ronjonp

 


@ronjonp wrote:

Post a sample drawing.


image.png

 

 

 

 

 

Message 7 of 9
ronjonp
in reply to: jtm2020hyo

Definitely not hatch. Sorry don't have time to look into this closely. I can tell you that the points are stored in the dxf codes 10-13 of the solid. You could create closed polylines with those points ( quick test and this does not work )then perhaps convert to solids and union them.

Message 8 of 9
pendean
in reply to: jtm2020hyo

2D SOLID objects are not haches https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoC...

 

Capture.PNG 

 

 

May I ask why you cannot use them as is since they are not hatches? You should be able to snap to the intersections with 2D Solids.

 

 

Message 9 of 9
jtm2020hyo
in reply to: pendean


@pendean wrote:

2D SOLID objects are not haches https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoC...

 

Capture.PNG 

 

 

May I ask why you cannot use them as is since they are not hatches? You should be able to snap to the intersections with 2D Solids.

 

 


 

 

I need to delete all SOLIDs in the drawing (nested/regular/dynamic blocks) but leave their boundary.

 

this for the performance and clear the drawing

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost