Jump to content

Rotate specific block to zero degree


acad1985

Recommended Posts

Hello guys,

I found a lisp on below path,  file to rotate the blocks to 0 degree by the name of the block.but as per this code i need to select the block.

Instead of select the block manually i want to select the block through Lisp. i tried to modify but i can;t able to do that.

Can anyone help me on this.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rotate-objects-to-0/td-p/5841894

 

(defun C:B0 (/ bdata sel); = Block to 0 rotation
   ;(setq sel (ssget "_x" '((0 . "INSERT")(2 . "123"))))
  (setq bdata (entget (car (entsel "\nSelect Block for 0 rotation: "))))
    (entmod (subst '(50 . 0) (assoc 50 bdata) bdata))
)

Thanks in Advance.

Edited by acad1985
Link to comment
Share on other sites

Try this :

 

(vl-load-com)
(defun C:B0 ( / ss cnt)
  (setq ss (ssget "_x" '((0 . "INSERT")(2 . "123"))));123 = Block to rotate to 0
  (repeat (setq cnt (sslength ss))
    (vlax-put-property (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))) 'rotation 0)
  );end_repeat
  (princ)
)

 

Link to comment
Share on other sites

Vanilla. :) 

The following would ignore blocks on locked layers.

(defun c:Foo (/ sel int ent get)
  (and (setq int -1 sel (ssget "_X" '((0 . "INSERT"))))
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (setq get (entget ent))
      (if (/= 4
              (logand
                4
                (cdr
                  (assoc 70
                         (entget (tblobjname "LAYER" (cdr (assoc 8 get))))
                         )
                  )
                )
              )
        (entmod (subst '(50 . 0) (assoc 50 get) get))
        )
      )
       )
  (princ)
  )

 

Link to comment
Share on other sites

Try this


(defun test ( / obj ss bname x)
(setq obj (vlax-ename->vla-object (car (entsel "Pick block for 0"))))
(setq bname (vla-get-EffectiveName obj))
(setq ss (ssget "_x" (list(cons 0  "INSERT")(cons 2 bname))))
(repeat (setq x (sslength ss))
(vla-put-rotation (vlax-ename->vla-object (ssname ss (setq x (- x 1)))) 0.0)
)
)
(test)

Link to comment
Share on other sites

@Tharwat FWIW, there is no need to test for & exclude block references on locked layers, as entmod will simply return nil if the entity is not write-enabled.

 

Since INSERTs don't require subclass markers, here's another way to perform the entmod:

(defun c:test ( / i s )
    (if (setq s (ssget "_X" '((0 . "INSERT"))))
        (repeat (setq i (sslength s))
            (entmod (list (cons -1 (ssname s (setq i (1- i)))) '(50 . 0.0)))
        )
    )
    (princ)
)

 

Link to comment
Share on other sites

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