Jump to content

Geometric Center improved?


Recommended Posts

Posted (edited)

It's been a while since I've been on cad, I got really excited when I saw the OSnap, to snap to the center of a square, but that's not really what it is. It has to be a closed object. 

 

I was wondering if there have been any improvements or a lisp that someone has came up with. Maybe it would first have to create a boundary? 

 

I just do a lot of work placing things right in the center or 2' x 2' act ceiling tiles. It wouldn't be a super time saver, because there is always snap midway between two points, and also, I can copy from the point of a corner, but..it would be pretty cool.

Edited by Doctor Nocturnal
typo
Posted

You could use the M2P command modifier. For example, if you need to place a block at the midpoint between two lines, Start the Move command, select the block, choose a base point on the block, then type M2P. Now click on the endpoint of one line and the endpoint of the other line and the block will be placed at the midpoint between the two endpoints you selected.

 

Edit: I just re-read your post and it sounds like maybe you already know about M2P?

Posted

Let's say you want to snap to the center of several rectangles (closed or open or part of a grid) such as the following:

image.png.50d8184df82f9b738dd34144be18ba49.png

 

You could create a single polyline  (red) from corner to opposite corner using osnap end and intersection and then use osnap midpoint to snap the block to the centers. The single polyline is then easily deleted.

image.png.75573917e6a9e4388240e1f5555768e8.png

 

image.png

Posted

Like Lrm just pick inside each shape use bpoly and a quick and dirty is that 4 points of the pline created the mid of pt1 + pt3 is the answer.

 


(defun c:test ( / co-ord pt1 pt2 dist ang )
(while (setq pt (getpoint "Pick a point inside"))
(command "bpoly" pt "")
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget  (entlast)))))
(setq pt1 (nth 0 co-ord))
(setq pt2 (nth 2 co-ord))
(setq ang (angle pt1 pt2))
(setq dist (/ (distance pt1 pt2) 2.0))
(setq pt1 (polar pt1 ang dist))
(command "erase" (entlast) "")
(command "line" pt2 pt1 "")
)
)
(c:test)

Posted
; Middle Object Osnap
; Macro: ^P(or midobj (load "midobj.lsp")(princ))(midobj) 
(defun midobj (/ ll ur selection pntlist pnts adoc)
  (setq selection (car (entsel))
          adoc   (vla-get-activedocument (vlax-get-acad-object))
  )
  (vla-getboundingbox (vlax-ename->vla-object selection) 'll 'ur)
  (setq pntlist  (mapcar 'vlax-safearray->list (list ll ur)))
  (list(/(+(caar pntlist)(caadr pntlist))2.0)(/(+(cadar pntlist)(cadadr pntlist))2.0))
)

or

;Center of closed polygon
;^P(or C:pc1 (load "pc1.lsp"))(pc1)
; (load "pc1.lsp")(pc1)
(defun pc1 ( / acdoc acspc acsel reg pt) (vl-load-com) ;; © Lee Mac 2011

  (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
        acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
  )
;  (if (ssget "+.:E:S")
  (if (ssget "+.:E:S" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))
    (progn
      (vlax-for obj (setq acsel (vla-get-ActiveSelectionSet acdoc))
        (setq pt(trans (vlax-get (setq reg (car (vlax-invoke acspc 'addregion (list obj)))) 'Centroid) 1 0))
        (vla-delete reg)
      )
      (vla-delete acsel)
    )
  )
  pt
)

or something in this thread: https://www.cadtutor.net/forum/topic/43811-display-hatch-area-as-a-label/?tab=comments#comment-358082

 

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