Jump to content

Lisp for Copyalign (2 clicks align)


stlo

Recommended Posts

Hi everyone! I wonder if it's possible to add a COPY upgrade fonction to an existing align code that requires only two clicks to perform the alignment! I would like to copy parts of a drawing and quickly align them on separate lines without modifying my original drawing! I would like to select (COPY), Pick source line, Pick destination line all in the lisp! It this possible? The code that I'm posting has been done by Stefan BMR and marko_ribar participate in it and it's really great. It's from the topic "Align objects with 2 clicks". Thank you very much!

(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

 (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

I made a 3 click version of something that sounds like it could do what you require, 

perhaps with a few changes.  For one thing you don't need the scale factor.

Replace (setq sc (getreal "\Set scale factor: "))

by (setq sc 1.0)

 

See if this helps, tell me if it doesn't

 

 

  • Like 2
Link to comment
Share on other sites

Hi Emmanuel! Thank you so much! By changing to (setq sc 1.0), it works great! I select the object, I pick the first source point, the first destination point and when I click on the second source point, it automatically align the object so I don't even have to draw a destination line to make sure it's perfectly square! Very nice!

If I would like to make a test and add the copy command to the code that I've posted, is ther a simple way to just add (command "_.COPY" sSet "" "0,0,0" "@") somewhere? Maybe I'm dreaming? :) 

 

Link to comment
Share on other sites

Hi BIGAL! Where would you add this in the routine that I've post? I've tried just below the "Start main routine" header and also just before (command "_align" ss "" trying to recreate a certain logic by looking at Emmanuel's code but it's not working! Still don't know a lot about lisp but the good thing is that I'm getting more and more curious!

Thanks

Link to comment
Share on other sites

Because all my pieces have to be also align on a specific line to be correctly understood without erasing my original drawing! Also, some pieces are not drawn in ortho mode, so using the copyalign function gives me the possibility to rotate some of the pieces very quickly on a perfectly straight line (ortho). I'll stick with Emmanuel's copyalign because I'm getting use to it and it's great! I was just trying to merge a copy command into another align lisp just to make a test but it's not working! 

Thank you very much for your time!

Have a good day! 

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...