Jamesclark64 Posted February 12 Posted February 12 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? Quote
StevJ Posted February 13 Posted February 13 If what you wish to move is selected prior to the MOVE command being issued, that's what you get. Steve Quote
enthralled Posted February 13 Posted February 13 After selection (first click), you can click and hold (drag) on the selected object to move. That's 2 clicks. Quote
fuccaro Posted February 13 Posted February 13 Or use the grips if we are talking about single graphical entities or blocks or groups... Quote
Steven P Posted February 13 Posted February 13 (edited) For a single object (command "move" pause "" (getvar "lastpoint") pause) Edited February 13 by Steven P Quote
enthralled Posted February 13 Posted February 13 (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. Quote
Steven P Posted February 13 Posted February 13 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) Quote
Steven P Posted February 13 Posted February 13 (edited) 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 February 14 by Steven P Quote
Jamesclark64 Posted February 14 Author Posted February 14 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. Quote
pkenewell Posted February 14 Posted February 14 (edited) 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 February 14 by pkenewell 1 Quote
Steven P Posted February 14 Posted February 14 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) Quote
aridzv Posted February 14 Posted February 14 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. ) ) Quote
pkenewell Posted February 14 Posted February 14 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. 1 Quote
pkenewell Posted February 14 Posted February 14 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 Quote
Steven P Posted February 14 Posted February 14 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 1 Quote
aridzv Posted February 14 Posted February 14 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 Quote
pkenewell Posted February 14 Posted February 14 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. 1 Quote
aridzv Posted February 14 Posted February 14 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. 1 Quote
pkenewell Posted February 14 Posted February 14 (edited) @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 February 14 by pkenewell 1 Quote
pkenewell Posted February 14 Posted February 14 (edited) 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 February 14 by pkenewell 1 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.