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

Thread: How to automaticly select entities and create a block

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,106
    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,106
    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
    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

  9. #9
    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

    Check to make sure you still have the "X" after the ssget call, or make sure the last answer to the "block" command is still a double quote (""). Or, if you can, just post your "master" code and we'll go from there.

    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

  10. #10
    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

    Hello everyone,

    As requested, here is the code (with comments added) of my "masterpiece. It uses a DCL file to execute the function the user selects -- thanks to those in this forum who helped me get the DCL working properly!

    I'm just trying to ad the functionality to the A1 part of the code that will take the scale bar on our architectural drawings (layer Dependant) and select all entities, turn them into a block named SCALEBAR, inserted at 0,0 in model space of the drawing.

    The part of the code that I am trying to integrate runs perfectly as a stand-alone lisp. My comments about it are in the code.

    Anyway, thank you, one and all for the wonderful help you have been!

    Don
    Attached Files Attached Files

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
  •