Step through block definition, Nil returned INSTEAD of last element.

Discussion in 'AutoCAD' started by RDI, Jan 20, 2004.

  1. RDI

    RDI Guest

    When I try to step through a block definition, it returns nil INSTEAD of the
    last element. Any ideas on why?

    (defun dxf (code elist)
    (cdr (assoc code elist))
    )
    ;returns the block "header"
    (setq cent2 (tblsearch "block" blockname))
    ;returns the line
    (setq cent2(entget(entnext(if (dxf -2 cent2)(dxf -2 cent2)(dxf -1 cent2)))))
    ;returns the text
    (setq cent2(entget(entnext(if (dxf -2 cent2)(dxf -2 cent2)(dxf -1 cent2)))))
    ;returns the FIRST block
    (setq cent2(entget(entnext(if (dxf -2 cent2)(dxf -2 cent2)(dxf -1 cent2)))))

    ;returns nil--why not the SECOND block?
    (setq cent2(entget(entnext(if (dxf -2 cent2)(dxf -2 cent2)(dxf -1 cent2)))))
     
    RDI, Jan 20, 2004
    #1
  2. RDI

    ECCAD Guest

    RDI,
    You looking for the 2nd blockname in the 'block' table, or the
    second block in the drawing by that name.
    If in .dwg, do a (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blockname)))); where blockname = "header"
    If in block' table, there is only (1) block by that name,
    use (foreach (setq cent2 (tblsearch 'block'...
    Bob
     
    ECCAD, Jan 20, 2004
    #2
  3. RDI

    Mark Propst Guest

    try this snip from a toolbox routine
    (defun GetBlockParts(blockname)
    ;if you want to modify block, need tblobjname, not tblsearch
    (setq gbp:List(entget(tblobjname "BLOCK" blockname)))
    ;get first subentity of block definition
    (setq gbp:subent(cdr(assoc -2 gbp:List)))
    (while
    gbp:subent
    (print (cdr(assoc 0(entget gbp:subent))))
    (setq gbp:subent(entnext gbp:subent)))
    (princ)
    )
    (defun test2()
    (setq blkname"YourBlockName")
    (GetBlockParts blkname)
    )
     
    Mark Propst, Jan 20, 2004
    #3
  4. RDI

    Mark Propst Guest

    here's with a bit of cleanup and error checking
    (defun PrintBlockParts(blockname / gbp:MasterList gbp:subent)
    ;if you want to modify block, need tblobjname, not tblsearch
    (setq blkent (tblobjname "BLOCK" blockname))
    (if blkent
    (progn
    (setq gbp:MasterList(entget blkent))
    ;get first subentity of block definition
    (setq gbp:subent(CDR(ASSOC -2 gbp:MasterList)))
    (princ(strcat "\nBlock " blockname " contains the following entity
    types"))
    (while
    gbp:subent
    (print (cdr(assoc 0(entget gbp:subent))))
    (setq gbp:subent(entnext gbp:subent)))
    );progn
    (princ(strcat "No block found: " blockname))
    );if
    (princ)
    )
    (defun test()
    (setq blkname"YourBlockName")
    (PrintBlockParts blkname)
    )
     
    Mark Propst, Jan 20, 2004
    #4
  5. RDI

    rdi Guest

    Thanks Mark! That worked great!

    Why does tlbojname work better than tblsearch? From what I've seen, they
    both return similar info.

    The tblobjname returns the EntName which you then use entget to get the
    entity list. While tblsearch returns the entity list.
     
    rdi, Jan 22, 2004
    #5
  6. RDI

    Mark Propst Guest

    why? I don't know...it's just that the help tells you that if you want to
    modify an entity, you must use the list derived from tblobjname, instead of
    the list from tblsearch. They look similar but if it's in the help it cant'
    be wrong <g>! right? :)~
    So if you just need info, tblsearch is fine, if you need to modify info,
    tblobjname is the key.
     
    Mark Propst, Jan 22, 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.