acad1985 Posted March 22, 2019 Share Posted March 22, 2019 (edited) 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 March 22, 2019 by acad1985 Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 22, 2019 Share Posted March 22, 2019 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) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 22, 2019 Share Posted March 22, 2019 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) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 22, 2019 Share Posted March 22, 2019 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) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 22, 2019 Share Posted March 22, 2019 @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) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 23, 2019 Share Posted March 23, 2019 @Lee Mac Thank you for that precious observation. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted March 23, 2019 Author Share Posted March 23, 2019 Hello Everyone, Thank you so much for your code. All of your code works perfectly. Thanks everyone Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted March 25, 2019 Share Posted March 25, 2019 Another one from Alanjt: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.