Jump to content

Anyone know of a two click move routine?


Jamesclark64

Recommended Posts

About 10 years ago my boss at the time changed the move routine such that it used the first click (select object) as the location for the second click (specify basepoint) Essentially saving one click all together.  Does anyone know of such a routine? Or where I'd begin with coding this from scratch?

Link to comment
Share on other sites

If what you wish to move is selected prior to the MOVE command being issued, that's what you get.

 

Steve

Link to comment
Share on other sites

After selection (first click), you can click and hold (drag) on the selected object to move. That's 2 clicks.

Link to comment
Share on other sites

For a single object

 

(command "move" pause "" (getvar "lastpoint") pause)

 

Edited by Steven P
Link to comment
Share on other sites

(defun c:MoveSnap (/ basePoint ent entData newLocation moveVector)
  ;; Load the necessary Visual LISP extensions
  (vl-load-com)
  
  ;; Prompt user to select an object by clicking on it
  (princ "\nSelect object by clicking on it: ")
  (setq basePoint (getpoint))
  
  ;; Get the entity and its properties at the clicked point
  (setq entData (nentselp basePoint))
  
  ;; Check if an entity was selected
  (if (not entData)
    (princ "\nNo object selected or found at the point.")
    (progn
      ;; Extract the entity name from the selection
      (setq ent (car entData))
      
      ;; Prompt for new location
      (setq newLocation (getpoint "\nSpecify new location: "))
      
      ;; Calculate the movement vector
      (setq moveVector (mapcar '- newLocation (trans (cadr entData) 1 0)))
      
      ;; Use command to move the selected entity
      (command "_.move" ent "" "_non" basePoint "_non" newLocation)
    )
  )
  
  ;; Clean up and exit
  (princ)
)

(princ "\nType MoveSnap to move an object. ")
(princ)

 

Made by AI.

Link to comment
Share on other sites

A couple of options here:

 

(defun c:qmove ( / ) ;;single object selection
  (command "move" pause "" "_non" (getvar "lastpoint") pause)
)

 

which will allow the user to select a single object and move it, the base point being the point clicked on the object

 

and

 

(defun c:qmove ( / pt1 pt2 MySS ) ;; Single selection set selection
  (setq pt1 (getpoint "Select Objects, 'crossing points'"))
  (setq MySS (ssget "_W" pt1 (setq pt2 (getpoint "Select Objects, 'crossing points'"))))
  (command "move" MySS "" "_non" pt1 pause)
)

 

Which will move a single selection set, here based on a 'window' selection, everything within a rectangle made off the 2 clicked points. The base point is the first point clicked - swap over pt1 to pt2 in the move command for the second point clicked to be the base point.

 

 

But which way were you wanting this to work, many objects or a single object? (Many objects will need some tidying to make it a nicer LISP, single object works OK for me just now)

Link to comment
Share on other sites

and this version is a little better:

 

(defun c:qmove ( / pt1 MySS Var_Old)
  (setq MySS (ssget))
  (setq pt1 (cadr (grread t 15 0)) )
  (command "move" MySS "" pt1 pause )
  (princ)
)

 

Edited by Steven P
Link to comment
Share on other sites

On 13/02/2024 at 12:16, Steven P said:

A couple of options here:

 

(defun c:qmove ( / ) ;;single object selection
  (command "move" pause "" "_non" (getvar "lastpoint") pause)
)

 

Just tried everything here. And this works a treat.  Fantastic work. But is there a way I can get it to loop? But please don't worry if its a lot of work. 

 

 

Link to comment
Share on other sites

1 hour ago, Jamesclark64 said:

But is there a way I can get it to loop? But please don't worry if its a lot of work. 

@Jamesclark64 While this is not the best programming practice, putting the command in a loop is easy; you just have to ESC to stop it. Someone else here may have a better trick without making it a much bigger program.

(defun c:qmove ( / ) ;;single object selection
  (While T
     (command "._move" pause "" "_non" (getvar "lastpoint") pause)
  )
)

 

ACTUALLY - this is better programming practice and works the same without needing ESC to exit:

(defun c:qmove ( / e p) ;;single object selection
  (While (setq e (entsel "\nSelect Object: "))
     (setq p (cadr e) e (car e))
     (command "._move" e "" "_non" p pause)
  )
  (princ)
)

 

Edited by pkenewell
  • Like 1
Link to comment
Share on other sites

However for a 1 line piece of code, anything more complex for a loop is probably not so necessary. It might show an error in the command line (so add 15 lines of error checking code to make 1 line work)

Link to comment
Share on other sites

other way,

using the object interstion point or any type of line first vertex as base point:

(defun c:qmv ( / ent entd bpt )
 (while T
  (setq ent (car (entsel "\nSelect object to move:"))) ;select object to move, ESC or ENTER to exit
  (setq entd (entget ent))
  (setq bpt (cdr(assoc 10 entd))) ;get the object insertion point or the first vertex of *line(s)
  (command "move" ent "" bpt pause) ;move the object using bpt (the object insertion point or the first vertex of *line(s)) as base point.
 )
)

 

Link to comment
Share on other sites

1 minute ago, Steven P said:

However for a 1 line piece of code, anything more complex for a loop is probably not so necessary. It might show an error in the command line (so add 15 lines of error checking code to make 1 line work)

@Steven P Edited my original post to add another solution. not too much more code to make it the same and loop cleanly.

  • Like 1
Link to comment
Share on other sites

3 minutes ago, aridzv said:

ther way,

using the object interstion point or any type of line first vertex as base point:

See my added solution above for yours; (entsel) has a point return embedded in it and no (while T... is necessary

Link to comment
Share on other sites

3 minutes ago, pkenewell said:

@Steven P Edited my original post to add another solution. not too much more code to make it the same and loop cleanly.

 

That is probably best for this LISP I think

  • Like 1
Link to comment
Share on other sites

1 minute ago, pkenewell said:

See my added solution above for yours; (entsel) has a point return embedded in it and no (while T... is necessary

 

Your lisp used the base point as the user randomly selected point in the object.

Sometimes this is what the user prefers,

But there are situations where the user needs a specific point of the object and not a random point.

 

The code I wrote uses a defined point of the object

Link to comment
Share on other sites

Just now, aridzv said:

The code I wrote uses a defined point of the object

@aridzv Good "Point" (pardon the pun) 😅. I agree that's a good option. I was just replicating the original function the OP liked.

  • Like 1
Link to comment
Share on other sites

1 minute ago, pkenewell said:

@aridzv Good "Point" (pardon the pun) 😅. I agree that's a good option. I was just replicating the original function the OP liked.

Not necessarily...

Sometimes the user will prefer the original solution you wrote. Visually it is indeed much more comfortable. But sometimes a defined point of the object will be needed.

  • Like 1
Link to comment
Share on other sites

@aridzv I recommend you slightly change your code (sorry - can't help but mess with stuff):

(defun c:qmv ( / ent entd bpt )
   (while (setq ent (entsel "\nSelect object to move:")) ;select object to move, ENTER to exit
     (setq entd (entget (car ent)))
     (setq bpt (cdr (assoc 10 entd))) ;get the object insertion point or the first vertex of *line(s)
     (command "._move" ent "" "_non" bpt pause) ;move the object using bpt (the object insertion point or the first vertex of *line(s)) as base point.
   )
)

 

Edited by pkenewell
  • Like 1
Link to comment
Share on other sites

Here is a slightly slower version that allows multiple selection:

(defun c:qmovem ( / p ss)
  (princ "\nSelect Objects: ")
  (While (setq ss (ssget))
     (setq p (cadr (grread t 15 0)));<-- Thanks Steven P for this part!
     (command "._move" ss "" "_non" p pause)
     (princ "\nSelect Objects: ")
  )
  (princ)
)

 

EDIT: Updated to correct it based on Steven P feedback.

Edited by pkenewell
  • Like 1
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...