(setq e (entget (car (entsel)))) question

Discussion in 'AutoCAD' started by coachball8, May 27, 2004.

  1. coachball8

    coachball8 Guest

    I need to select a block, then iterate thru the sub-entities to change all the mtext to a different layer. I can get
    (setq d (assoc 8 e))
    (setq e2 (subst '(8 . "mylayer") d e1))
    (entmod e2), however, I can't seem to figure out to isolate the mtext. Another option would be to use nentsel and be able to select all the text at once, but nentsel doesn't allow me to do that. What's the best way to accomplish this? TIA
     
    coachball8, May 27, 2004
    #1
  2. coachball8

    BillZ Guest

    I don't know who posted this.

    ;9/11/02
    ;to find nested entities in block in a drawing;
    ;
    ;
    ;
    ;
    (defun getNestedEnts (name / rtn)
    (setq ename (tblobjname "block" name))
    (while ename
    (if (/= (cdr (assoc 0 (entget ename))) "INSERT")
    (setq rtn (cons ename rtn))
    (setq inn (cons ename inn))
    )
    (setq ename (entnext ename))
    )
    (reverse rtn)
    )

    I used it once and it seemed to work.

    Bill

    I changed the description as it was a copy form another program.
    Message was edited by: BillZ
     
    BillZ, May 27, 2004
    #2
  3. coachball8

    Jamie Duncan Guest

    If it's mtext, then you must use the block name and do a tblsearch/tblnext
    thing,
    see comments and hints in following lisp

    (defun c:fixents (/ ss1 temp ent1 looper entdat bnm ctr enttyp bl_list)
    (command ".layer" "t" "0" "un" "0" "s" "0" "")
    (setq ss1 (ssadd) looper T ctr 0)
    (while looper
    (prompt "\nSelect Entities to set to Bylayer for Colour and Linetype:
    ");;;revise this
    (setq ss1 (ssget));;;revise this to filter for inserts
    (if ss1 (setq looper nil))
    )
    (repeat (sslength ss1)
    (setq ent1 (ssname ss1 ctr) entdat (entget ent1) enttyp (cdr (assoc 0
    entdat)))
    (if (= enttyp "INSERT")
    (progn
    (setq bl_list (list (cdr (assoc 2 entdat))))
    (foreach bnm bl_list
    (jddfixablock bnm)
    )
    )
    (progn
    (setq entdat (subst (cons 62 256)(assoc 62 entdat) entdat)
    entdat (subst (cons 6 "Bylayer")(assoc 6 entdat) entdat)
    )
    (entmod entdat)(entupd ent1)
    )
    )
    (setq ctr (+ ctr 1))
    )
    (princ)
    )
    (defun jddfixablock (bname / enam1 end1)
    (setq enam1 (tblobjname "block" bname))
    (while (setq enam1 (entnext enam1))
    (setq end1 (entget enam1) ;;;step thru block def
    ;;;put your test for mtext here
    ;;; end1 (subst (cons 62 256)(assoc 62 end1) end1))
    ;;; end1 (subst (cons 6 "Bylayer")(assoc 6 end1) end1))
    end1 (subst (cons 8 "0")(assoc 8 end1) end1)) ;;;make this the
    layer you want
    )
    (entmod end1)
    ;;;end of mtext test
    ;;; if your block def contains an insert - get the block name of the insert
    and add it to our block name list
    (if (= (cdr (assoc 0 (entget enam1))) "INSERT")(setq bl_list (append
    bl_list (list (cdr (assoc 2 (entget ent1)))))))
    )
    )

    HTH

    Jamie Duncan

    the mtext to a different layer. I can get
    Another option would be to use nentsel and be able to select all the text at
    once, but nentsel doesn't allow me to do that. What's the best way to
    accomplish this? TIA
     
    Jamie Duncan, May 27, 2004
    #3
  4. coachball8

    Jürg Menzi Guest

    coachball8

    You can't modify Block Inserts, you have to change the Block Reference:

    (defun BlkMod (Nme Lay / BlkTbl CurEnt EntLst)
    (setq BlkTbl (tblobjname "BLOCK" Nme)
    CurEnt (cdr (assoc -2 (entget BlkTbl)))
    )
    (while (setq CurEnt (entnext CurEnt))
    (setq EntLst (entget CurEnt))
    (if (eq (cdr (assoc 0 EntLst)) "MTEXT")
    (entmod
    (subst
    (cons 8 Lay)
    (assoc 8 EntLst)
    EntLst
    )
    )
    )
    )
    (entupd BlkTbl)
    (command "_.REGEN")
    (princ)
    )

    Use:
    (BlkMod "MyBlockName" "NewLayer")

    Cheers
     
    Jürg Menzi, May 27, 2004
    #4
  5. coachball8

    coachball8 Guest

    Thanks for the help. That's really what I was trying to, but I don't have enough experience to get it done. I came up with this from some code Jason P. had posted:

    (defun C:Chrblyr (/ Ent Lst Clr)
    (while (not (setq Ent (nentsel "\nselect an object: "))))

    (while Ent
    (setq Lst (cons (car Ent) Lst))
    (setq Ent (nentsel "\nselect an object <done>: "))
    )

    ;(while (or (not Clr) (> Clr 256))
    ;(initget 6) (setq Clr (getint "\nspecify a color number: "))
    ;)

    (foreach x Lst (vla-put-layer (vlax-ename->vla-object x) "mylayer"))
    (princ)
    )
    It works okay, but you have to select each piece of text, and it doesn't regen. Yours works better. Thanks to you and Bill. You guys are great!
     
    coachball8, May 27, 2004
    #5
  6. coachball8

    Jamie Duncan Guest

    I think I revised this properly, you may want to check the parenteses...:)

    this is done in simple lisp - and offers recursion for nested blocks - an
    alternate to Jurg's posting

    Jamie Duncan

    (defun c:fixents (/ ss1 temp ent1 looper entdat bnm ctr enttyp bl_list
    new_lay)
    (command ".layer" "t" "0" "un" "0" "s" "0" "")
    (setq ss1 (ssadd) looper T ctr 0)
    (setq new_lay (getvar "clayer"))
    (while looper
    (prompt "\nSelect Entities to set to Bylayer for Colour and Linetype: ")
    (setq ss1 (ssget))
    (if ss1 (setq looper nil))
    )
    (repeat (sslength ss1)
    (setq ent1 (ssname ss1 ctr) entdat (entget ent1) enttyp (cdr (assoc 0
    entdat)))
    (if (= enttyp "INSERT")
    (progn
    (setq bl_list (list (cdr (assoc 2 entdat))))
    (foreach bnm bl_list
    (jddfixablock bnm)
    )
    )
    )
    (setq ctr (+ ctr 1))
    )
    (princ)
    )
    (defun jddfixablock (bname new_lay / enam1 end1)
    (setq enam1 (tblobjname "block" bname))
    (while (setq enam1 (entnext enam1))
    (setq end1 (entget enam1))
    (if (= (cdr (assoc 0 end1)) "MTEXT")
    (progn
    (setq end1 (subst (cons 8 new_lay)(assoc 8 end1)
    end1))
    (entmod end1)
    )
    (progn
    (if (= (cdr (assoc 0 (entget enam1))) "INSERT")
    (setq bl_list (append bl_list (list (cdr
    (assoc 2 (entget ent1))))))
    )
    )
    )
    )
    )
     
    Jamie Duncan, May 27, 2004
    #6
  7. coachball8

    Jürg Menzi Guest

    coachball8

    Glad to help you...

    My proposition to use the function:
    (remove the Regen command from 'BlkMod')

    (defun C:ChangeBlockMtextLayer ( / CurEnt CurSet)
    (princ "\nSelect Blocks...")
    (if (setq CurSet (ssget '((0 . "INSERT"))))
    (progn
    (while (setq CurEnt (ssname CurSet 0))
    (BlkMod (cdr (assoc 2 (entget CurEnt))) "NewLayerName")
    (ssdel CurEnt CurSet)
    )
    (command "_.REGEN")
    )
    )
    (princ)
    )

    This allows you to select *all* block you wish to change...

    Cheers
     
    Jürg Menzi, May 27, 2004
    #7
  8. coachball8

    coachball8 Guest

    Thanks again, but I have yet another question. I'd like to use a wildcard in the block name, since all the blocks have the same name, but are prefixed by a number (i.e. 1_revblk__000 would be for an a-sized dwg, while 2_revblk___000 would be for a b-size, and so on and so forth). I can't use wildcards with this, so how can I create a list of the blocks, and then search only those on the list. Thanks again for your help.
     
    coachball8, May 27, 2004
    #8
  9. coachball8

    coachball8 Guest

    Thanks to you too, Jamie. I'll give it a whirl.
     
    coachball8, May 27, 2004
    #9
  10. coachball8

    Jürg Menzi Guest

    coachball8

    (defun C:ChangeBlockMtextLayer ( / CurEnt CurSet)
    (if (setq CurSet (ssget "X" '((0 . "INSERT")(2 . "#_revblk__000"))))
    (progn
    (while (setq CurEnt (ssname CurSet 0))
    (BlkMod (cdr (assoc 2 (entget CurEnt))) "NewLayerName")
    (ssdel CurEnt CurSet)
    )
    (command "_.REGEN")
    )
    )
    (princ)
    )

    Cheers
     
    Jürg Menzi, May 27, 2004
    #10
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.