Jump to content

Align objects with 2 clicks?


Grrr

Recommended Posts

Hi Stefan BMR,

I was skeptic at first while trying the lisp, but then I re-read your post. Indeed it works perfectly with polyline segments, and not that good with lines. It seems that it matters which side of the "segment" or the line is picked as destination and source. Please check the following dwg where you can see the results of the different situations http://www.sendspace.com/file/j9vrq0

 

Theres no worries for the "complicated object" being a block, because in Step1 selected objects can be anything from the model, but the objects that must be aligned (which I call source and destination line) can appear in form of a lines/single segment polylines/segment of a multi-segment polyline (they are selected in Step2 and Step3). Yes, there's a chance that it could be selected a line from a block (for a destination or source line) but thats a question for developing the lisp, now I just want to focus on the main task.

Theres already lisp for aligning with blocks http://www.cadtutor.net/forum/showthread.php?47495-Align-Block-to-Curve but nothing I could find for a line/pline or other objects.

 

If you could adapt it to work with lines also it would be enough for me :)

 

EDIT:

ReMark: Rotating the UCS is not a good option for editing many objects with different rotation (You must rotate the UCS each time for performing edit) and its not comfortable, especially if you have heavy drawing - instead of quick align, edit, and re-align objects process. Also as lamensterms stated if the road moves - the task is nearly impossible.

eldon: Time is everything, I also used rotate with reference - but if there was easier and faster method, people would never thought about the normal aligning method or rotating with reference. If it was Autodesk's built in, they would ask you "Why you don't just use align with picking lines?"

Edited by Grrr
Link to comment
Share on other sites

I think your technique is flawed and this is just an attempt to minimize the damage that has already been done.

 

I would also suggest you look at custom lisp routines that match the angle of the crosshairs to an object that already exists in the drawing.

Link to comment
Share on other sites

Hi Stefan BMR,

If you could adapt it to work with lines also it would be enough for me :)

 

Sure, why not..

