Jump to content

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


notview

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

(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)
)

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 10 years later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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