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
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
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")
)
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 :mrgreen:
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
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
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
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