Combining Copy & Align command LISP

Combining Copy & Align command LISP

muhamed_ragab92
Enthusiast Enthusiast
2,618 Views
11 Replies
Message 1 of 12

Combining Copy & Align command LISP

muhamed_ragab92
Enthusiast
Enthusiast

Can i find lisp to combine between copy and align command and contentious ? i searched for that and find cac lisp but i cant find the script for that 

0 Likes
2,619 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

Try this...

 

(defun c:AlignCopy (/ ss el)

  (if (setq el (entlast)
	    ss (ssget ":L"))
    (progn
      (command "_.COPY" ss "" "_none" '(0 0 0) "_none" '(0 0 0))
      (setq ss (ssadd))
      (while (setq el (entnext el))
	(ssadd el ss))
      (command "_.ALIGN" ss "")))
  (princ)
)
0 Likes
Message 3 of 12

john.uhden
Mentor
Mentor

Be careful, @ВeekeeCZ.  If the "last" entity had subentities like attributes or vertices, then (entnext (entlast)) will return the ename of the subentity.

 

I always use my own function:

 

;;------------------------------------------------------------
;; Function to get the absolutely last entity in the database:
;; Revised (01-07-03) in case the drawing is empty.
;;
(defun @cv_entlast ( / e elast)
   (setq elast (entlast))
   (while (and elast (setq e (entnext elast)))
      (setq elast e)
   )
   elast
)

John F. Uhden

Message 4 of 12

ВeekeeCZ
Consultant
Consultant

@john.uhden wrote:

Be careful, @ВeekeeCZ.  If the "last" entity had subentities like attributes or vertices, then (entnext (entlast)) will return the ename of the subentity.

 

 


 

Thanks John, I'm aware of this possibility... But since you've pointed out...

 

 

(defun c:AlignCopy (/ @cv_entlast ss el)
  
  ;; by John Uhden
  ;;------------------------------------------------------------
  ;; Function to get the absolutely last entity in the database:
  ;; Revised (01-07-03) in case the drawing is empty.
  ;;
  (defun @cv_entlast ( / e elast)
    (setq elast (entlast))
    (while (and elast (setq e (entnext elast)))
      (setq elast e))
    elast)

  ; --------------------------------------------------------------
  
  (if (setq el (@cv_entlast)
	    ss (ssget ":L"))
    (progn
      (command "_.COPY" ss "" "_none" '(0 0 0) "_none" '(0 0 0))
      (setq ss (ssadd))
      (while (setq el (entnext el))
	(ssadd el ss))
      (command "_.ALIGN" ss "")))
  (princ)
)
0 Likes
Message 5 of 12

muhamed_ragab92
Enthusiast
Enthusiast

i tried it but i can't understand how is it work , it's three or four steps after select object , can you explain or say a tip for it 

0 Likes
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

@muhamed_ragab92 wrote:

i tried it but i can't understand how is it work , it's three or four steps after select object , can you explain or say a tip for it 


There is really nothing special about it - it's the regular autocad's ALIGN command. The only difference is that the routine makes a copy of selected objects first, then the copy is used for the ALIGN command (automatically)

 

If you don't know how to use the ALIGN command, see the video HERE

0 Likes
Message 7 of 12

muhamed_ragab92
Enthusiast
Enthusiast

okay yup i know align but the lisp i asked about is make copy and align in onetime like select object and after that select the wall and it aligned automatically on the wall , you understand

0 Likes
Message 8 of 12

ВeekeeCZ
Consultant
Consultant

I don't. But you can try THIS Lee Mac's craziness.

Good luck, Cheers!

0 Likes
Message 9 of 12

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

...  If the "last" entity had subentities like attributes or vertices, then (entnext (entlast)) will return the ename of the subentity  .... 


There's no need to bother with all of that fishing around for the new objects, unless drawing order in the end result is critical.  I would just leave the copy/copies where they are, and Align the same selection set that was copied:

 

(defun c:AlignCopy (/ ss el)
  (if ss (ssget ":L"))
    (command

      "_.COPY" ss "" "_none" '(0 0 0) "_none" '(0 0 0)
      "_.ALIGN" "_previous" ""

    ); command

  ); if
  (princ)
); defun

 

However, @muhamed_ragab92, I don't understand the word "contentious" -- I suspect that's not the right English word for what you mean.  Can you explain differently?

 

If you want to select objects to make a Copy and then just select something to Align with [by "wall" do you mean a wall object in an overlay program, or just a basic-AutoCAD Line representing one face of a wall, or...?], there will be two possible Alignments [different directions on the same object], and infinite possible alignment origin points along it, so it may not be possible to escape the need to pick several points in the Align command.  A sample drawing or image with before and after conditions would help.

Kent Cooper, AIA
0 Likes
Message 10 of 12

cschnarr
Enthusiast
Enthusiast

@Kent1Cooper 

Kent. I could use a pointer for the code above you posted. On my first attempt I got an "extra right paren" error.

I have tried a few revisions to correct it, but can't get it to run still.

There doesn't seem to be any allowance for me to select objects during the command.

 

Then I get the following:

Unknown command "AlignCopy". Press F1 for help.
Unknown command "NONE". Press F1 for help.
Unknown command "NONE". Press F1 for help.

Specify first source point: 

 

Any thoughts where I am going wrong?

0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant

No mention of whether I had tested that, but I suspect not.  I think I must have taken John's routine and removed things, without considering fully what remained.  Try this adjustment:

 

(defun c:AlignCopy (/ ss)
  (if (setq ss (ssget ":L"))
    (command

      "_.COPY" ss "" "_none" '(0 0 0) "_none" '(0 0 0)
      "_.ALIGN" "_previous" ""

    ); command

  ); if
  (princ)
); defun

Kent Cooper, AIA
Message 12 of 12

cschnarr
Enthusiast
Enthusiast

@Kent1Cooper 

Thanks Kent! Works perfectly now!

This is a very clean solution.

0 Likes