Autolisp - Change value in coordinates

Autolisp - Change value in coordinates

traci_haberghamJQEJT
Enthusiast Enthusiast
662 Views
5 Replies
Message 1 of 6

Autolisp - Change value in coordinates

traci_haberghamJQEJT
Enthusiast
Enthusiast

Good morning all,

I'm looking to create a command to rule a line either in the x or y direction from the initial point that the user chooses.

 

I can get the point but I'm unsure on the best way to update the value within the co-ordinates!

What is the best way to add 20000 to the x value of a coordinate?

 

Thank you

Traci

0 Likes
Accepted solutions (3)
663 Views
5 Replies
Replies (5)
Message 2 of 6

tramber
Advisor
Advisor
Accepted solution

I use this :

(defun +x (pt val) (cons(+(car pt)val)(cdr pt)))

It gives :

(+x '(0 0 0) 10) -> (10 0 0)

(+x  pointA  added_value)

 

(cons(+(car pt)val)(cdr pt))

Is the code. 


EESignature

Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@traci_haberghamJQEJT wrote:

.... from the initial point that the user chooses. ....

What is the best way to add 20000 to the x value of a coordinate?

....


(polar UserPoint 0 20000)

or for the Y value instead:

(polar UserPoint (/ pi 2) 20000)

 

Or:

 

(mapcar '+ UserPoint '(20000 0 0))

or for the Y value instead:

(mapcar '+ UserPoint '(0 20000 0))

 

Kent Cooper, AIA
Message 4 of 6

john.uhden
Mentor
Mentor

@traci_haberghamJQEJT ,

You don't necessarily need AutoLisp to do what you want.

Just make sure that Orthomode is on (F8)
Then pick your starting point,

Then aim your cursor either up/down or left/right and type in the length.

John F. Uhden

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor
Accepted solution

This will add a value to the point selected, maybe can be used transparently. 

 

(mapcar '+ (getvar 'lastpoint) (list 20000 0.0 0.0))

 

 

 

(defun c:20000 ( / )
(command "line" (getpoint "\nPick 1st point "))
(command (mapcar '+ (getvar 'lastpoint) (list 20000 0.0 0.0)) "")
)

 

 

There is a way using a reactor that you could type Lxxx and it will draw a line xxx length in X direction.  Maybe better as X1200 then can have Y1000 and so on. Will leave it to others to have a go at modifying code provided. Load the lisp and type X20000 on command line. or X1000 and so on. Note if want decimals must do like this 123-4 use a "-" for decimal point.

 

 

Message 6 of 6

traci_haberghamJQEJT
Enthusiast
Enthusiast

That's great, thank you.  It halves the amount of clicks the user has to do.

0 Likes