IS THERE ANY LISP TO MOVE OBJECT TO A PARTICULAR COORDINATE

IS THERE ANY LISP TO MOVE OBJECT TO A PARTICULAR COORDINATE

arpansark0544TCX
Advocate Advocate
3,135 Views
12 Replies
Message 1 of 13

IS THERE ANY LISP TO MOVE OBJECT TO A PARTICULAR COORDINATE

arpansark0544TCX
Advocate
Advocate

wHAT I AM SEARCHING FOR IS A LISP WHICH COULD ASK ME TO SELECT A POINT IN MODEL SPACE AND TAKE IT'S COORDINATE AND MOVE THE REQUIRED OBJECT TO THAT COORDINATE.

AS IT CAN REDUCE DRAG AND DROP TIME WE USUALLY DO IN MOVE OR COPY COMMANDS.

0 Likes
Accepted solutions (4)
3,136 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

I don't see the time savings.  What difference does it make whether you pick the location to Move something to before or after the Move command starts?  You still need to pick the location.  How is the object to be Moved determined?  Does selecting it need to be part of the routine, or is it already determined somehow?  I think a detailed description of the steps you expect to take and things you expect to happen, in order, would be helpful.

 

But in any case:  Move what location on the required object to that point?  Do you need to pick that, too?  Or will the object always be something with an obvious location on it to use [a Block's or Text's insertion point, a Circle's center, maybe a Line's midpoint but maybe you want an endpoint (which one?), etc.]?

Kent Cooper, AIA
Message 3 of 13

hak_vz
Advisor
Advisor
Accepted solution

You don't need any special lisp, just basic autolisp function (getpoint).

Autolisp basics that any cad user should know.

Watch my screencast here!

 

(setq m (getpoint "\nSelect destination point >"))
Make it a function

(defun c:gp nil (setq m (getpoint "\nSelect destination point >")))

 

To call point coordinates type m (variable name) with ! in front   m  -->  !m

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.
Message 4 of 13

arpansark0544TCX
Advocate
Advocate
THANK YOU VERY MUCH . IT WORKED
Message 5 of 13

hak_vz
Advisor
Advisor
Accepted solution

Here are some of functions that I regularly use. GP to store point inside global variable, SV to set some value, and GD to get some distance and store to variable. You can create any named variable you want (not just m as in sample above). This variables are then transmitted through all open drawings. So for example you can take a point in one drawing, and do what ever you need to same named variable in any other drawing (move, connect a line ....)

(defun twodec (x)(atof(rtos x 2 3)))

(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 Variable name for distance > "))
    (set (read _name) pp)
	(vl-propagate (read _name))
	(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)
	(vl-propagate (read _name))
	pp
)

(defun c:sv( / pp _name)
	;assign value to variable name
	(setq pp (getstring "\n Enter value or expression >"))
	(setq _name (getstring "\n Variable name> "))	
    (set (read _name) (eval (read pp)))
	(vl-propagate (read _name))

)

 

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.
Message 6 of 13

arpansark0544TCX
Advocate
Advocate

Can we take the idea further and is it possible to place object at the intersection of multiple polylines. 

Lisp should identify the crossing/intersection of polylines/xlines. And store the coordinates of the intersection and copy the object selected to the obtained coordinates.

I know it can be done by array but some minor dimension error always comes.

Thank you for the help.

 

arpansark0544TCX_0-1647001934862.png

 

0 Likes
Message 7 of 13

hak_vz
Advisor
Advisor
Accepted solution

Try this

 

(defun c:foo (/ *error* take pointlist3d get_intersections get_intersection_points adoc ss ob pt i j ipts all_ipts)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(princ)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist3d (lst / ret) (while lst (setq	ret (cons (take 3 lst) ret) lst (cdddr lst))) (reverse ret))
	(defun get_intersections	(obj1 obj2 / var)
		(setq var (vlax-variant-value (vla-intersectwith obj1 obj2 0)))
		(if (< 0 (vlax-safearray-get-u-bound var 1))(vlax-safearray->list var))
	)
	(defun get_intersection_points (obj1 obj2) (pointlist3d (get_intersections obj1 obj2)))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(princ "\nSelect gridlines to find intersections >")
	(setq 
		ss (ssget '((0 . "LINE,LWPOLYLINE,XLINE")))
		ob (car(entsel "\nSelect object to copy over grid>"))
		pt (getpoint "\nPick attachment point for selected object >")
		i -1
	)
	(cond
		((and pt ob ss )
		(while (< (setq i (1+ i)) (sslength ss))
			(setq eo (vlax-ename->vla-object (ssname ss i)))
			(setq j -1)
			(while (< (setq j (1+ j)) (sslength ss))
				(if(/= i j)
						(foreach m (get_intersection_points eo (vlax-ename->vla-object (ssname ss j)))
							(if (not (member m all_ipts)) 
								(setq  all_ipts (cons m all_ipts))
							)
						)
				)
			)
		)
		(vla-endundomark adoc)
		(vla-startundomark adoc)
		(setvar 'cmdecho 0)
		(foreach ipt all_ipts
			(command "_.copy" ob "" pt ipt"")
		)
		(setvar 'cmdecho 1)
		(vla-endundomark adoc)
		)
	)
    (princ)
)

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 8 of 13

arpansark0544TCX
Advocate
Advocate
Thank you very much sir @hak_vz.
This is an awesome lisp. It is working smooth as butter.
0 Likes
Message 9 of 13

arpansark0544TCX
Advocate
Advocate

Sir after working a while on the file I found that in some files the object is copied to a different location.

I have attached the DWG file for your reference.

arpansark0544TCX_0-1647063894163.png

 

0 Likes
Message 10 of 13

hak_vz
Advisor
Advisor

I'll check the code as soon as I get some tome to spend on it.

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.
Message 11 of 13

ВeekeeCZ
Consultant
Consultant

Once we learn the basics well enough (ARRAY / COPY-ARRAY) these routines come obsolete.

Message 12 of 13

arpansark0544TCX
Advocate
Advocate
I agree. But array cannot place objects with different distances between them.
And then this type of awesome routine by @hak_vz comes into play.

0 Likes
Message 13 of 13

ВeekeeCZ
Consultant
Consultant

Also COPYM command is worth exploring.