Grrr Posted April 21, 2014 Posted April 21, 2014 (edited) EDIT3 (short version): So the default concept for alignment in AutoCAD is picking "source and destination" points - atleast 2 pairs, then it asks you to scale the objects. This process is kinda slow and annoying for me. The goal of this lisp is to: 1.Select entities (to be aligned) 2.Pick destination line (as an align reference) 3.Pick source line (to align objects to it) So would it be possible to get the coordinates of the both endpoints of a "source" and "destination" line, and "match" them to be on the same axis? (without questioning to resize the object) and then maybe perform "dynamic" movement locked on that axis? Edited April 23, 2014 by Grrr 1 Quote
lamensterms Posted April 24, 2014 Posted April 24, 2014 Hi Grrr, I like the idea of your routine, but I'm afraid I wont be able to assist you creating it (my LISP skills arent up to the task). One thing that did occur to me is that by picking 2 lines to align - there might be an issue determining which end points of the line are the first and second points. I'm sure someone will have a solution to overcome this problem. Quote
Grrr Posted April 24, 2014 Author Posted April 24, 2014 Hi lamensterms, in my previous (longer) version of my post I threw a several methods/ideas how this lisp could be performed. One of them was rotating the object from the apparent intersection of both lines on angle(alpha), and if alpha is If some coder is willing to write a routine, I'll give a deeper explanation. Although I didn't expected such low attention for this useful lisp. Quote
marko_ribar Posted April 24, 2014 Posted April 24, 2014 Grrr, it sounds to me that you're speaking that lines should be aligned to each other... It's simply enough to (entmod) start/end vertices of source line to be aligned with destination line... But how would you link other objects as per picture lamensterms posted to source line to accomplish aligning process together with all objects linked to source line... I don't think there would be much improvements than real built-in align command can do... Quote
Grrr Posted April 24, 2014 Author Posted April 24, 2014 Its not about aligning the lines, but the objects (the role of the picked lines is to be referent - they could be a part from different objects - like a segment of a polyline) Not sure if my pictures explain enough: Quote
lamensterms Posted April 24, 2014 Posted April 24, 2014 Hi again Grrr, Yep, that makes plenty of sense. Rotating from any point on source line 1, to any point on source line 2, about the intersection of both lines. Or you could read the endpoints and match the closest and furthest (if that makes sense). I reckon that would satisfy most conditions. It does sound like it's achievable. And it would definitely be more efficient than the align command. Quote
Grrr Posted April 24, 2014 Author Posted April 24, 2014 Grrr, it sounds to me that you're speaking that lines should be aligned to each other... It's simply enough to (entmod) start/end vertices of source line to be aligned with destination line... But how would you link other objects as per picture lamensterms posted to source line to accomplish aligning process together with all objects linked to source line... I don't think there would be much improvements than real built-in align command can do... Its not just about the lines, see the picture as another example Hi again Grrr, Yep, that makes plenty of sense. Rotating from any point on source line 1, to any point on source line 2, about the intersection of both lines. Or you could read the endpoints and match the closest and furthest (if that makes sense). I reckon that would satisfy most conditions. It does sound like it's achievable. And it would definitely be more efficient than the align command. Well, there are different approaches to do it - the problem is that I don't know what are the possibilities of lisp (can it find the coordinates of the apparent intersection anyway?!). Other suggestion would be to perform "move" from one of the both endpoints of the line/or midpoint and then rotate with reference to match the angles Quote
hmsilva Posted April 24, 2014 Posted April 24, 2014 Grrr, just as a demo and a starting point... (defun c:demo (/ old_osm p1 p2) (setq old_osm (getvar 'OSMODE)) (setvar 'OSMODE 512) (princ "\nSelect objects to align: ") (if (and (setq ss (ssget "_:L")) (setq p1 (getpoint "\nSelect source line: ")) (setq p2 (getpoint "\nSelect destination line: ")) ) (progn (setvar 'OSMODE 0) (command "ROTATE" ss "" "APP" p1 p2 "R" "APP" p1 p2 p1 p2) (setvar 'OSMODE old_osm) ) (setvar 'OSMODE old_osm) ) (princ) ) HTH Henrique Quote
ReMark Posted April 24, 2014 Posted April 24, 2014 In the image in post #7 one can align the two objects using midpoint and endpoint (no scaling obviously). Quote
marko_ribar Posted April 24, 2014 Posted April 24, 2014 Grrr, this can only be faster than real align command only if you already have those 2 lines created, otherwise : 1. draw line 1 ( 2 clicks ); 2. draw line 2 ( 2 clicks ); 3. select object(s) ( 2 clicks ); 4. pick first line ( 1 click ); 5. pick second line ( 1 click )... And this is : 2 + 2 + 2 + 1 + 1 = 8 clicks... Align command : 1. select object(s) ( 2 clicks ); 2. pick 1st source point ( 1 click ); 3. pick 1st destination point ( 1 click ); 4. pick 2nd source point ( 1 click ); 5. pick 2nd destination point ( 1 click ); 6. HIT ENTER+ENTER... And this is : 2 + 1 + 1 + 1 + 1 = 6 clicks + 2x ENTER... You must take into consideration the fact that source and destination lines actually don't exist, you have to create them in order for lisp to do the rest of the job... Even then you have : 1. select object(s) ( 2 clicks ); 2. pick source line ( 1 click ); 3. pick destination line ( 1 click )... And this is : 2 + 1 + 1 = 4 clicks... Just quicker for 2 clicks and 2 enters, but actually when you don't have those lines, you actually have 2 clicks more and you must prey not to miss line selections... IMHO, this is waste of time... Quote
Grrr Posted April 24, 2014 Author Posted April 24, 2014 marko_ribar, nope because in the most cases these lines are part of the existing objects, but in theory they could be part of other objects (which we don't want to align but use their lines as references), see the picture (green lines are the destination lines, and are part from existing object(s)). Ofcourse I agree that the aligment is not that perfect for now in hmsilva's code but if first match the midpoints of the destination and source line, and then match the angles will do it alot better (or first match angles, and then perform move to match midpoints or endpoints). I've added while function to hmsilva's code and it works quite good (defun c:demo (/ old_osm p1 p2) (setq old_osm (getvar 'OSMODE)) (while (princ "\nSelect objects to align: ") (setvar 'OSMODE 512) (if (and (setq ss (ssget "_:L")) (setq p1 (getpoint "\nSelect source line: ")) (setq p2 (getpoint "\nSelect destination line: ")) ) (progn (setvar 'OSMODE 0) (command "ROTATE" ss "" "APP" p1 p2 "R" "APP" p1 p2 p1 p2) (setvar 'OSMODE old_osm) ) ) (setvar 'OSMODE old_osm) ) (princ) ) The only problem is that it rarely aligns the very top "big, complicated object1" in the picture with "big, complicated object2". Anyway for the normal ALIGN command it would take 24 clicks total to get the result we try to perform with only 8 clicks! EDIT: sorry for the example in first picture (its easier and takes less clicks to perform the alignment with ALIGN command), see the example task on the second picture(where nothing is on the same angle) Quote
ReMark Posted April 24, 2014 Posted April 24, 2014 What kind of work do you do where you have five objects that look like those in the image to the far right that you then need to go back and align four of them? Quote
marko_ribar Posted April 24, 2014 Posted April 24, 2014 I agree this is faster than using align command, but this is not align - it's actually "rotate to be aligned" command... EDIT message : You have to take in consideration that you don't have those rectangles in your working drawing - you have to create them, and I share the question : what kind of drawing is this (without those rectangles)? Are your entities scattered all around center rectangle and with variable rotations? Maybe I am wrong, but if those rectangles that are to be aligned represent XREFs, wouldn't be more appropriate that you set their rotations to 0.0 to be aligned with X axis and then make array of them along X axis in order to make drawing aligned... Quote
Grrr Posted April 24, 2014 Author Posted April 24, 2014 (edited) What kind of work do you do where you have five objects that look like those in the image to the far right that you then need to go back and align four of them? Urban planning and design, or working over old scanned drawings with different objects in it with different rotation, or drawing orthogonal shapes and forms that must be aligned into sloped line from existing object. http://wiki.openstreetmap.org/w/images/f/fa/Cadastre-Style-Hausen-adZ.svg I agree this is faster than using align command, but this is not align - it's actually "rotate to be aligned" command... It doesn't matter how its called or how it works, the point is the user's task and the ending result to make life easier. EDIT: The point is not what kind of drawing is this, the point is what happens when you have repetitive task of drawing something and perform align everytime on something else. Honestly I skip ALIGN command more because of the user's task, and use instead ROTATE with reference angle - which is kinda less annoying for me. But this lisp removes all the pain of clicking dots. Edited April 24, 2014 by Grrr Quote
marko_ribar Posted April 24, 2014 Posted April 24, 2014 According to your link, are you telling me that you have to rotate those houses in your drawing using "rotate to be aligned" command rather than "align" command or just "rotate" - your drawing shows exactly real life situation - you don't have to make exact rotation alignments - you do it approximately correct according to street network... You don't need for this routine, just clear vision and "rotate" command... And if your drawing is detailed, then your house drawing should be oriented according to main street edge of house aligned with X axis... Quote
Grrr Posted April 24, 2014 Author Posted April 24, 2014 You are right, but I usually search for some kind of precision. My first goal was to implement some of the 2d commands from Revit into AutoCAD through lisp. I've deleted my very first messages after creating this thread in order for people to read it short and simple - and for me to get some answers about the lisp I'm asking. Its a shame that BIM software has advantages in 2D drafting than a CAD software. But maybe one day Autodesk will say "hey, lets built in those options in AutoCAD also". Quote
Stefan BMR Posted April 24, 2014 Posted April 24, 2014 Hi Grrr This simple routine is just for testing purpose, no error trap. So far, it works with polylines, can be adapted for lines, but if your "complicated object" is a block, it would be harder to code. Watch this video to see different results depending on picked point. (nearest vertex on source object is the first alignment point; the other vertex on the same segment is the second alignment point etc) [EDIT: gif removed.] (defun c:al2p ( / ss e1 e2 l1 l2 p1) (if (and (setq ss (ssget ":L")) (setq e1 (entsel "\nSelect source object: ")) (setq e2 (entsel "\nSelect destination object: ")) ) (progn (setq l1 (get_ends e1) l2 (get_ends e2) ) (command "_align" ss "" "_non" (car l1) "_non" (car l2) "_non" (cadr l1) "_non" (cadr l2) "" "_n" ) ;;; (if ;;; (setq p1 (getpoint "\nSpecify base point to move objects or press Enter to exit: ")) ;;; (progn ;;; (command "_move" ss "" "_non" p1) ;;; (while (> (getvar 'cmdactive) 0) (command pause)) ;;; ) ;;; ) ) ) (princ) ) (defun get_ends (e / o p p1 p2) (setq o (car e) p (vlax-curve-getparamatpoint o (vlax-curve-getclosestpointto o (cadr e)) ) p1 (fix p) p2 (1+ p1) ) (if (> (- p2 p) (- p p1)) (list (vlax-curve-getpointatparam o p1) (vlax-curve-getpointatparam o p2) ) (list (vlax-curve-getpointatparam o p2) (vlax-curve-getpointatparam o p1) ) ) ) Quote
ReMark Posted April 25, 2014 Posted April 25, 2014 If you are drawing these objects (ex. - houses on a street plan) wouldn't it make more sense to rotate the crosshairs or your UCS first which would eliminate the need for the align command. It seems you are use the wrong technique and asking for a lisp routine to fix the problems you have created rather than using the right technique. I've done many, many drawings over my CAD career in a variety of different disciplines but I rarely have need to use the align command. Quote
eldon Posted April 25, 2014 Posted April 25, 2014 I would probably use Rotate with reference. I am not sure why the emphasis on saving clicks. I use a two button mouse with the default settings of Pick on the left and Return on the right, and one can get very swift. Perhaps there is a medical reason for saving on clicks. Quote
lamensterms Posted April 25, 2014 Posted April 25, 2014 I think the need for the "quick align" could be fair enough. Depending on the method used to create these plans, rotating the UCS first may not be the simplest option. For instance, if the road moves, you might need a easy way to move/re-align the houses to suit the new road. Or if you were copying the same house/building BLOCK around a plan, it would be good to quickly match each new BLOCK to the orientation of its surroundings. 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.