Jump to content

I can not calculate the area of this hatch


Giovannino60

Recommended Posts

I think there's something wrong with that hatch pattern. If I delete the hatch and then create a new hatch, using the same hatch boundary lines, the Area will display in the Properties panel.

Hatch.jpg

Link to comment
Share on other sites

  • 1 year later...

Mainly due to hatch boundary
1. Self-crossing
2. point too densely

......

 

It can be restored by re-establishing the boundary, then self-intersecting the boundary, thinning out the vertices, etc.

 

====================

 

[XDrX-PlugIn(145)] Fixed Hatch with area 0 (theswamp.org)

https://www.theswamp.org/index.php?topic=59461.0

 

Video_2024-04-16_211824.gif.88e6e1a6f07ff8ca61a9817f3638dcc2.gif

 

(defun c:xdtb_hafix0 (/ ha ha1 ha-new has loop loops mp old-boundary progress re ss x)
  (defun _delete-old-boundary (loops)
    (mapcar
      '(lambda (loop)
	 (if (and
	       (setq ss (ssget "f" (xdrx-getpropertyvalue loop "vertices") '((0 . "*line,arc,ellipse,circle"))))
	       (ssdel loop ss)
	       (> (sslength ss) 0)
	     )
	   (progn
	     (mapcar
	       '(lambda (x)
		  (setq re (xdrx-geom-relation loop x t))
		  (if (or
			(= re XD:kTangent)
			(= re XD:kBoundary)
			(= re XD:kCoincident)
		      )
		    (xdrx-entity-delete x)
		  )
		)
	       (xdrx-ss->ents ss)
	     )
	   )
	 )
       )
      loops
    )
  )
  (if (and
	(setq ha (xdrx-ssget (xdrx-string-multilanguage "\n选择填充对象<退出>:" "\nSelect Hatch<Exit>:") '
			     ((0 . "hatch"))
		 )
	)
	(setq has (xdrx_hatch_get0area ha))
      )
    (progn
      (xdrx-begin)
      (xdrx-sysvar-push '("fitarc" 0))
      (xdrx-document-safezoom ha)
      (xdrx_statusbar_begin (xdrx-string-multilanguage "处理中..." "Procesing...") (length has))
      (setq progress 0)
      (mapcar
	'(lambda (x)
	   (xdrx_statusbar_setpos (setq progress (1+ progress)))
	   (if (setq mp (xdrx-hatch->mpolygon x))
	     (progn
	       (setq ha1 (xdrx-mpolygon->hatch mp))
	       (xdrx-entity-matchprop x ha1)
	       (setq ha x
		     ha-new (car (xdrx-ss-getsub ha1 '((0 . "hatch"))))
		     loops (xdrx-getpropertyvalue ha-new "assocobjids")
	       )
	       (if (setq old-boundary (xdrx-getpropertyvalue x "assocobjids"))
		 (progn
		   (xdrx-entity-delete old-boundary)
		 )
		 (progn
		   (_delete-old-boundary loops)
		 )
	       )
	       (xdrx-object-swapid ha ha-new)
	       (xdrx-entity-delete ha-new)
	     )
	   )
	 )
	has
      )
      (xdrx_statusbar_end)
      (xdrx-prompt (xdrx-string-formatex (xdrx-string-multilanguage "\n修复了 %d 个面积为0的填充."
								    "\nFixed %d Hatchs with area 0."
					 ) (length has)
		   )
      )
      (xdrx-sysvar-pop)
      (xdrx-end)
    )
  )
  (princ)
)

 

=============================

 

The code above , using XDRX - API,
Before trying the forum code, please download and install XDRX - API

 

xdcad/XDrx-API: Autolisp development library written in ObjectARX (github.com)

https://github.com/xdcad/XDrx-API

 

Edited by XDSoft
Link to comment
Share on other sites

On 3/5/2023 at 12:23 PM, Cad64 said:

I think there's something wrong with that hatch pattern. If I delete the hatch and then create a new hatch, using the same hatch boundary lines, the Area will display in the Properties panel.

 

I bet the polyline is self intersecting. use the following to check.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/to-find-self-intersection-of-lwpolyline/m-p/6491654/highlight/true#M343734

 

 

Link to comment
Share on other sites

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...