Jump to content

Recommended Posts

Posted

i have a autocad lisp https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-block-entities-from-layer-zero-to-current/td-p/11584200 from this forum this lisp work fine but can anyone change it to do multiple blocks. the lisp basically does that it changes block object inside layer to current layer i want same process but for multiple blocks anyhelp would be appreciated.

thanks.https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-block-entities-from-layer-zero-to-current/td-p/11584200

(defun c:fb (/ block bname)
(setq block (ssget "_+.:E:S" '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway
(setq currentlayer (getvar "clayer"))
(setq bname (cdr (assoc 2 (entget(ssname block 0))))) ;; index forgotten , 0 is the first
(command "-bedit" bname )
(command "change" "all" "" "p" "la" currentlayer "")
; (command "setbylayer" "all" "" "yes" "yes")
(command "_.bclose" "_save") ;; close the editor
(princ)
)

(vl-load-com)
(prompt "\nType FB to set all entities in a block to the current layer.")

 

Posted (edited)

See this which is the basis for the change you want to make: https://lee-mac.com/ssget.html

 

 

Try this untested change, however since you are editing each block in turn in the block editor it could be slow

 

EDITED CODE: Missed a ')'

 

(defun c:fb (/ block bname acount)
  (setq block (ssget '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway ;; CHANGED THIS LINE
  (setq currentlayer (getvar "clayer"))
  (setq acount 0)                   ;;ADDED THIS LINE
  (while (< acount (sslength block)) ;; ADDED THIS LINE
    (setq bname (cdr (assoc 2 (entget(ssname block acount))))) ;; index forgotten , 0 is the first;; CHANGED THIS LINE
    (command "-bedit" bname )
    (command "change" "all" "" "p" "la" currentlayer "")
;    (command "setbylayer" "all" "" "yes" "yes")
    (command "_.bclose" "_save") ;; close the editor
    (setq acount (+ acount 1))    ;; ADDED THIS LINE
  ) ; end while                   ;; ADDED THIS LINE

  (princ)
)

(vl-load-com)
(prompt "\nType FB to set all entities in a block to the current layer.")

 

Edited by Steven P
  • Like 1
Posted (edited)

 

 

 

Edited by samarth yadav
Posted
On 10/23/2024 at 6:12 PM, Steven P said:

See this which is the basis for the change you want to make: https://lee-mac.com/ssget.html

 

 

Try this untested change, however since you are editing each block in turn in the block editor it could be slow

 

(defun c:fb (/ block bname acount)
  (setq block (ssget '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway ;; CHANGED THIS LINE
  (setq currentlayer (getvar "clayer"))
  (setq acount 0)                   ;;ADDED THIS LINE
  (while (< acount (sslength block) ;; ADDED THIS LINE
    (setq bname (cdr (assoc 2 (entget(ssname block acount))))) ;; index forgotten , 0 is the first;; CHANGED THIS LINE
    (command "-bedit" bname )
    (command "change" "all" "" "p" "la" currentlayer "")
;    (command "setbylayer" "all" "" "yes" "yes")
    (command "_.bclose" "_save") ;; close the editor
    (setq acount (+ acount 1))    ;; ADDED THIS LINE
  ) ; end while                   ;; ADDED THIS LINE

  (princ)
  )

(vl-load-com)
(prompt "\nType FB to set all entities in a block to the current layer.")

 

thanks for the response but not able to select more than one block at a time it is working same as before 

Posted

I missed a closing bracket - I've modified the code above and it should work now

Posted

Thank you steven working perfectly fine thanks for the help you saved so much time

  • Like 1

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