mstb Posted November 3, 2020 Posted November 3, 2020 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. Quote
ronjonp Posted November 3, 2020 Posted November 3, 2020 (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 November 3, 2020 by ronjonp Quote
pkenewell Posted November 3, 2020 Posted November 3, 2020 (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 November 3, 2020 by pkenewell Quote
mstb Posted November 3, 2020 Author Posted November 3, 2020 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 Quote
mstb Posted November 3, 2020 Author Posted November 3, 2020 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 Quote
pkenewell Posted November 3, 2020 Posted November 3, 2020 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. Quote
ronjonp Posted November 3, 2020 Posted November 3, 2020 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 ) Quote
mstb Posted November 3, 2020 Author Posted November 3, 2020 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 Quote
mstb Posted November 3, 2020 Author Posted November 3, 2020 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 Quote
Steven P Posted November 3, 2020 Posted November 3, 2020 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 Quote
mstb Posted November 4, 2020 Author Posted November 4, 2020 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 Quote
BIGAL Posted November 5, 2020 Posted November 5, 2020 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) ) Quote
pkenewell Posted November 5, 2020 Posted November 5, 2020 (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. Edited November 5, 2020 by pkenewell Quote
BIGAL Posted November 5, 2020 Posted November 5, 2020 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. Quote
pkenewell Posted November 6, 2020 Posted November 6, 2020 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... Quote
Recommended Posts
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.