(defun c:al2p ( / *error* sel_ob get_ends ss e1 e2 l1 l2 p1)
 (vl-load-com)
 (or acDoc (setq acDoc (vla-get-activedocument (vlax-get-acad-object))))
 (vla-startundomark acDoc)

 (defun *error* (msg)
   (and msg (not (wcmatch (strcase msg) "*CANCEL*,*EXIT*,*QUIT*")) (princ (strcat "\nError: ") msg))
   (vla-endundomark acDoc)
   (princ)
   )

 ;********************
 ;sel_obj- prevent selecting the same objects; prompt for missing
 ;return list (ename point)
 (defun sel_ob (p tip msg / e msg1)
   (setvar 'errno 0)
   (if (setq e (entsel msg))
     (if
       (and
         (setq msg1 (strcat "\nFirst element is not " tip))
         (wcmatch (cdr (assoc 0 (entget (car e)))) tip)
         (setq msg1 "\nSecond element must be different than first...")
         (not (eq (car e) p))
       )
        e
        (progn (princ msg1) (sel_ob p tip msg))
     )
     (if (= (getvar 'errno) 7)
       (progn (princ "\nMissed.. Try again.")
              (sel_ob p tip msg)
       )
       nil
     )
   )
 )
 ;********************
 (defun get_ends (e / o p p1 p2 b)
   (setq o  (car e)
         b  (eq (cdr (assoc 0 (entget o))) "LWPOLYLINE")
         p  (vlax-curve-getparamatpoint
              o
              (vlax-curve-getclosestpointto o (trans (cadr e) 1 0))
            )
         p1 (if b
              (fix p)
              (vlax-curve-getstartparam o)
            )
         p2 (if b
              (1+ p1)
              (vlax-curve-getendparam o)
            )
   )
   (if (> (- p2 p) (- p p1))
     (list
       (trans (vlax-curve-getpointatparam o p1) 0 1)
       (trans (vlax-curve-getpointatparam o p2) 0 1)
     )
     (list
       (trans (vlax-curve-getpointatparam o p2) 0 1)
       (trans (vlax-curve-getpointatparam o p1) 0 1)
     )
   )
 )
;;; Start main routine
 
 (if
   (and
     (setq ss (ssget ":L"))
     (setq e1 (sel_ob      nil "LINE,LWPOLYLINE" "\nSelect source object: "))
     (setq e2 (sel_ob (car e1) "LINE,LWPOLYLINE" "\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))
;;;          )
;;;        )
     )
   )
 (vla-endundomark acDoc)
 (princ)
 )

Hi Stefan BMR,

I was skeptic at first ...

You own me a beer for this :). The code is for free...

Link to comment
Share on other sites

Thanks, Stefan BMR ! It works wonderful, it even aligns parralel objects - so in some parts it skips the usage of the "MOVE" command! :)

For sure I own you a beer !

Just a last request: I've tried to add while function in order to do the task repeatedly, but didn't succeed (I'm not good in editing codes), could you make it?

 

EDIT: ReMark, obviously you are not helping but doing opposite.

Link to comment
Share on other sites

Just replace : (if ... with :

 

 (while
   (and
     (setq ss (ssget ":L"))
     (setq e1 (sel_ob      nil "LINE,LWPOLYLINE" "\nSelect source object: "))
     (setq e2 (sel_ob (car e1) "LINE,LWPOLYLINE" "\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"
     )
     t
   )
 )
 (vla-endundomark acDoc)
 (princ)
)

Link to comment
Share on other sites

Just one beer? You work cheap. LoL

 

I have some code I need too. What are you doing the rest of the day?

Cheap work is cheap

 

Thanks, Stefan BMR ! It works wonderful, it even aligns parralel objects - so in some parts it skips the usage of the "MOVE" command! :)

For sure I own you a beer !

Just a last request: I've tried to add while function in order to do the task repeatedly, but didn't succeed (I'm not good in editing codes), could you make it?

 

EDIT: ReMark, obviously you are not helping but doing opposite.

What you do with your left hand? Just tap the space bar and you are back in business. Or replace (if (and with (while (and ...

Link to comment
Share on other sites

Thank you, marko_ribar! :)

 

EDIT: Stefan BMR, for me its easier to hit "esc" key in the end, rather than tapping space bar :)

Its OK, but you must know in this case "undo" command will undo everything you aligned in one go.

Link to comment
Share on other sites

Its OK, but you must know in this case "undo" command will undo everything you aligned in one go.

 

I've tried Ctrl+Z or "undo" command, but it returns only one aligment task although I did repeatedly different aligment tasks in one go.

Now its fun for me using this lisp, so I can forget any rotate references and built in align commands. Thanks again!

Link to comment
Share on other sites

  • 2 years later...

Hi

I was trying to use this routine for lines, and Works properly until the end. Agfter choosing offset and rotate, the object to align remains fixed with no action. REgards

Link to comment
Share on other sites

Hi

I was trying to use this routine for lines, and Works properly until the end. Agfter choosing offset and rotate, the object to align remains fixed with no action. REgards

 

Welcome to CADTutor Darwin. :)

I haven't read this whole thread, so my response may be incorrect in the context of Stefan's lisp.

The OFFSET command is not used to move an object, but rather to create a copy (which may or not be identical to the original, depending on the type of object).

The behavior you are describing sounds normal to me. The original object stays where it is, and a copy is generated, which would be the object available for ROTATE, within the command string.

 

Perhaps the MOCORO command would be better suited to the task you are describing?

Link to comment
Share on other sites

Thank you for your answer, but the problema is that any copy is generated. A rutine that allow to align two or more objects just pick on them it is very usefull. Using original tool Autocad align pick on several vertex is very annoying.

Link to comment
Share on other sites

Are you familiar with the MOCORO command? As copying is an option, not always used.

Stefan certainly knows his stuff, so I have no doubt you are in good hands. :)

 

The following lisp by Lee Mac http://www.lee-mac.com/objectalign.html

 

Thanks Lee! :beer:

 

may or may not be appropriate in this case, but I have no doubt, that if you are not familiar with it, there will come a time when it will be helpful.

Link to comment
Share on other sites

Thank you for the link. I already send a emai to Lee, to find out why his routine doesnt work on my computer. I know Mocoro, but I think that what I am looking for is Lee, routine.

Regards

Link to comment
Share on other sites

Hi Lee,

No no error, I can select the objects, the objet to align to, and then I can read the line of offset and rotate, I select offset choose a quantity and then nothing happens the rutine closed itself.

Thank you.

Link to comment
Share on other sites

  • 6 years later...
On 4/25/2014 at 6:19 AM, highflybird said:

Interesting code. I just test it,

find two cases occurred.Can't choose the direction?

201404.jpg

Same question here, I dont know anything about lisp programming, please give me some help.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...