Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
JCprog
Posts: 142
Registered: ‎02-12-2014
Message 1 of 8 (287 Views)

Lisp to align all blocks

287 Views, 7 Replies
04-29-2014 12:41 PM

Hello everyone:smileyhappy:

 

Situation:

If theres blocks A,B,C,D,E and they're all placed radomly (all have different xyz)

 

Thought:

Need a lisp that user picks first block (eg "Block A) as insertion point reference then routine ask which coordinate to follow (x, y, or z?) then select blocks to follow alignment. When user picks to follow block A's  x-coordinate.....block B,C,D,E should have same x-coordinate but maintain y & z unchanged.

 

This can be done manually but very tedious in a way. Please Help!

Thanks in advance:smileyhappy:

 

Mentor
smaher12
Posts: 191
Registered: ‎11-20-2011
Message 2 of 8 (270 Views)

Re: Lisp to align all blocks

04-29-2014 12:59 PM in reply to: JCprog

Here is one I have that will align text/blocks horizontaly. I'm sure it can easily be modified to meet your needs.

 

(defun c:blkalign ()

   (setq OS (getvar "OSMODE"))
   (setvar "OSMODE" 0)

	(princ "\nSelect blocks or text to align horizontaly evenly: ")
	(setq ss (ssget))

   (setq albl (entsel "\nSelect text or block to align with: "))
   (setq albl (car albl))
   (setq alpt (cdr (assoc 10 (entget albl))))
   (setq alpty (cadr alpt))
   (setq ctr 0)

     (while
       (setq ename (ssname ss ctr))
       (setq inpt (cdr (assoc 10 (entget ename))))
       (setq inptx (car inpt) )
       (setq inpty (cadr inpt))
       (setq newpt (list inptx alpty))
       (command "move" ename "" inpt newpt)
       (setq ctr (+ ctr 1))
     )

   (setvar "OSMODE" OS)
)

 

*Expert Elite*
dgorsman
Posts: 5,698
Registered: ‎10-12-2006
Message 3 of 8 (264 Views)

Re: Lisp to align all blocks

04-29-2014 01:13 PM in reply to: JCprog

Manual way isn't very tedious.  Select the blocks (quick select if needed), plug the appropriate ordinate value into the Properties palette.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Distinguished Contributor
JCprog
Posts: 142
Registered: ‎02-12-2014
Message 4 of 8 (260 Views)

Re: Lisp to align all blocks

04-29-2014 01:21 PM in reply to: smaher12

Thanks for the reply smaher12,

It works horizontally, thanks for sharing! The routine just breaks when ucs is rotated but it works fine on world ucs. And it must not take out snap settings. Works more better than the align command (which is essentially no different from "move" :smileywink:

*Expert Elite*
hmsilva
Posts: 3,368
Registered: ‎12-17-2004
Message 5 of 8 (248 Views)

Re: Lisp to align all blocks

04-29-2014 01:40 PM in reply to: JCprog

JCprog wrote:

Situation:

If theres blocks A,B,C,D,E and they're all placed radomly (all have different xyz)

 

Thought:

Need a lisp that user picks first block (eg "Block A) as insertion point reference then routine ask which coordinate to follow (x, y, or z?) then select blocks to follow alignment. When user picks to follow block A's  x-coordinate.....block B,C,D,E should have same x-coordinate but maintain y & z unchanged.


Hi JCprog,

as a start point...

(defun c:demo ( / ans ent i pt pt1 s ss)
  (if
    (and
      (not (prompt "\nSelect Block to follow coordinate: "))
      (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
      (not (initget "X Y Z"))
      (setq ans (getkword "\nEnter the coordinate to follow [X/Y/Z] <exit>:"))
    )
     (if (and ans
	      (not (prompt "\nSelect Blocks to change coordinates: "))
	      (setq ss (ssget "_:L" '((0 . "INSERT"))))
	 )
       (progn
	 (setq pt (cdr (assoc 10 (entget (ssname s 0)))))
	 (repeat (setq i (sslength ss))
	   (setq ent (entget (ssname ss (setq i (1- i)))))
	   (setq pt1 (cdr (assoc 10 ent)))
	   (cond
	     ((= ans "X")
	      (entmod (subst (cons 10 (list (car pt) (cadr pt1) (caddr pt1)))
			     (assoc 10 ent)
			     ent
		      )
	      )
	     )
	     ((= ans "Y")
	      (entmod (subst (cons 10 (list (car pt1) (cadr pt) (caddr pt1)))
			     (assoc 10 ent)
			     ent
		      )
	      )
	     )
	     ((= ans "Z")
	      (entmod (subst (cons 10 (list (car pt1) (cadr pt1) (caddr pt)))
			     (assoc 10 ent)
			     ent
		      )
	      )
	     )
	   )
	 )
       )
     )
  )
  (princ)
)

HTH

Henrique

 

Distinguished Contributor
JCprog
Posts: 142
Registered: ‎02-12-2014
Message 6 of 8 (240 Views)

Re: Lisp to align all blocks

04-29-2014 01:57 PM in reply to: hmsilva

Thanks for the reply Henrique!

I dont think thats simply a "startpoint".....Thats technically a "nailed-down-finishpoint" to me....lol

 

Thanks a million!!!!!!!!!:smileyhappy: as always.....it works awesome!!!!!!!!

*Expert Elite*
hmsilva
Posts: 3,368
Registered: ‎12-17-2004
Message 7 of 8 (235 Views)

Re: Lisp to align all blocks

04-29-2014 01:59 PM in reply to: JCprog
You're welcome, JCprog
Glad I could help

Henrique
*Expert Elite*
3wood
Posts: 1,152
Registered: ‎03-25-2009
Message 8 of 8 (221 Views)

Re: Lisp to align all blocks

04-29-2014 02:45 PM in reply to: dgorsman

dgorsman wrote:

Manual way isn't very tedious.  Select the blocks (quick select if needed), plug the appropriate ordinate value into the Properties palette.


I always do this.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.