Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to align all blocks

9 REPLIES 9
Reply
Message 1 of 10
JCprog
2014 Views, 9 Replies

Lisp to align all blocks

Hello everyoneSmiley Happy

 

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 advanceSmiley Happy

 

9 REPLIES 9
Message 2 of 10
smaher12
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)
)

 

Message 3 of 10
dgorsman
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.
"I don't know" is the beginning of knowledge, not the end.


Message 4 of 10
JCprog
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" 😉

Message 5 of 10
hmsilva
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

 

EESignature

Message 6 of 10
JCprog
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!!!!!!!!!Smiley Happy as always.....it works awesome!!!!!!!!

Message 7 of 10
hmsilva
in reply to: JCprog

You're welcome, JCprog
Glad I could help

Henrique

EESignature

Message 8 of 10
3wood
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.

Message 9 of 10
bananaking365
in reply to: hmsilva

Hi @hmsilva,

 

The routine works great for the geometries in the block. However, the attributes in the block are not moved by the routine (please see attached screenshot). Can the routine be modified to include attributes in the block?

 

Thank you.

Tags (2)
Message 10 of 10
Kent1Cooper
in reply to: bananaking365


@bananaking365 wrote:

.... the attributes in the block are not moved by the routine (please see attached screenshot). Can the routine be modified to include attributes in the block?

....


Does ATTSYNC move them to appropriate locations in relation to the moved Blocks?

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost