Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Beginner Question

8 REPLIES 8
Reply
Message 1 of 9
robkimross
465 Views, 8 Replies

Beginner Question

I am trying to teach myself some Autolisp, people who new it are now gone. what i need to do is pick 2 diagonal points and then draw a rectangle a set distance around it. No problem there, but the rectangle must be an integer. I've tried using FIX but with no luck. Any help would be greatly appreciated
8 REPLIES 8
Message 2 of 9
t.willey
in reply to: robkimross

Post what you have so far so people can just help you modify you code to work instead of writting a whole new code.

Tim
Message 3 of 9
Anonymous
in reply to: robkimross

There are lots of ways to do that 1; (initget 1) (setq p1 (getpoint "\nFirst Corner: ")) (initget 1) (setq p2 (getcorner p1 "\nOpposite Corner: ")) (setq p1 (mapcar 'fix p1) p2 (mapcar 'fix p2)) This always rounds down positives, rounds up negatives. If you need to round to the nearest point, then more code would be required. -David rjt205 wrote: > I am trying to teach myself some Autolisp, people who new it are now gone. what i need to do is pick 2 diagonal points and then draw a rectangle a set distance around it. No problem there, but the rectangle must be an integer. I've tried using FIX but with no luck. Any help would be greatly appreciated
Message 4 of 9
robkimross
in reply to: robkimross

here is what i've got. Thanks for the help.

(DEFUN DIESET (/
A ;lower left point of die stls
B ;upper right point of die stls
L1 ;X distance of die stls
W1 ;Y distance of die stls
P1 ;lower left point of die set
P2 ;lower right point of die set
P3 ;upper right point of die set
P4 ;upper left point of die set
A
B

)

(SETQ A (GETPOINT "\n PICK LOWER LEFT INTERSECTION:"))
(SETQ B (GETPOINT "\n PICK UPPER RIGHT INTERSECTION:"))
(setq L1 (list (- (car B) (car A))))
(setq W1 (list (- (cadr B) (cadr A))))
(setq P1 (list (- fix (car A)) 1) (- fix (cadr A)) 4)))
(setq P2 (list (+ fix (car B)) 1) (- fix (cadr A)) 4)))
(setq P3 (list (+ fix (car B)) 1) (+ fix (cadr B)) 4)))
(setq P4 (list (- fix (car A)) 1) (+ fix (cadr B)) 4)))
(command "line" P1 P2 P3 P4 "C")
Message 5 of 9
Anonymous
in reply to: robkimross

Just curious david, but why didnt his version of 'fix' work as opposed to yours; is he applying the fix on each line similar to the way mapcar is doing it? ta "David Bethel" wrote in message news:4149eb41$1_1@newsprd01... > There are lots of ways to do that 1; > > > (initget 1) > (setq p1 (getpoint "\nFirst Corner: ")) > (initget 1) > (setq p2 (getcorner p1 "\nOpposite Corner: ")) > (setq p1 (mapcar 'fix p1) > p2 (mapcar 'fix p2)) > > This always rounds down positives, rounds up negatives. If you need to > round to the nearest point, then more code would be required. -David > > rjt205 wrote: > > > I am trying to teach myself some Autolisp, people who new it are now gone. what i need to do is pick 2 diagonal points and then draw a rectangle a set distance around it. No problem there, but the rectangle must be an integer. I've tried using FIX but with no luck. Any help would be greatly appreciated
Message 6 of 9
Anonymous
in reply to: robkimross

(setq P1 (getpoint "\nPick Lower Left Intersection: ")) (setq P2 (getcorner P1 "\nPick Upper Right Intersection: ")) ;this will draw rectangle rubberband (setq L1 (fix (- (car P2) (car P1)))) ; set length to integer (setq W1 (fix (- (cadr P2) (cadr P1)))) ; set width (height) to integer ; this starts the rectangle at the lower left intersection (setq P2 (polar P1 0.0 L1)) (setq P3 (polar P2 (/ pi 2) W1)) (setq P4 (polar P1 (/ pi 2) W1)) (command "LINE" P1 P2 P3 P4 "C") ;to center between 2 selected points (setq P1 (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0))) (setq P1 (polar P1 pi (/ L1 2.0))) (setq P1 (polar P1 (/ pi -2) (/ W1 2.0))) (setq P2 (polar P1 0.0 L1)) (setq P3 (polar P2 (/ pi 2) W1)) (setq P4 (polar P1 (/ pi 2) W1)) (command "LINE" P1 P2 P3 P4 "C") Notes - you might want to save current osnap settings, turn off before program and turn on when finished
Message 7 of 9
Anonymous
in reply to: robkimross

My guess would be that due to the fact he is obtaining L1 & W1 without changing the points to integers, his math is giving misleading results. As to the (fix), it is a matter of personal preference. I'm a little lazy as far as typing goes. Less is better. -David pi wrote: > Just curious david, > but why didnt his version of 'fix' work as opposed to yours; is he applying > the fix on each line similar to the way mapcar is doing it? > ta >
Message 8 of 9
robkimross
in reply to: robkimross

I tried copy/paste your code, adding (defun temp (), it would load fine but when i typed temp it did not recognize it as a valid command. I also think I haven't explained my task very well. attached is an example of what I'm trying to do. The small rect is existing before running my lisp, the larger is what I am trying to construct. Notice decimal places
Message 9 of 9
Anonymous
in reply to: robkimross

(defun c:temp () .....

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost