Change Elements Lineweight to BYLAYER?

Discussion in 'AutoCAD' started by Don I, Dec 3, 2004.

  1. Don I

    Don I Guest

    I know I can use the following to do it--but I need to change elements
    within blocks as well. I've got a routine that changes the COLOR of all
    elements within all blocks to bylayer but not LINEWEIGHT.

    From the checking that I did, it seems as though if an element is set to
    anything OTHER than bylayer, dxf code 370 contains the weight. If it IS
    bylayer, then the 370 code isn't even there.

    I was able to get the following to return what the element list would like
    like without this dxf code, but when I try to entmod it, nothing
    happens--not even an error.

    (setq newentlist
    (append
    ;returns the portion of the entlist
    ;BEFORE the 370 code
    (reverse(member(reverse entlist)))
    ;returns the portion of the entlist
    ;AFTER the 370 code
    (member(reverse entlist))
    )
    )

    TIA
     
    Don I, Dec 3, 2004
    #1
  2. Don I

    Joe Burke Guest

    Don,

    Something like this avoids DXF questions. And it's flexible. For instance, filterlst
    allows excluding certain block names, which might be useful. Likewise, comment out or
    add properties to be modified, as needed.

    Note, blocks containing attributes pose other issues. Recent threads discussed that
    topic.

    (defun c:ModBlockDefs ( / doc blocks filterlst )
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (setq blocks (vla-get-blocks doc))
    (setq filterlst '("*MODEL_SPACE" "*PAPER_SPACE"))
    (vlax-for blk blocks
    (if (not (vl-position (strcase (vlax-get blk 'Name)) filterlst))
    (vlax-for item blk
    (vlax-put item 'Color acByLayer)
    (vlax-put item 'Lineweight acLnWtByLayer)
    (vlax-put item 'Linetype "ByLayer")
    )
    )
    )
    (vla-regen doc acActiveViewport)
    (princ)
    )

    Joe Burke
     
    Joe Burke, Dec 3, 2004
    #2
  3. Don I

    RDI Guest

    Thx.

    I'll try that (hopefully today).

    Don
     
    RDI, Dec 3, 2004
    #3
  4. Don I

    Jay Guest

    Here is something I hacked for changing color to bylayer. I found that if it already was bylayer, the dxf entry wasn't
    there, much like you seem to be describing.

    ;*******Subroutine to change color and layer********
    (defun PRBLK (EN2 NAM)
    (setq CNT 0)
    (while EN2
    (setq CNT (1+ CNT)
    EG2 (entget EN2)
    EN2 (entnext (cdr (assoc -1 EG2)))
    )
    (grtext -2 (strcat NAM " block entity # " (itoa CNT)))
    ;---Check color---
    (if (assoc 62 EG2)
    (setq EG2 (subst (cons 62 256) (assoc 62 EG2) EG2))
    (setq EG2 (append EG2 (list (cons 62 256))))
    )
    (entmod EG2)
    ;---Set to layer 0---

    (if (/= (cdr (assoc 8 EG2)) "0")
    (progn
    (setq EG2 (subst (cons 8 "0") (assoc 8 EG2) EG2))
    (entmod EG2)
    )
    )
    ;---Check for nested blocks---
    (if (= (cdr (assoc 0 EG2)) "INSERT")
    (progn
    (setq NM2 (cdr (assoc 2 EG2))
    EN3 (cdr (assoc -2 (tblsearch "BLOCK" NM2)))
    )
    (PRBLK EN3 NM2)
    )
    );endif
    )
     
    Jay, Dec 3, 2004
    #4
  5. Don I

    RDI Guest

    I already assumed that I'd add DXF code to the entity list--but I couldn't
    find anything that told me what to set it TOO.

    This is the routine that I'm using to change all block sub-elements to color
    bylayer and layer 0.

    (setq ename (tblnext "block" T))
    (while (/= ename nil)
    (setq ename1 (cdr (last ename)))
    (setq ent1 (entget ename1))
    (setq ent2 (subst (cons 62 0) (assoc 62 ent1) ent1))
    (if (/= ent1 ent2)
    (entmod ent2)
    )
    (while (setq ename1 (entnext ename1))
    (setq ent1 (entget ename1))
    (setq ent2 (subst (cons 62 0) (assoc 62 ent1) ent1))
    (setq ent2 (subst (cons 8 "0") (assoc 8 ent2) ent2))
    (entmod ent2)
    )
    (setq ename (tblnext "block"))
    )
    (setq ss (ssget "x" '((0 . "INSERT"))))
    (setq l (sslength ss))
    (while (> l 0)
    (setq l (1- l)
    n (ssname ss l)
    )
    (entupd n)
    )
    (princ)
    it already was bylayer, the dxf entry wasn't
     
    RDI, Dec 3, 2004
    #5
  6. Don I

    Bill DeShawn Guest

    I wrote a routine to do this by merely picking the block that I wanted to
    redefine.
    Here is the routine:

    ;BEGIN BF0.LSP
    ;BLOCKFIX-ZERO
    (defun bf0err (msg)
    (princ msg)
    (if olderr (setq *error* olderr))
    (princ "\nSomething went wrong. Please try again. ")
    (command "_.undo" "_end")
    )
    ; Routine to place all objects in a block on layer 0, LTYPE & COLOR to be
    BYLAYER.
    (defun c:bf0 (/ ent elist ip inslay bname rot x y z newx newy newz newrot
    newlist sset)
    (command "_.undo" "_g")
    (setq olderr *error* *error* bf0err)
    (setq ent (entsel))
    (setq elist (entget (car ent)))
    (setq ip (cdr (assoc 10 elist)))
    (setq inslay (cdr (assoc 8 elist)))
    (setq bname (cdr (assoc 2 elist)))
    (setq rot (assoc 50 elist))
    (setq x (assoc 41 elist))
    (setq y (assoc 42 elist))
    (setq z (assoc 43 elist))
    (setq newx (cons 41 1.0))
    (setq newy (cons 42 1.0))
    (setq newz (cons 43 1.0))
    (setq newrot (cons 50 0.0))
    (setq newlist (subst newx x elist))
    (setq newlist (subst newy y newlist))
    (if z (setq newlist (subst newz z newlist)))
    (setq newlist (subst newrot rot newlist))
    (entmod newlist)
    (command "_.explode" (car ent))
    (setq sset (ssget "p"))
    (command "_.chprop" sset "" "LA" "0" "LT" "BYLAYER" "c" "bylayer" "")
    (if (tblsearch "BLOCK" bname)
    (command "_.block" bname "y" ip sset "")
    (command "_.block" bname ip sset "")
    )
    (setvar "clayer" inslay)
    (command "_.insert" bname ip (cdr x)(cdr y) (rtos (rtd (cdr rot)) 2 6))
    (setq *error* olderr)
    (command "_.undo" "_end")
    (princ)
    )

    Merry Christmas
     
    Bill DeShawn, Dec 6, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.