PDA

View Full Version : Create rectangle then move at center point


CISCO
2007-10-18, 09:01 PM
I need a simple lisp file to create a Rectangle using a GETPOINT (1st corner point), dimensions option (GETINT). Then I would like to move it from center point of Rectangle using _m2P (the mid pt of 2 points)...to wherever I choose without having to select the 2nd point. I figure there should be a way of doing it automatically by the 2 given dimensions. Let me know if I need to give more information.

I have been messing with Autolisp for about a month only. Thanks in advance.

tedg
2007-10-18, 10:01 PM
I need a simple lisp file to create a Rectangle using a GETPOINT (1st corner point), dimensions option (GETINT). Then I would like to move it from center point of Rectangle using _m2P (the mid pt of 2 points)...to wherever I choose without having to select the 2nd point. I figure there should be a way of doing it automatically by the 2 given dimensions. Let me know if I need to give more information.

I have been messing with Autolisp for about a month only. Thanks in advance.
Ok, here's a quick crude version. It probably doesn't need to be this complicated.
I took pieces of a couple of routines I wrote for different things and combined them.

It asks you for your start point, length and width.
Then the mid points of the vertical and horizontal sides and your in the move command

(defun C:test (/ len wid xp1 yp1 xp2 yp2 xp3 yp3 p1 p2 p3 p4 osm la xpt ypt)
(setq strt_point (getpoint "Select start Point"))(terpri)
(setq len (getdist "How wide?"))(terpri)
(setq wid (getdist "How high?"))(terpri)
(setq Xp1 (car strt_point))
(setq yp1 (cadr strt_point))
(setq p1 (list xp1 yp1 0))
(setq xp2 (+ xp1 len))
(setq yp2 yp1)
(setq p2 (list xp2 yp2 0))
(setq xp3 xp2)
(setq yp3 (+ yp2 wid))
(setq osm (getvar "osmode"))
(setq la (getvar "clayer"))
(setq p3 (list xp3 yp3 0))
(setq p4 (list xp1 yp3 0))
(setvar "osmode" 16384)
(command "layer" "t" "0" "S" "0" "" "")
(command "pline" p1 p2 p3 p4 "c")
(setvar "osmode" 2)
(setq xpt (getpoint "select your horizontal midpoint"))(terpri)
(setq ypt (getpoint "select your vertical midpoint"))(terpri)
(command "move" "last" "" ".y" xpt ".x" ypt ".z" "0")
(setvar "osmode" osm)
(setvar "clayer" la)
)
(princ)


Hope it helps, it's a start.
If I have time to improve it I'll re post.

good luck!

CISCO
2007-10-18, 11:06 PM
Okay...I just tried your lisp, it will take 3 onscreen selections (starting corner point, mid pt at vert, mid pt at horiz). I am trying to minimize the on screen selection to 1 only (the starting point). I imagine there must be some kind of calculus/trig formula where it uses the 2 dimensions and comes up with the last corner point automatically without having to input/select anything else. So far what I have will use 2 on screen selections. See the attachment to see what i have so far...Thanks anyway, and I will keep that lisp for future reference, since I am still learning a lot of the functions.
Ok, I just thought of this, can you make the rect move based on _mp2 of 2 opposing corners instead of the 2 midpoints of the 2 lines? That would solve my problem.

tedg
2007-10-18, 11:35 PM
Okay...I just tried your lisp, it will take 3 onscreen selections (starting corner point, mid pt at vert, mid pt at horiz). I am trying to minimize the on screen selection to 1 only (the starting point). I imagine there must be some kind of calculus/trig formula where it uses the 2 dimensions and comes up with the last corner point automatically without having to input/select anything else. So far what I have will use 2 on screen selections. See the attachment to see what i have so far...Thanks anyway, and I will keep that lisp for future reference, since I am still learning a lot of the functions.
Ok, I just thought of this, can you make the rect move based on _mp2 of 2 opposing corners instead of the 2 midpoints of the 2 lines? That would solve my problem.
Yea, like I said, it was quick and crude and more than it needed to be.
Yours is much cleaner.
I would imagine if you could find the mid point of the two corner rectangle selection points as your "move" base point that would work well. Maybe point filters?

I'm not sure how to do that, I may play around with that.
I'm sure the "AUGI code gurus" may have a quick answer for you.

BTW, in my routine, you can "type" the inches in like yours, you don't need to select screen points, so it's like yours with the bonus of being able to do both.

Mike_R
2007-10-18, 11:43 PM
Well, here's a nice simple little routine that does exactly what you're asking for. Was quick and dirty and wasn't well tested, but we'll see how it goes, eh? ;)


(defun C:RECT-MOVE (/ corner1 dist-x dist-y temp-1 temp-2 corner2 midpt)
(setq corner1 (getpoint "\nSelect Start Point.: ")
dist-x (getdist "\nDistance along X axis: ")
dist-y (getdist "\nDistance along Y axis: ")
corner2 (list (+ (car corner1) dist-x) (+ (cadr corner1) dist-y) 0)
midpt (list (+ (car corner1) (/ dist-x 2)) (+ (cadr corner1) (/ dist-y 2)) 0)
)
(vl-cmdf "._RECTANGLE" "_non" corner1 "D" dist-x dist-y "_non" corner2
"MOVE" "L" "" midpt pause)
(princ)
)
Cheers! :beer:

CISCO
2007-10-19, 04:29 PM
Thanks Mike, that did the trick...I figured pretty much all on your lisp, but I do have a question...i haven't researched this yet, and maybe you can explain what it means...
"vl-cmdf", What does that do or where can i go to figure it out? Thanks again.

h_reyes
2007-10-19, 08:28 PM
As I can see you are using "_non" in options commands.
Why you include it, what does "_non", what is its purpose?
I'm unsuccessful to find explanation in official documentation (I think "_non" is not documented at all...)

Opie
2007-10-19, 08:38 PM
As I can see you are using "_non" in options commands.
Why you include it, what does "_non", what is its purpose?
I'm unsuccessful to find explanation in official documentation (I think "_non" is not documented at all...)
It is specifying no osnap.

Mike_R
2007-10-19, 09:06 PM
Thanks Mike, that did the trick...I figured pretty much all on your lisp, but I do have a question...i haven't researched this yet, and maybe you can explain what it means...
"vl-cmdf", What does that do or where can i go to figure it out? Thanks again.
"vl-cmdf" is just the VLisp version of the "command" function. What it does is check to see if the "command" code will cause an error, and if it will, it does not run the command. In the bit of code that I posted, it's not very likely it'll error out, but I prefer to use "vl-cmdf" to "command" as a matter of principle.

To find more information about it, and probably a better explanation, check the developer help: Help - Additional Resources - Developer Help. On the contents tab open Autolisp Reference - AutoLisp Functions - V Functions - vl-cmdf.