chiimayred Posted March 18, 2015 Share Posted March 18, 2015 (edited) Hey guys, I'm trying to get the four corners of a rectangle in modelspace set to variables and I'm having a hard time with it. I'm able to get the four corners into a list, but I'm having a hard time setting each coordinate to a variable. The issue I'm having at this point is that the second variable duplicates the coordinate values. The first variable Here's what I got so far... (defun c:test (/ ptlist x y) (setq ptlist (massoc 10 (entget(car(entsel))))) (defun c:massoc (key alist / x nlist) (foreach x alist (if (eq key (car x)) (setq nlist (cons (cdr x) nlist)) ) ) (reverse nlist) ) ;end (princ ptlist) (setq x (car ptlist)) (setq y (cadr ptlist)) (princ) (princ x) (Princ) (princ y) ) I got part of this code from here When I draw in a rectangle in modelspace and I use this code, this is what I'm getting. Command: TEST Select object: ((18.2488 -11.0958) (23.6419 -11.0958) (23.6419 -5.32136) (18.2488 -5.32136))(18.2488 -11.0958)(23.6419 -11.0958)(23.6419 -11.0958) So it builds the list and sets the first variable right, but it duplicates the second. Thanks in advance! e: I haven't added in error trapping yet, just trying to figure this out first. Edited March 18, 2015 by chiimayred updated code, bit at the end Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 18, 2015 Share Posted March 18, 2015 The variable is not duplicated - the function is evaluating the (princ y) expression to print the value of the variable 'y' to the command-line, and is then returning the value returned by the last evaluated expression, which is the (princ y) expression. Simply add (princ) to the end of the code to ensure that the last returned value is a null symbol, and hence avoid the duplicate output. Quote Link to comment Share on other sites More sharing options...
chiimayred Posted March 18, 2015 Author Share Posted March 18, 2015 Wow, I feel like such a dunce! Thanks for your reply, this is my first time really working with lists. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 18, 2015 Share Posted March 18, 2015 No worries! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.