Jump to content

Move object from mid between two points to mid between two points


Recommended Posts

Posted

Anybody can make a lisp program: Move objects with a base point from Mid between two points, then move and paste to Mid between two points.

 

Thanx!

Posted

Just use "_m2p" OSNAP... Type command OSNAP and turn snaps to for ex. "_int", "_mid", "_end" and turn on check for activation - or press F3... Then when you want to move, type MOVE, select object(s), when asked for first point, ctrl+right mouse click, find "_m2p" OSNAP, pick first helper point, pick second helper point (remember that now these points are helpers and picking reactor reacts according to previously set OSNAP - so real picked point will be mid between these two helper picked points), and finally when asked for destination point, do the same as with first source point... Object(s) will be moved as your request...

Posted

You may instead resort to M2P command modifier; it will allow you to get the middle point between two picked points.

 

 

By the way, by posting the same thread twice you will just split the discussion; please ask a Moderator to join them. Thank you.

Posted

Sometimes, that's the way I did, but if there is another way to do just in one command, in a lisp who can do for it, I really appreciate it.

Posted
(defun c:mm2p ( / p1 p2 p3 p4 ss )
   (if
       (and
           (setq ss (ssget "_:L"))
           (setq p1 (getpoint "\n1st Point of Mid for Basepoint: "))
           (setq p2 (getpoint "\n2nd Point of Mid for Basepoint: "))
           (setq p3 (getpoint "\n1st Point of Mid for Next point: "))
           (setq p4 (getpoint "\n2nd Point of Mid for Next point: "))
       )
       (command "_.move" ss ""
           "_non" (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2)
           "_non" (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p3 p4)
       )
   )
   (princ)
)

Posted

Thank you Lee!!

This is what I really want.

Simple routine but great!!

  • 3 weeks later...
Posted

Lee,

Your web postings have been and are a great help to me.

 

There is a new snap, MTP, that snaps to the midpoint between any two points. Any type of point input is allowed (including other snaps, e.g. int,app,cen,etc.). It is in 2013 but I don't know in which version it was first introduced. Since it is not lisp based but an input option it can be used during the execution of any lisp routine.

Posted

Re: MTP. It's a command modifier and can be invoked within a command by typing MTP or M2P. Works both ways. I think someone already mentioned this.

Posted

I modified my "F1" key in the CUI to iniate M2P and use it like an osnap. No need for special codes. I use it to center text in BOM cells, etc.

Posted

Just replying to Lee in case he had not heard of MTP ... but upon closer inspection his code is to use two midpoints to move something as the OP had asked for. I wondered why an expert like Lee would not have known about MTP (or M2P). My eyesight is going along with my memory (and a few other things). I saw Lee defun-ing c:m2p instead of c:mm2p. It was just me not paying close enough attention. My apologies Lee.

Posted

Lee is more of a programmer than a day-to-day AutoCAD user. Most of us prefer it that way as his custom lisp routines have often saved us from ourselves and saved the day as well.

  • Like 1
Posted

Pretty awesome there Lee Mac, that's one I will use a lot. :thumbsup:

Posted
Lee,

Your web postings have been and are a great help to me.

 

There is a new snap, MTP, that snaps to the midpoint between any two points. Any type of point input is allowed (including other snaps, e.g. int,app,cen,etc.). It is in 2013 but I don't know in which version it was first introduced. Since it is not lisp based but an input option it can be used during the execution of any lisp routine.

 

Just replying to Lee in case he had not heard of MTP ... but upon closer inspection his code is to use two midpoints to move something as the OP had asked for. I wondered why an expert like Lee would not have known about MTP (or M2P). My eyesight is going along with my memory (and a few other things). I saw Lee defun-ing c:m2p instead of c:mm2p. It was just me not paying close enough attention. My apologies Lee.

 

No apologies necessary Henry, I can certainly see the source of the misunderstanding.

To clarify, I am aware of the mtp / m2p function, however, I will almost always opt to perform my own geometrical calculations within my programs over reliance on command modifiers, the geomcal utility, or any Express Tools.

 

Of course as you know, the program could equally be written:

(defun c:mm2p ( / ss )
   (if (setq ss (ssget "_:L"))
       (command "_.move" ss "" "m2p" "\\" "m2p" "\\")
   )
   (princ)
)

Finally, I'm delighted that my posts have been of benefit to you.

 

Pretty awesome there Lee Mac, that's one I will use a lot. :thumbsup:

 

Cheers Steve, I guess sometimes the simple ones are the most useful.

  • Like 1
  • 10 years later...
Posted

Hi all,

 

Just wondering, instead of the base point being selecting by the midpoint between 2 chosen points, could it be set up so the base point is the midpoint of a chosen closed polyline? Would be great to be able to simply click a polyline and move it by its midpoint instead of needing to choose 2 points to find the midpoint of to move from

Posted
7 hours ago, masterfal said:

Hi all,

 

Just wondering, instead of the base point being selecting by the midpoint between 2 chosen points, could it be set up so the base point is the midpoint of a chosen closed polyline? Would be great to be able to simply click a polyline and move it by its midpoint instead of needing to choose 2 points to find the midpoint of to move from

 

 

This should give you the mid point of a line or polyline, added a bit to do the move from Lee Macs example above -chose which one you like to use

 

(defun c:Mid_Pt ( / Sel_Ent Sel_Obj Mid_Len Mid_Pt )
  (setq Sel_Ent (car (entsel)) )
  (setq Sel_Obj (vlax-Ename->Vla-Object Sel_Ent))
  (setq Mid_Len (/ (vla-get-length Sel_Obj ) 2 ))
  (setq Mid_Pt (vlax-curve-getPointAtDist Sel_Obj Mid_Len))
;;  Mid_Pt

;;;;;;;;;
;;Do nmove as you want for example:
  (setq p3 (getpoint "\n1st Point of Mid for Next point: "))
  (setq p4 (getpoint "\n2nd Point of Mid for Next point: "))
  (command "_.move" Sel_Ent ""
           "_non" Mid_Pt
           "_non" (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p3 p4)
  )
;;;;;;;;;


)

 

which you could use to move a polyline

Posted

@Steven P Since not all curve objects have an ActiveX length property (namely, arcs, circles, etc.); it may be better to obtain the midpoint using a function such as the following, which will work with any curve object of finite length:

(defun curvemidpoint ( ent )
    (vlax-curve-getpointatdist ent
        (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2.0)
    )
)

 

  • Like 1
Posted
7 minutes ago, Lee Mac said:

@Steven P Since not all curve objects have an ActiveX length property (namely, arcs, circles, etc.); it may be better to obtain the midpoint using a function such as the following, which will work with any curve object of finite length:

(defun curvemidpoint ( ent )
    (vlax-curve-getpointatdist ent
        (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2.0)
    )
)

 

 

Thanks Lee, that is better

Posted

Is it mid point of length or a GCEN ie centre of closed pline.

  • Like 1
Posted
On 7/1/2023 at 11:06 AM, BIGAL said:

Is it mid point of length or a GCEN ie centre of closed pline.

 

yeh i was referring to the centre of a closed polyline. ie moving centre of one rectangle onto the centre of a different rectangle. apologies if i didn't explain clearly..

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