benhubel Posted December 14, 2015 Posted December 14, 2015 I am an absolute beginner when it comes to LISP, and I'm trying to write a routine. After trying several tutorials, I decided to come here. I am attempting to write a program that will align a selection to the X axis when the user clicks on a single line or curve. I also want to include a feature that aligns to the Y axis as well, but that will probably come later. There is a Quick Mirror LISP from Lee Mac (http://www.lee-mac.com/quickmirror.html) that performs most of the required steps. I'm trying to decipher it, but I don't know where to begin with tailoring it to fit my needs. If such a progam already exists, I would love to get my hands on it, as it would save me loads of time. Using the Align command requires far too many clicks (and requires too much precision per click). Quote
Lee Mac Posted December 15, 2015 Posted December 15, 2015 Welcome to CADTutor Could you elaborate on what you mean by 'align a selection to the X axis'? For example, should the selection be rotated about the center of its bounding box such that the point on the selected object is aligned with the x-axis? e.g.: Quote
Grrr Posted December 15, 2015 Posted December 15, 2015 Maybe you'll find something helpful in this thread: http://www.cadtutor.net/forum/showthread.php?85946-Align-objects-with-2-clicks Quote
benhubel Posted December 15, 2015 Author Posted December 15, 2015 Lee Mac - thank you! I have actually thought that part through, but forgot to mention it. Due to my inexperience, I was keeping it simple. I was looking to make the center point of the target line segment to be the center of rotation. The ideal, once I figure out how things work, is to rotate it around the center of mass and then move it to the nearest empty space on the drawing. Grrr - that's looks like it's close enough to what I want, and will probably contain enough code for my untrained mind to cobble it together with quick mirror to make something. I'm hoping to provide more info once I get off work tonight. I welcome anybody writing the code, but if you do, please leave LOTS of comments in the code so that I can learn how to replicate the process. I'm mostly trying to teach myself to be proficient with coding LISP. Thanks Quote
Lee Mac Posted December 15, 2015 Posted December 15, 2015 Here's a very simple (and heavily commented) approach to get you started, compatible for alignment with lines only: ;; Define function, declare local variables (defun c:alignx ( / ent enx pt1 pt2 sel ) ;; If the user makes a selection of objects (on unlocked layers) (if (setq sel (ssget "_:L")) ;; If the user selects a single object (if (setq ent (car (entsel "\nSelect line to align with x-axis: "))) ;; If the selected object is a LINE (if (= "LINE" (cdr (assoc 0 (setq enx (entget ent))))) ;; Then evaluate the following expressions (progn ;; Retrieve the WCS start & end points and translate them to UCS (setq pt1 (trans (cdr (assoc 10 enx)) 0 1) pt2 (trans (cdr (assoc 11 enx)) 0 1) ) ;; end setq ;; Invoke the Rotate command (command "_.rotate" ;; Pass the selection of objects sel "" ;; Specify the line midpoint as the rotation base point "_non" (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2) ;; Rotate the reference line to zero "_R" "_non" pt1 "_non" pt2 0.0 ) ;; end command ) ;; end progn ;; Else the selected alignment object was not a line (princ "\nThe selected object is not a line.") ) ;; end if ;; Else no alignment object was selected (princ "\nNo alignment object selected.") ) ;; end if ;; Else no objects were selected (princ "\nNo objects selected.") ) ;; end if ;; Supress the value returned by the last evaluated expression (princ) ) ;; end defun Quote
benhubel Posted December 16, 2015 Author Posted December 16, 2015 Sweet! I'll play around with this. Thank you. Quote
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.