Customized move tool

Customized move tool

Anonymous
Not applicable
788 Views
6 Replies
Message 1 of 7

Customized move tool

Anonymous
Not applicable

Hello once again,

From time to time I need to move twice in a row the same object in ortogonal fashion:

- in example: 100 units left and then 50 unit up

- or: 50 units right and 20 units down etc.

 

I wrote this code that (almost) work...

It moves object up&right or up&left.

It swapped moving down&left with down&right and vice versa...

 

(defun c:magic_move (/ selection dist dist2 base quadrant move1 move2)

  	(setq selection (ssget))
	(setq dist (getreal "\nMagic move: "))
  	(setq dist2 (getreal "\nMagic move: "))
  	(setq base (getpoint "\nBase point: "))
  	(setq quadrant (getpoint base))
   	
	(if (> (car quadrant) (car base))
	  	(if (> (cadr quadrant) (cadr base))
			(setq 	move1 	(polar base 0 dist)			;right
				move2	(polar base (/ pi 2) dist2)		;up
			)
	  	)

	  	(if (< (cadr quadrant) (cadr base))
			(setq	move1	(polar base 0 dist)			;right
				move2	(polar base (* 1.5 pi) dist2)		;down
			)
		)
	)

	(if (< (car quadrant) (car base))
	  	(if (> (cadr quadrant) (cadr base))
		  	(setq 	move1 	(polar base pi dist)			;left
			      	move2	(polar base (/ pi 2) dist2)		;up
			)
		)
	
		(if (< (cadr quadrant) (cadr base))
		  	(setq 	move1	(polar base pi dist)			;left
			      	move2	(polar base (* 1.5 pi) dist2)		;down
			)
		)
	)

(magic_move move1 move2)

); defun

(defun magic_move (move1 move2)

  	(command "move" selection "" base move1 "")
  	(command "move" selection "" base move2 "")
  	(princ)
  
); defun

Anyone sees this bug?

 

0 Likes
789 Views
6 Replies
Replies (6)
Message 2 of 7

dlanorh
Advisor
Advisor

Have a look at this topic. https://www.theswamp.org/index.php?topic=55529.0 

I am not one of the robots you're looking for

0 Likes
Message 3 of 7

doaiena
Collaborator
Collaborator

Just point to a direction with the mouse and write the number of units you want to move with.

(defun c:test ( / ss basePt p1 p2)

(if (setq ss (ssget))
(progn

(while (not basePt) (setq basePt (getpoint "\nPick base point: ")))
(while (not p1) (setq p1 (getpoint basePt "\nPick next point or enter distance: ")))
(while (not p2) (setq p2 (getpoint p1 "\nPick last point or enter distance: ")))
(command "move" ss "" basePt p2)
))

(princ)
);defun



PS: Just had another idea. Infinite moves, until you end the command.

(defun c:test ( / ss basePt flag p1)

(if (setq ss (ssget))
(progn

(while (not basePt) (setq basePt (getpoint "\nPick base point: ")))
(setq flag T)

(while flag
(if (setq p1 (getpoint basePt "\nPick next point or enter distance: "))
(progn
(command "move" ss "" basePt p1)
(setq basePt p1 p1 nil)
)
(setq flag nil)
)
)

(princ "\nDone!")
))

(princ)
);defun

 

0 Likes
Message 4 of 7

hak_vz
Advisor
Advisor

@Anonymous wrote:

Hello once again,

From time to time I need to move twice in a row the same object in ortogonal fashion:

- in example: 100 units left and then 50 unit up

- or: 50 units right and 20 units down etc.


Ok. the only tricky point is when you dont know horizontal and vertical displacent. We all know that any transition has its on horizontla and vertical part, ortogonality is there . If you have to make ortogonal transitions in rotated coordinated system change it.  Moving objects using "@" relative coordinate is easy. Polar tracking too.

 


