Jump to content

Recommended Posts

Posted

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.

Posted

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.

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

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
Posted
@ronjonp, what if the source block has coordinates '(1 1 1) ? ;)

 

DOH! :lol:

Posted

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

Posted

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.

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

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

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

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

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