search for insertion point of blocks

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

  1. molokaiboy

    molokaiboy Guest

    I am trying to search for the insertion point of block1, and insert block1-1 in at that point. How do I search to find the insertion point for certain blocks?

    TIA

    Collin
     
    molokaiboy, Aug 3, 2004
    #1
  2. molokaiboy

    Walt Engle Guest

    Open the blocks as a dwg and type "base" (without the quotes) and look at the command line - you will be given the x,y & z coordinates of the insertion point. You
    can also change it at that time if you want by type a new x,y & z coordinate or picking a point.
     
    Walt Engle, Aug 3, 2004
    #2
  3. molokaiboy

    MP Guest

    just to get you started...
    (vl-load-com)
    (setq blkname "block1")
    (setq blkset(ssget"x"(list(cons 2 blkname))))
    (if blkset
    (progn
    (setq i 0)
    (repeat(sslength blkset)
    (setq vo(vlax-ename->vla-object(ssname blkset i)))
    (setq inspt
    (vlax-safearray->list
    (vlax-variant-value
    (vlax-get-property vo 'Insertionpoint)
    )
    )
    )
    (princ inspt)
    (terpri)
    (setq i(1+ i))
    )
    )
    )

    block1-1 in at that point. How do I search to find the insertion point for
    certain blocks?
     
    MP, Aug 3, 2004
    #3
  4. molokaiboy

    molokaiboy Guest

    I failed to mention that I first need to search to see if that block is inserted into the drawing, then find that insertion point and insert in another block at that insertion point.

    Collin
     
    molokaiboy, Aug 3, 2004
    #4
  5. molokaiboy

    Jürg Menzi Guest

    Hi Collin

    Check this function. Proceeds blocks in paperspace also.

    Code:
    (defun C:InsAtBlock ( / AcaDoc BlkObj CurEnt CurObj CurSpc InsPnt)
    (vl-load-com)
    (setq RefNme "block1"
    NewNme "block1-1.dwg" ;'.dwg' if the block isn't in the drawing
    )
    (if (setq CurSet (ssget "X" (list (cons 2 RefNme))))
    (progn
    (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt)
    InsPnt (vla-get-InsertionPoint CurObj)
    CurSpc (vla-ObjectIDToObject AcaDoc (vla-get-OwnerID CurObj))
    BlkObj (vla-InsertBlock CurSpc InsPnt NewNme 1 1 1 0)
    )
    ; If you want copy one or several properties from the given block
    ; to the new block, uncomment the corresponding line(s).
    ;;;    (vla-put-Layer BlkObj (vla-get-Layer CurObj))
    ;;;    (vla-put-Linetype BlkObj (vla-get-Linetype CurObj))
    ;;;    (vla-put-LinetypeScale BlkObj (vla-get-LinetypeScale CurObj))
    ;;;    (vla-put-LineWeight BlkObj (vla-get-LineWeight CurObj))
    ;;;    (vla-put-Normal BlkObj (vla-get-Normal CurObj))
    ;;;    (vla-put-Rotation BlkObj (vla-get-Rotation CurObj))
    ;;;    (vla-put-Visible BlkObj (vla-get-Visible CurObj))
    ;;;    (vla-put-XScaleFactor BlkObj (vla-get-XScaleFactor CurObj))
    ;;;    (vla-put-YScaleFactor BlkObj (vla-get-YScaleFactor CurObj))
    ;;;    (vla-put-ZScaleFactor BlkObj (vla-get-ZScaleFactor CurObj))
    (ssdel CurEnt CurSet)
    )
    )
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Aug 3, 2004
    #5
  6. molokaiboy

    molokaiboy Guest

    Thanks for the input. I'll try it out.

    Collin
     
    molokaiboy, Aug 3, 2004
    #6
  7. molokaiboy

    molokaiboy Guest

    I get this error message:
    Command: ; error: Automation Error. Filer error
    What I am doing wrong?


    (defun C:AddTableRow ( / AcaDoc BlkObj CurEnt CurObj CurSpc InsPnt)
    (vl-load-com)
    (command "-osnap" "off")
    (setq RefNme "DashTable-2COL"
    NewNme "DashTable-2COL-AddROW" ;'.dwg' if the block isn't in the drawing

    );end setq
    (if (setq CurSet (ssget "X" (list (cons 2 RefNme))))
    (progn
    (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt)
    InsPnt (vla-get-InsertionPoint CurObj)
    CurSpc (vla-ObjectIDToObject AcaDoc (vla-get-OwnerID CurObj))
    BlkObj (vla-InsertBlock CurSpc InsPnt NewNme 1 1 1 0)
    );end if

    (if(tblsearch "block" DashTable-2COL)
    (command "-layer" "S" "notes" "" "" "-insert" "DashTable-2COL-AddROW.dwg" InsPnt "" "" "0")
    )


    (ssdel CurEnt CurSet)
    );end progn
    );end while
    );end setq

    (princ)
    );end defun

    TIA

    Collin
     
    molokaiboy, Aug 4, 2004
    #7
  8. molokaiboy

    Walt Engle Guest

    Why are you going to all this trouble? Blocks are dwgs that are inserted. Open the dwg, type BASE and at the command
    line you will be given the x,y & z coordinates. That is the base or insertion point.
     
    Walt Engle, Aug 4, 2004
    #8
  9. molokaiboy

    ajm Guest

    Try this :

    (setq blk (entget (car (entsel)))) ;retrieve block definition
    (setq bn (cdr (assoc 2 blk))) ;retrieve blocks name
    (setq bxs (cdr (assoc 41 blk))) ;retrieve blocks x scale factor
    (setq bip (cdr (assoc 10 blk))) ;retrieve blocks insertion point

    H.T.H.
    Andrew McDonald
     
    ajm, Aug 4, 2004
    #9
  10. molokaiboy

    Jürg Menzi Guest

    Hi Collin
    Read my comment:
    ;'.dwg' if the block isn't in the drawing

    Code:
    (defun C:AddTableRow ( / AcaDoc BlkObj CurEnt CurObj CurSpc InsPnt NewNme
    OldOsm RefNme)
    (vl-load-com)
    (setq OldOsm (getvar "OSMODE") ;save current OSMODE
    (setvar "OSMODE" 0)
    (setq RefNme "DashTable-2COL"
    ;'.dwg' (also path if block is not in acad support environment) if the block
    ;isn't in the drawing:
    NewNme "DashTable-2COL-AddROW.dwg"
    );end setq
    (if (setq CurSet (ssget "X" (list (cons 2 RefNme))))
    (progn
    (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt)
    InsPnt (vla-get-InsertionPoint CurObj)
    CurSpc (vla-ObjectIDToObject AcaDoc (vla-get-OwnerID CurObj))
    BlkObj (vla-InsertBlock CurSpc InsPnt NewNme 1 1 1 0)
    );end if
    ;you don't need following lines, block is inserted by 'vla-InsertBlock'
    ;above:
    ;;;    (if(tblsearch "block" DashTable-2COL)
    ;;;     (command "-layer" "S" "notes" "" ""
    ;;;              "-insert" "DashTable-2COL-AddROW.dwg" InsPnt "" "" "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")
    (ssdel CurEnt CurSet)
    );end progn
    );end while
    );end setq
    (setvar "OSMODE" OldOsm) ;restore OSMODE
    (princ)
    );end defun
    
    Cheers
     
    Jürg Menzi, Aug 4, 2004
    #10
  11. molokaiboy

    molokaiboy Guest

    Juerg,

    I need to add 5 more blocks to the search. The drawing could consist of either block1 or block2, etc. How would I add this in so that it searches to see what block is inserted and what that insertion point is so that I can insert in block1-1 or block2-1, etc. at the given insertion point?

    TIA

    Collin
     
    molokaiboy, Aug 4, 2004
    #11
  12. molokaiboy

    molokaiboy Guest

    Thanks ajm. Will this work?

    (defun C:AddTableRow ()

    (command "-osnap" "off")
    (setq RefNme "DashTable-2COL"

    (setq DashTable-2COLblk (entget (car (entsel)))) ;retrieve block definition
    (setq DashTable-2COLbn (cdr (assoc 2 blk))) ;retrieve blocks name
    (setq DashTable-2COLbxs (cdr (assoc 41 blk))) ;retrieve blocks x scale factor
    (setq DashTable-2COLbip (cdr (assoc 10 blk))) ;retrieve blocks insertion point

    (setq DashTable-3COLblk (entget (car (entsel)))) ;retrieve block definition
    (setq DashTable-3COLbn (cdr (assoc 2 blk))) ;retrieve blocks name
    (setq DashTable-3COLbxs (cdr (assoc 41 blk))) ;retrieve blocks x scale factor
    (setq DashTable-3COLbip (cdr (assoc 10 blk))) ;retrieve blocks insertion point

    (setq TBBA "DashTable-2COL")

    (if(tblsearch "block" DashTable-2COL)
    (command "-layer" "S" "notes" "" "" "-insert" "DashTable-2COL-AddROW.dwg" DashTable-2COLbip "" "" "0")
    )

    (if(tblsearch "block" DashTable-3COL)
    (command "-layer" "S" "notes" "" "" "-insert" "DashTable-2COL-AddROW.dwg" DashTable-3COLbip "" "" "0")
    )


    (princ)
    )


    Collin
     
    molokaiboy, Aug 4, 2004
    #12
  13. molokaiboy

    Jürg Menzi Guest

    Hi Collin

    And here we gooooooooooooooo:

    Code:
    (defun C:AddTableRow ( / AcaDoc BlkObj CurEnt CurObj CurSpc FltStr InsPnt
    NmeLst TmpLst)
    (vl-load-com) ;("OldBlockName . "NewBlockName.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")
    )
    ;;; AFAIK, there is a limit for the ssget filter:
    ;;; all old block names together including the comma delimiters shouldn't
    ;;; exceed 255 characters (with the actual names you get 41 characters)
    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 (vla-get-InsertionPoint CurObj)
    NewNme (cdr (assoc (vla-get-Name CurObj) NmeLst))
    CurSpc (vla-ObjectIDToObject AcaDoc (vla-get-OwnerID CurObj))
    BlkObj (vla-InsertBlock CurSpc InsPnt NewNme 1 1 1 0)
    );end if
    ;;; 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")
    (ssdel CurEnt CurSet)
    );end progn
    );end while
    );end setq
    (princ)
    )
    Cheers
     
    Jürg Menzi, Aug 4, 2004
    #13
  14. molokaiboy

    molokaiboy Guest

    Jürg,

    I get this error message when I run the command. I inserted in block "block1" and this is what I got:

    ; error: Automation Error. Filer error

    What does this mean?

    TIA

    Collin
     
    molokaiboy, Aug 4, 2004
    #14
  15. molokaiboy

    molokaiboy Guest

    ajm,

    I got this to work fine. It prompts me to select the block. Is there a way for me to bypass having the user select the block and have the lisp do it?

    TIA

    Collin
     
    molokaiboy, Aug 4, 2004
    #15
  16. molokaiboy

    molokaiboy Guest

    Andrew,

    I got it to work. Thanks for supplying the code.

    Collin
     
    molokaiboy, Aug 4, 2004
    #16
  17. molokaiboy

    molokaiboy Guest

    Andrew,

    I got it to work fine, but now I need to add an alert box if the block exists. How can I do that?

    (if(tblsearch "block" DashTable-2COL)
    (command "-layer" "S" "notes" "" "" "-insert" "DashTable-2COL-AddROW.dwg" DashTable-2COLbip "" "" "0")

    TIA

    Collin
     
    molokaiboy, Aug 4, 2004
    #17
  18. molokaiboy

    T.Willey Guest

    (if (tblsearch "block" DashTable-2COL)
    (progn
    (alert (strcat DashTable-2COL " exist in drawing
    Insearting Dash Table-2COL-AddRow.dwg"))
    (command "-layer" "S" "notes" "" "" "-insert" "DashTable-2COL-AddROW.dwg" DashTable-2COLbip "" "" "0")
    );- end progn
    );- end if

    This should work.
     
    T.Willey, Aug 4, 2004
    #18
  19. molokaiboy

    molokaiboy Guest

    How do I set it so that if the block doesn't exist, it will insert it in, and if it already exists, it will not reinsert the block but pop up the alert msg.

    TIA
    Collin
     
    molokaiboy, Aug 5, 2004
    #19
  20. molokaiboy

    molokaiboy Guest

    Andrew,

    How do I get it to select the block through the lisp instead of prompting the user??

    ;(setq DashTable-2COLblk (entget (car (entsel)))) ;retrieve block definition

    TIA

    Collin
     
    molokaiboy, Aug 5, 2004
    #20
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.