@Anonymous wrote:
(defun c:magic_move (/ selection dist dist2 base quadrant move1 move2)

  	(setq selection (ssget))
	(setq dist (getreal "\nMagic move: "))
  	(setq dist2 (getreal "\nMagic move: "))
  	(setq base (getpoint "\nBase point: "))

This equals move @dist1,dist2

 

I wont answer your task by writing some new code , but will show here my helper functions to store variable, distance, selection set or a point into a named global variables, and also helper to review and clear globals (saved in a list). I've added a function rm to perform relative move. Maybe you find it usefull.

(setq globals nil)
(defun c:globals () globals)
(defun twodec (x)(atof(rtos x 2 2)))
(defun c:clear ()
	;clears all global variable generated by our macros 
	(while (and globals) (set (read (car globals)) nil) (setq globals (cdr globals)))
	(if (not globals) (alert "Autolisp globals have been cleared!"))
	(princ)
)

(defun odefined (p / defined i)
	(setq defined nil i 0)
	(if globals 
		(repeat (length globals)
			(if (= p (nth i globals))(setq defined T))
		(setq i (+ i 1))
		)
	)
	defined
)

(defun c:gd (/ pp _name)
;get distance and assign to variable name
	(setq pp (atof(rtos(distance (getpoint "\nSelect first point > ")(getpoint "\nSelect second point > ")) 2 5)))
	(setq _name (getstring "\n Naziv variable > "))
    (set (read _name) pp)
	(princ)	
	(setq globals (cons _name globals))
	(strcat _name " = " (rtos pp 2 5))

)

(defun c:gp ( / pp _name)
;get point and assign to variable name
	(setq pp (mapcar 'twodec (getpoint "\nSelect point > "))
		_name (getstring "\n Variable name > "))
    
	(set (read _name) pp)
	(setq globals (cons _name globals))
	pp
)

(defun c:sv( / pp _name)
	;assign value to variable name
	(setq pp (getreal "\n Enter value >"))
	(setq _name (getstring "\n Variable name > "))	
	(setq globals (cons _name globals))
    (set (read _name) pp)

)

(defun c:ss( / pp _name)
	;assign name to some selection set
	(setq pp (ssget))
	(setq _name (getstring "\n Variable name > "))	
	(setq globals (cons _name globals))
    (set (read _name) pp)
)


(defun c:rm (/ hor ver ss)
(setq hor (getreal "\nHorizontal distance >")
	  ver (getreal "\nvertical distance >")
	  ss (ssget)
)
(command "move" ss "" (list 0 0) (strcat "@" (rtos hor 2 5) "," (rtos ver 2 5 ) ""))
(princ) 
)

 

To function rm you may answer with stored variables for some measured distance. If you named your variable "a" then you recall it with as "!a".  Or any number you like.

 

Or you may store object to named selection set (let say a) with comand ss and move it with command move and polar tracking. Sorry, don't see a need for special code to do that.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 7

hak_vz
Advisor
Advisor

If you need to move previous object repeatedly you may use acads "move" command option previous.

Command: m
Select entities to move: p

That way you avoid continuous reselection of same object(s). At first iteration you may answer with the name of your previously defined selection set name you stored into a global variable. With polar tracking or ortho on you just select previous entity(es), click wherever, move a mouse to desired direction and type a distance.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 7

Anonymous
Not applicable

@doaiena @hak_vz @dlanorh 

Thank you for your ideas. Nevertheless, I found myself the bug in my code... after "if statements" there was missing "progn". I guess my initial code didn't evalute the "inner if statements" properly...

 

(defun c:magic_move (/ selection dist dist2 base quadrant move1 move2)
  	(setq selection (ssget))
	(setq dist (getreal "\nMagic move: "))
  	(setq dist2 (getreal "\nMagic move: "))
  	(setq base (getpoint "\nBase point: "))
  	(setq quadrant (getpoint base))

	(if (> (car quadrant) (car base))
	(progn
	  	(if (> (cadr quadrant) (cadr base))
			(setq 	move1 	(polar base 0 dist)			;right
				move2	(polar base (/ pi 2) dist2)		;up
			)
	  	)

	  	(if (< (cadr quadrant) (cadr base))
			(setq	move1	(polar base 0 dist)			;right
				move2	(polar base (* 1.5 pi) dist2)		;down
			)
		)
	)
	)

	(if (< (car quadrant) (car base))
	(progn
	  	(if (> (cadr quadrant) (cadr base))
		  	(setq 	move1 	(polar base pi dist)			;left
			      	move2	(polar base (/ pi 2) dist2)		;up
			)
		)
	
		(if (< (cadr quadrant) (cadr base))
		  	(setq 	move1	(polar base pi dist)			;left
			      	move2	(polar base (* 1.5 pi) dist2)		;down
			)
		)
	)
	)

(magic_move move1 move2)
); defun

(defun magic_move (move1 move2)
  	(command "move" selection "" base move1 "")
  	(command "move" selection "" base move2 "")
  	(princ)
); defun

Now it's working!

 

 

0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

Much simpler wrote 2 defuns Chx Chy as the name implies asks for distance + / - then pick objects.

 

 

(defun C:CHX ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (setq x 0)
  (princ "\nalters object in X direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat ht ",0"))
  (while (= x 0)
    (setq newobj (entsel "\nPoint to object: "))
    (if (/= newobj nil)
    (progn
    (command "move" newobj "" "0,0" newht)
    ))
  (if (= newobj nil)(setq x 1))
  )
)
;
(defun C:CHY ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (setq x 0)
  (princ "alters object in Y direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat  "0," ht))
  (while (= x 0)
  (SETQ NEWobj (entsel "\nPoint to object: "))
  (if (/= newobj nil)
  (progn
  (command "move" newobj "" "0,0" newht)
  ))
  (if (= newobj nil)(setq x 1))
  )
  )


;simple routine to change objects in the z direction
(defun C:CHZ ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (setq x 0)
  (princ "alters object in Z direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat "0,0," ht))
  (while (= x 0)
  (SETQ NEWobj (entsel "\nPoint to object: "))
  (if (/= newobj nil)
  (progn
  (command "move" newobj "" "0,0,0" newht)
  ))
  (if (= newobj nil)(setq x 1))
  )
  )

0 Likes