Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: How to automaticly select entities and create a block

  1. #1
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Question How to automaticly select entities and create a block

    Hello everyone,

    I would search this, but am not sure what to use as search criteria, so here goes...

    I am looking for a lisp that selects all entities on a given layer, and then turns those entities into a block named xxxxx inserted at 0,0.

    Does anyone out there have any suggestions?

    Don

  2. #2
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    OK, I have it part of the way, but what if a block named "SCALEBAR" has already been created by this routine, and is present in the drawing?

    How do I have my routine check to see if the block already is defined and is inserted, or maybe if it is defined but not inserted?

    Here is the code I have thus far:

    Code:
    (defun c:scalebar ()
    (setq sel1 (ssget '((0 . "ALL")(8 . "G-TTLB-PLBK"))))
    (command "-block" "SCALEBAR" "0,0" "P" "")
    (command "-insert" "SCALEBAR" "0,0" "" "" "0")
    )
    The problem with what I have, is that if the block is already there, the code errors out with the question "redefine block?". I want to include this in a lisp I am working on so that it will skip over it if the block is already INSERTED. If it is not I want it to insert the definition already there in the drawing. Help!

    Don
    Last edited by Opie; 2005-10-26 at 06:03 PM. Reason: [CODE] tags added

  3. #3
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,174
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    Don you will need to search the BLOCK table for the BLOCKNAME See the modifications below.
    Quote Originally Posted by dfuehrer
    Code:
    (defun c:scalebar ()
    (setq sel1 (ssget '((0 . "ALL")(8 . "G-TTLB-PLBK"))))
    (if (not (tblsearch "BLOCK" "SCALEBAR"))
    (command "-block" "SCALEBAR" "0,0" "P" "")
    )
    (command "-insert" "SCALEBAR" "0,0" "" "" "0")
    )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  4. #4
    I could stop if I wanted to tyshofner's Avatar
    Join Date
    2004-03
    Location
    Dallas, Tx
    Posts
    229
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    This should do it:

    Code:
     
    (defun c:scalebar ()
    (setq sel1 (ssget "X" '((8 . "G-TTLB-PLBK"))))
    (cond
    ((= (tblsearch "BLOCK" "SCALEBAR") nil)
    (command "-block" "SCALEBAR" "0,0" sel1 "")
    (command "-insert" "SCALEBAR" "0,0" "" "" "0")
    )
    ((and (/= (tblsearch "BLOCK" "SCALEBAR") nil) (= (ssget "X" '((0 . "INSERT") (2 . "SCALEBAR"))) nil))
    (command "-insert" "SCALEBAR" "0,0" "" "" "0")
    )
    )
    )
    Ty

  5. #5
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    tyshofner (sorry I don't know your real name),

    Thank you very much for the code. It runs great as a "stand-alone" but not at all when incorporated into the masterpiece I am trying to add it into. Any ideas?

    Don

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,174
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    Quote Originally Posted by dfuehrer
    tyshofner (sorry I don't know your real name),

    Thank you very much for the code. It runs great as a "stand-alone" but not at all when incorporated into the masterpiece I am trying to add it into. Any ideas?

    Don
    How are you calling it in your masterpiece? Are you using the full defined name of the routine?

    Code:
    (c:scalebar);; this one should work
    or
    Code:
    (scalebar);; this one would not
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    Richard,

    I am using it as:

    (c:scalebar)

    I am trying to call it out underneath another defun. Perhaps this is the problem. It just skips over the SCALEBAR portion of the code and continues to run the original defun.

    Can I call it out without the:

    (defun c:scalebar()
    )

    and just use the res of your code?

    Don
    Last edited by dfuehrer; 2005-10-26 at 07:12 PM.

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,174
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    Yes you can take it out of its definition and place it in your code where you want it.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    Still doesn't work! It pauses where ever I I place it, asking to select objects...

    What am I doing wrong?

    Can a lisp be called up from within another lisp?

    Don

  10. #10
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: How to automaticly select entities and create a block

    Quote Originally Posted by dfuehrer
    ...I am looking for a lisp that selects all entities on a given layer, and then turns those entities into a block named xxxxx inserted at 0,0....
    Code:
    (defun c:BlockLayer (/ Ent Lay SelSet )
      ;; Copyright removed
      (if (setq Ent (entsel "Select object on layer to convert to block : " ) )
        (progn
          (command "_.UNDO" "BEgin" )
          (setq Lay (cdr (assoc 8 (entget (car Ent )))) )
          (setq SelSet (ssget "_X" (list (cons 8 (cdr (assoc 8 (entget (car Ent )))) ))))
          (command "._-block" "xxxxx" "0,0,0" SelSet "" )
          (command "._-insert" "xxxxx" "0,0,0" "" "" "" )
          (command "._change" "l" "" "p" "la" Lay "" )
          (command "_.UNDO" "End" )
        )
        (princ "...nothing selected" )
      )
      (princ)
    )
    : ) Happy Computing !

    kennet

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 2012-07-04, 07:40 AM
  2. Select entities by color of an exploded block
    By cadconcepts in forum AutoLISP
    Replies: 12
    Last Post: 2011-06-27, 03:02 PM
  3. Select entities off the screen
    By bweir in forum AutoLISP
    Replies: 5
    Last Post: 2007-04-20, 09:14 PM
  4. Can't select entities
    By jpaulsen in forum AutoCAD General
    Replies: 6
    Last Post: 2007-04-19, 03:20 PM
  5. Select entities without touching them
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2005-10-05, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •