Author Topic: Finding a block name  (Read 3273 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Finding a block name
« on: December 01, 2005, 07:38:13 AM »
How can I search a drawing to find a particular block name?
I want to look at a drawing, see which title block is inserted as a block, and then dependant on which one is loaded run a page setup routine.

I know the dotted pair for a block is (0 . "block_name"), but how can i search for any block name ending in "sheet"?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

nivuahc

  • Guest
Re: Finding a block name
« Reply #1 on: December 01, 2005, 07:44:16 AM »
I just threw something together yesterday that might help you out. I'll post it, along with a few suggestions, when I get to the orifice.

If you can't wait, and want to attempt to tackle it on your own, consider looking up tblnext.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding a block name
« Reply #2 on: December 01, 2005, 07:45:20 AM »
ssget honours wildcards, so something like ..

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "*SHEET"))))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding a block name
« Reply #3 on: December 01, 2005, 07:57:14 AM »
.. just for the sake of completeness, if you want to be more selective ..

(setq ss1 (ssget "_X" '((0 . "INSERT") (2 . "*SHEET,*SHEET01"))))

(setq ss2 (ssget "_X" '((0 . "INSERT") (2 . "x_SHEET,y_SHEET,main_SHEET,SHEET01"))))

.. note that there are no spaces after the comma
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

nivuahc

  • Guest
Re: Finding a block name
« Reply #4 on: December 01, 2005, 08:42:28 AM »
silly me, I was going to suggest something completely different :oops:

Anyways, what I was going to suggest was a completely different approach (I didn't think Hudster was actually trying to 'select' the block).

My initial thought was to use tblnext to find out which blocks were defined in the drawing such as

Code: [Select]
(defun BuildBlockList (/ BlockItem)
  (setq BlockList nil)
  (setq BlockItem (tblnext "BLOCK" T))
 
  (while (/= BlockItem nil)
    (setq BlockList
   (append BlockList
   (list (cdr (assoc 2 BlockItem)) ;; Name
);_end list
   );_end append
  );_end setq BlockList
    (setq BlockItem (tblnext "BLOCK"))
  );_end while
 
  ;; uncomment the following block to display a list of the results
 
;;;  (mapcar
;;;    '(lambda (BlockListItem)
;;;       (princ (strcat "\n" BlockListItem))
;;;       );_end lambda
;;;    BlockList
;;;    );_end mapcar

  ;; uncomment the block above to display a list of the results
 
  (princ)
);_end defun BuildBlockList

And I was going to suggest that, instead of building a list of all blocks like above, eliminate those blocks that don't conform to your criteria. :|

hudster

  • Gator
  • Posts: 2848
Re: Finding a block name
« Reply #5 on: December 01, 2005, 09:03:58 AM »
ssget honours wildcards, so something like ..

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "*SHEET"))))

Cool, I din't think you could use wildcards with ssget.

Thanks you guys, you always come through with an answer. Semms to me like I do a lot of asking though.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Finding a block name
« Reply #6 on: December 01, 2005, 09:45:03 AM »
you can also use...

(setq bname (tblsearch "BLOCK" "your block name"))


 :-D
Keep smile...

nivuahc

  • Guest
Re: Finding a block name
« Reply #7 on: December 01, 2005, 09:51:53 AM »
the way I understood it, the name of the particular block isn't a known factor. Only that it ends in "SHEET".

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding a block name
« Reply #8 on: December 01, 2005, 09:52:58 AM »
you can also use...

(setq bname (tblsearch "BLOCK" "your block name"))


 :-D

*yawn*
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Finding a block name
« Reply #9 on: December 01, 2005, 12:58:04 PM »
Keep smile...