Jump to content
RubberDinero

Align Block and Attributes to X Y or Z

Recommended Posts

RubberDinero

I usually do extensive research before posting a question to this forum, but I have not been able to find the answer I'm looking for.

 

I'm trying to create a lisp that asks you for a plane

(getkword "X Y or Z <Y>:")

 

Then pick a point

(getpoint "\nSelect Point)

 

Pick blocks

(setq blks (ssget '((0 . "INSERT"))))

 

Finally aligns all blocks to the selected plane.

 

I have a Lisp that does this, except that when the blocks have attributes, the attributes stay in place and I would have to manually move them.

 

I know that a way to do it is to select all blocks i want and go to the properties and change either the X Y or Z values, but that also seems tedious.

 

Any help is greatly appreciated.

 

Thanks.

Share this post


Link to post
Share on other sites
ronjonp

Post your code.

Share this post


Link to post
Share on other sites
RubberDinero

Here is one that I just found and it works great, but only on the Y axis. I noticed this one uses a Move command, and that would make sense as to why the attributes are also moving. unlike the entmod version

(defun c:abc ()

  (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)
)

 

 

Thanks.

Share this post


Link to post
Share on other sites
Lee Mac
I have a Lisp that does this, except that when the blocks have attributes, the attributes stay in place and I would have to manually move them.

 

If you are modifying the drawing database using entmod, you will need to separately modify the insertion point (DXF 10) of the INSERT entity, and the insertion point or alignment points (DXF 10/11) of all ATTRIB entities which follow.

 

Alternatively, if you modify the ActiveX insertionpoint property of the VLA Block Reference object, this will apply to the block reference and any associated attribute references, e.g.:

(defun c:ab ( / axs idx obj pnt sel )
   (initget "X Y Z")
   (setq axs (cond ((getkword "\nSelect axis [X/Y/Z] <Y>: ")) ("Y")))
   
   (if (and (setq sel (ssget "_:L" '((0 . "INSERT"))))
            (setq pnt (getpoint "\nSpecify alignment point: "))
            (setq pnt (trans pnt 1 (trans '(0 0 1) 1 0 t)))
       )
       (repeat (setq idx (sslength sel))
           (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
           (vla-put-insertionpoint obj (vlax-3D-point (mapcar '(lambda ( a b c ) (if (= axs c) b a)) (vlax-get obj 'insertionpoint) pnt '("X" "Y" "Z"))))
       )
   )
   (princ)
)
(vl-load-com) (princ)

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

Here's another:

(defun c:foo (/ a i k p s)
 ;; RJP - 01.03.2018
 (or (setq k (getenv "AlignBlocks")) (setq k "X"))
 (if (and (not (initget "X Y Z"))
   (setq k (cond ((getkword (strcat "\nAlignment [X/Y/Z] <" k ">: ")))
		 (k)
	   )
   )
   (setq p (getpoint "\nPick an alignment point: "))
   (setq s (ssget ":L" '((0 . "insert"))))
     )
   (progn
     (setenv "AlignBlocks" k)
     (setq i (vl-position k '("X" "Y" "Z")))
     (setq a (nth i p))
     (foreach b (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
(setq p (vlax-get b 'insertionpoint))
(vlax-put b
	  'insertionpoint
	  (cond	((= 0 i) (list a (cadr p) (caddr p)))
		((= 1 i) (list (car p) a (caddr p)))
		((list (car p) (cadr p) a))
	  )
)
     )
   )
 )
 (princ)
)
(vl-load-com)

Edited by ronjonp
Fixed bug Lee pointed out

Share this post


Link to post
Share on other sites
Lee Mac

@ronjonp, what if the source block has coordinates '(1 1 1) ? ;)

Share this post


Link to post
Share on other sites
ronjonp
@ronjonp, what if the source block has coordinates '(1 1 1) ? ;)

 

DOH! :lol:

Share this post


Link to post
Share on other sites
RubberDinero

Lee, you are on a whole different level! This worked great!

I definitely haven't dove into the VLA language aspect of creating Lisp, but it definitely seems like it's more powerful and somewhat easier to write, though i have no idea what I'm looking at(for the most part).

Share this post


Link to post
Share on other sites
RubberDinero

Just tried yours and it also works great! I definitely need to start digging into these languages a lot deeper.

 

Edited: This one is reffering to ronjonp's code.

Share this post


Link to post
Share on other sites
RubberDinero
Posted (edited)
Here's another:

(defun c:foo (/ a i k p s)
 ;; RJP - 01.03.2018
 (or (setq k (getenv "AlignBlocks")) (setq k "X"))
 (if (and (not (initget "X Y Z"))
   (setq k (cond ((getkword (strcat "\nAlignment [X/Y/Z] <" k ">: ")))
		 (k)
	   )
   )
   (setq p (getpoint "\nPick an alignment point: "))
   (setq s (ssget ":L" '((0 . "insert"))))
     )
   (progn
     (setenv "AlignBlocks" k)
     (setq i (vl-position k '("X" "Y" "Z")))
     (setq a (nth i p))
     (foreach b (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
(setq p (vlax-get b 'insertionpoint))
(vlax-put b
	  'insertionpoint
	  (cond	((= 0 i) (list a (cadr p) (caddr p)))
		((= 1 i) (list (car p) a (caddr p)))
		((list (car p) (cadr p) a))
	  )
)
     )
   )
 )
 (princ)
)
(vl-load-com)

 

I'm going to use your code, because I noticed that if i pre-select the objects before invoking the command, it leave the grips visible and i can click the insertion grip after all the prompts and align to it.

Lee's code may do this as well, but i didn't try it.

Edited by RubberDinero

Share this post


Link to post
Share on other sites
ronjonp
I'm going to use your code, because I noticed that if i pre-select the objects before invoking the command, it leave the grips visible and i can click the insertion grip after all the prompts and align to it.

Lee's code may do this as well, but i didn't try it.

 

I updated the code above to account for the bug Lee pointed out.

Share this post


Link to post
Share on other sites
Lee Mac
Lee, you are on a whole different level! This worked great!

I definitely haven't dove into the VLA language aspect of creating Lisp, but it definitely seems like it's more powerful and somewhat easier to write, though i have no idea what I'm looking at(for the most part).

 

Excellent to hear.

 

ActiveX properties & methods are certainly more readable than DXF groups, but each (Vanilla/Visual) have their advantages & disadvantages depending on the task at hand.

Share this post


Link to post
Share on other sites
RubberDinero
ActiveX properties & methods are certainly more readable than DXF groups, but each (Vanilla/Visual) have their advantages & disadvantages depending on the task at hand.

 

Now I have a starting point. Didn't even know the proper name. ActiveX Properties & Methods.

Share this post


Link to post
Share on other sites
Lee Mac
Now I have a starting point. Didn't even know the proper name. ActiveX Properties & Methods.

 

You're welcome - you might find my post here a good starting point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×