search for insertion point of blocks

Discussion in 'AutoCAD' started by molokaiboy, Aug 3, 2004.

  1. molokaiboy

    Jürg Menzi Guest

    Hi Collin
    The block name 'Block1-1' is not valid:
    - if missing .dwg extension
    - if outside of the AutoCAD environment, missing path and/or .dwg extension

    To solve the problem with already inserted blocks use this one:
    Code:
    (defun C:AddTableRow ( / AcaDoc BlkFil BlkNme BlkObj CurEnt CurObj CurSpc
    FltStr InsPnt NmeLst TmpLst)
    (vl-load-com);("RefBlockName . "AddBlockName.dwg"):
    (setq NmeLst '(
    ("Block1" . "Block1-1.dwg")
    ("Block2" . "Block2-1.dwg")
    ("Block3" . "Block3-1.dwg")
    ("Block4" . "Block4-1.dwg")
    ("Block5" . "Block5-1.dwg")
    ("Block6" . "Block6-1.dwg")
    )
    TmpLst (mapcar 'car NmeLst)
    FltStr (apply 'strcat
    (cons
    (car TmpLst)
    (mapcar '(lambda (l) (strcat "," l)) (cdr TmpLst))
    )
    )
    
    );end setq
    (if (setq CurSet (ssget "X" (list (cons 2 FltStr))))
    (progn
    (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt)
    InsPnt (vlax-get CurObj 'InsertionPoint)
    BlkFil (cdr (assoc (vla-get-Name CurObj) NmeLst))
    BlkNme (vl-filename-base BlkFil)
    FltLst (list
    (cons 2 BlkNme)
    '(-4 . "<AND")
    '(-4 . ">,>,*") (cons 10 (mapcar '- InsPnt '(1E-6 1E-6 0)))
    '(-4 . "<,<,*") (cons 10 (mapcar '+ InsPnt '(1E-6 1E-6 0)))
    '(-4 . "AND>")
    )
    )
    ;check is block name already inserted at this point
    (if (not (ssget "X" FltLst))
    (progn
    (setq CurSpc (vla-ObjectIDToObject AcaDoc (vla-get-OwnerID CurObj))
    BlkObj (vla-InsertBlock
    CurSpc (vlax-3d-point InsPnt) BlkFil 1 1 1 0
    )
    )
    ;;; if the existing block is on layer 'notes' use this line:
    (vla-put-Layer BlkObj (vla-get-Layer CurObj))
    ;;; if not, this one:
    (vla-put-Layer BlkObj "notes")
    )
    (alert (strcat "Block '" BlkNme "' is already inserted at this point."))
    )
    (ssdel CurEnt CurSet)
    );end progn
    );end while
    );end setq
    (princ)
    );end defun
    
    Cheers
     
    Jürg Menzi, Aug 5, 2004
    #21
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.