Jump to content

Recommended Posts

Posted

Hello everybody

I need to give center of hatch.

I do this

(foreach a (entget (car entsel))
	  (if (= (car a) 10)
	    (setq l (1+ l)
		  x (+ x (cadr a))
		  y (+ y (caddr a))
	    )
	  )
	)
	(setq pm (list (/ x l) (/ y l) 0.0))

but It's not accurate.

Is there another way?

Thanks All.

Posted (edited)

You need to wrap ( entsel ) like so for the code to even work 😉

 

AND

 

Variables 'l' 'x' and 'y' need to be set to 0 outside of the loop.

 

Like so:

(defun c:foo (/ e l pm x y)
  (if (setq e (car (entsel)))
    (progn (mapcar 'set '(l x y) '(0 0 0))
	   (foreach a (entget e)
	     (if (= (car a) 10)
	       (setq l (1+ l)
		     x (+ x (cadr a))
		     y (+ y (caddr a))
	       )
	     )
	   )
	   (setq pm (list (/ x l) (/ y l) 0.0))
	   (entmake (list '(0 . "POINT") (cons 10 pm)))
    )
  )
  (princ)
)

 

Edited by ronjonp
Posted (edited)

@mstb Simple method since you have AutoCAD 2020 is to temporarily turn off hatch layer. Start the BOUNDARY command on another layer > Pick the same internal point to make a polyline in the same area as the hatch, then use the "Geometric Center" Object Snap (GCEN at the command line) to draw a line or point at the center. Then you can delete the boundary polyline and turn the hatch layer back on.

 

EDIT: Note - I guess this method would not work with Islands. You would have to make a REGION and get the MomentOfInertia property?

Edited by pkenewell
Posted
19 minutes ago, ronjonp said:

You need to wrap ( entsel ) like so for the code to even work 😉

 

AND

 

Variables 'l' 'x' and 'y' need to be set to 0 outside of the loop.

 

Like so:


(defun c:foo (/ e l pm x y)
  (if (setq e (car (entsel)))
    (progn (mapcar 'set '(l x y) '(0 0 0))
	   (foreach a (entget e)
	     (if (= (car a) 10)
	       (setq l (1+ l)
		     x (+ x (cadr a))
		     y (+ y (caddr a))
	       )
	     )
	   )
	   (setq pm (list (/ x l) (/ y l) 0.0))
	   (entmake (list '(0 . "POINT") (cons 10 pm)))
    )
  )
  (princ)
)

 

Thank you very much

 
I wrote in a hurry

I mean That

 

but Is there another way?

 

and I need to get area of hatch

 

Posted
20 minutes ago, pkenewell said:

@mstb Simple method since you have AutoCAD 2020 is to temporarily turn off hatch layer. Start the BOUNDARY command on another layer > Pick the same internal point to make a polyline in the same area as the hatch, then use the "Geometric Center" Object Snap (GCEN at the command line) to draw a line or point at the center. Then you can delete the boundary polyline and turn the hatch layer back on.

 

EDIT: Note - I guess this method would not work with Islands. You would have to make a REGION and get the MomentOfInertia property?

Thank you very much

but I need that in lisp

Posted
2 minutes ago, mstb said:

Thank you very much

but I need that in lisp

Sorry can't help you with that right now. Too much code for my free time. Perhaps someone else is charitable.

Posted
6 minutes ago, mstb said:

Thank you very much

 

I wrote in a hurry

I mean That

 

but Is there another way?

 

and I need to get area of hatch

 

You should slow down and post code that somewhat looks like you're trying to solve this yourself 😉

 

You can use something like to to get the area ( bear in mind that not all hatches have an area ).

(if
  (and (setq o (car (entsel)))
       (= 'real (type (setq r (vl-catch-all-apply 'vla-get-area (list (vlax-ename->vla-object o))))))
  )
   r
)

 

Posted
1 hour ago, ronjonp said:

You should slow down and post code that somewhat looks like you're trying to solve this yourself 😉

 

You can use something like to to get the area ( bear in mind that not all hatches have an area ).


(if
  (and (setq o (car (entsel)))
       (= 'real (type (setq r (vl-catch-all-apply 'vla-get-area (list (vlax-ename->vla-object o))))))
  )
   r
)

 

Thank you very much

Posted
1 hour ago, pkenewell said:

Sorry can't help you with that right now. Too much code for my free time. Perhaps someone else is charitable.

Thank you very much

Posted

I got this from here a while ago

 

(defun c:CtrCoo (/ findctr a apt) ;;Center point of a hatch or a rectangle
  
  (defun findctr (en / pt)
    (command "_.Zoom" "_Object" en "")
    (setq pt (getvar 'viewctr))
    (command "_.Zoom" "_Previous")
    pt
    )
    (setq a (car (entsel "Select Rectangle: : "))
	apt (findctr a))
  (command "_Text" "_Justify" "_MC" apt 0.1 0 apt)
  (princ)
  )

Many apologies, I didn't record whose code it is

Posted
7 hours ago, Steven P said:

I got this from here a while ago

 


(defun c:CtrCoo (/ findctr a apt) ;;Center point of a hatch or a rectangle
  
  (defun findctr (en / pt)
    (command "_.Zoom" "_Object" en "")
    (setq pt (getvar 'viewctr))
    (command "_.Zoom" "_Previous")
    pt
    )
    (setq a (car (entsel "Select Rectangle: : "))
	apt (findctr a))
  (command "_Text" "_Justify" "_MC" apt 0.1 0 apt)
  (princ)
  )

Many apologies, I didn't record whose code it is

Thank you very much

Posted

Something like this, using bpoly as suggested would get a pt in an area with no hatch by picking the pline created.

 

(defun c:cenpt ( / oldsnap pt)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 1024)
(princ (setq pt (getpoint "\npick object hatch pline etc ")))
(setvar 'osmode oldsnap)
(princ)
)

 

Posted (edited)
11 hours ago, BIGAL said:

(defun c:cenpt ( / oldsnap pt) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 1024) (princ (setq pt (getpoint "\npick object hatch pline etc "))) (setvar 'osmode oldsnap) (princ) )

 

@BIGAL The Geometric Center Osnap does not work on Hatch objects. Even with the OSOPTIONS system variable bit 1 not set.

 

EDIT: Sorry - you were noting using the BOUNDARY or BPOLY command like I was earlier. Agreed. Also  note like I said earlier - this would not work accurately for hatches with islands, depending on how they interpret the "center" of the hatch.

 

EDIT 2: Another option would be to just select the Hatch and turn on the boundary display! I tested this with the GCEN osnap and it works.

 

Screen Shot 11-05-20 at 09.53 AM.JPG

Edited by pkenewell
Posted

Yeah did say use for pline then added the word "hatch" in the defun now removed in post, thanks.

 

Interesting once I added a bulge to a pline Gcen does not work Civ3D 2020 same with Bricscad.

 

 

 

 

Posted
15 hours ago, BIGAL said:

Yeah did say use for pline then added the word "hatch" in the defun now removed in post, thanks.

 

Interesting once I added a bulge to a pline Gcen does not work Civ3D 2020 same with Bricscad.

 

 

 

 

Hmmm. Seems to work fine for me in Vanilla AutoCAD 2021. Quirks...

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