PDA

View Full Version : How to automaticly select entities and create a block


dfuehrer
2005-10-26, 04:40 PM
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

dfuehrer
2005-10-26, 07:40 PM
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:

(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

Opie
2005-10-26, 08:08 PM
Don you will need to search the BLOCK table for the BLOCKNAME See the modifications below.
(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")
)

tyshofner
2005-10-26, 08:12 PM
This should do it:


(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:

dfuehrer
2005-10-26, 08:51 PM
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

Opie
2005-10-26, 08:55 PM
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?

(c:scalebar);; this one should work
or
(scalebar);; this one would not

dfuehrer
2005-10-26, 09:01 PM
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

Opie
2005-10-26, 09:17 PM
Yes you can take it out of its definition and place it in your code where you want it.

dfuehrer
2005-10-26, 09:39 PM
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

kennet.sjoberg
2005-10-27, 12:06 AM
...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....

(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

tyshofner
2005-10-27, 12:37 AM
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.

(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:

dfuehrer
2005-10-27, 05:09 PM
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

Opie
2005-10-27, 05:17 PM
Don,

I haven't had a chance to look at your routine, but I had a question due to my curiousity. Would it be easier to just make the various scale bars that you need and just insert the desired block into your drawing?

dfuehrer
2005-10-27, 05:30 PM
No, not really. The scale bars are aligned with part of our 8 1.2 x 11 title blocks, and on those layout tabs, we are not putting them to any particular scale.

Here at Mayo, we just show as much of the building as we can. The smaller buildings are zoomed in further, the larger ones zoomed out further. Sorry, this is not my solution, rather a legacy situation. I am no position to do things differently. Just bend like the willow (Grasshopper).

The problem with the scale bars is that part of the bar has the line weight overridden to be wider. I want to grab everything in model space and set it to be all Bylayer (line weight, line type, and color). Still working on the color issue. Any ideas there??

Don

Opie
2005-10-27, 05:31 PM
When you create your scale blocks, you can change the properties of those entities within your code or when you create the blocks manually.

dfuehrer
2005-10-27, 05:54 PM
The scale bars are already present, like I said legacy stuff. I am including an example. As you can see, they are on one layer, made up of text, lines, and lines that have their width modified...

Don

tyshofner
2005-10-27, 08:47 PM
Took a quick look. Try this out I didn't test it but it looked like you were trying to define the function within another function. I took out the "scalebar" defun and moved the function to the end of the file. You then call the function "(c:scalebar)" at the appropriate point in the code (where you had the defun).

Let me know if it works.

Ty :mrgreen:

dfuehrer
2005-10-27, 11:03 PM
Ty,

I took more than a quick look. You rock! Thank you very much. It (now) makes sense to me that it the command SPACEBAR has to be defined under it's own heading, then called up using (c:spacebar) to run it where I want it in the code. THANK YOU!

Are you going to attend AU this year?

Don :)

tyshofner
2005-10-28, 02:18 AM
My pleasure!! No I will not be attending AU this year :cry:. I'm just to busy.

Ty :mrgreen: