Jump to content
JoeyG_77

Change Layers inside a Block

Recommended Posts

JoeyG_77

Hey everyone ... Im looking for a lisp that would take a block open it and change all the layers & line types to "bylayer" & then change it to a specific layer and close the block after editing it.

 

Thanks

Joey G

Share this post


Link to post
Share on other sites
marko_ribar

I had this in my library - modified it from ByBlock to ByLayer for your purposes... Untested though...

 


(defun c:BlksByLayer ( / *error* BlkByLayer *adoc* ss i lst )

  (vl-load-com)

  (defun *error* ( m )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun BlkByLayer ( objSelection / blkdef )
    (if (= (type objSelection) 'ENAME)
      (setq objSelection (vlax-ename->vla-object objSelection))
    )
    (if (wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*")
      (if (and
            (setq blkdef (vla-item (vla-get-blocks *adoc*) (vla-get-name objSelection)))
            ;;;(= (vla-get-isdynamicblock blkdef) :vlax-false) ;;; - if you need to process dynamic blocks as well - if you don't remove comments
            (= (vla-get-isxref blkdef) :vlax-false)
            (not (vl-position (vla-get-name objSelection) lst))
          )
        (progn
          (setq lst (cons (vla-get-name objSelection) lst))
          (vlax-for objBlock blkdef
            (vla-put-color objBlock 256)
            (vla-put-linetype objBlock "ByLayer")
            (vla-put-Lineweight objBlock -1)
          )
        )
      )
    )
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (BlkByLayer (ssname ss (setq i (1- i))))
      (entupd (ssname ss i))
    )
  )
  (vla-regen *adoc* acactiveviewport)
  (*error* nil)
)

 

HTH., M.R.

Share this post


Link to post
Share on other sites
JoeyG_77

Marko ... Thanks for the response ! It worked great to change everything to bylayer but I needed it to change it to a specific layer after it changed to bylayer .

 

Thanks for the help 

Share this post


Link to post
Share on other sites
marko_ribar

Try changing this part :

  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (BlkByLayer (ssname ss (setq i (1- i))))
      (entupd (ssname ss i))
    )
  )

To something like this :

  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (BlkByLayer (ssname ss (setq i (1- i))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 8 "LayerName") (assoc 8 (entget (ssname ss i))) (entget (ssname ss i)))))))
    )
  )

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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