TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: rude dog on August 11, 2004, 09:57:34 PM

Title: Inserting blocks with Tablesearch??
Post by: rude dog on August 11, 2004, 09:57:34 PM
Is there a way To reinsert blocks that already exists in the drawing by utilizing the tablesearch and tablenext function?...Does this make for a smaller drawing?....and if it is possible can anyone one point me in the direction of a tutorial......
Thank ya
Title: Inserting blocks with Tablesearch??
Post by: JohnK on August 11, 2004, 10:17:47 PM
Not that i know of. Heres my understanding: the drawing has a Database (Which "tblsearch" queries). Inserting a block will increase the size of a drawing by a factor of 'n', no-matter if its definition exists in the Database or not.

Inserting a block thru code is the same way AutoCAD does it. If the definition dosent exsit in the database then check the paths, if you cant find it in any of the paths, then ask where it is.

Did that make any sence? LoL
Title: Inserting blocks with Tablesearch??
Post by: Jeff_M on August 11, 2004, 10:19:05 PM
I must be not quite understanding what you are asking.

For a block to be inserted to a drawing, it MUST first be defined in the Block Table. Once it is defined (which INSERT does if you specify file from outside the drawing), ALL insertions are just references back to the definition in the Table.

Searching the block table with tblsearch, and tblnext will ONLY tell you if a specific block has been loaded into the drawing.

HTH
Title: Inserting blocks with Tablesearch??
Post by: Kerry on August 11, 2004, 10:24:34 PM
Rude dog,

The INSERT in your drawing USES the definition of the  BLOCK in the COLLECTION/BLOCKTABLE.

There is nothing further you can do in this regard to make a smaller drawing.
Title: Inserting blocks with Tablesearch??
Post by: Kerry on August 11, 2004, 10:25:48 PM
Oops, beaten again by Jeff :)
Title: Inserting blocks with Tablesearch??
Post by: rude dog on August 11, 2004, 11:03:21 PM
I have a lisp routine that creates a 3d object in the backround on layer "0"
after the block is created...the routine calls a nested-routine which names the block<always the same name> and prompts for insertition points..... everytime I initiate the command it recreates the same object...it takes no time for the program to create it <its instanteous> but I was wondering if I was overloading the dwg. a buddy of mine said he could look for the entity name in the table and if it already existed reinsert it thru the table without re-creating it again......I'm probably confusing all Y'ALL.....
I guess ill have to ask him elaborate....Thanks
Title: Inserting blocks with Tablesearch??
Post by: Kerry on August 11, 2004, 11:09:06 PM
Quote from: rude dog
< snip > a buddy of mine said he could look for the entity name in the table and if it already existed reinsert it thru the table without re-creating it again......< snip >


That may reduce your processing time, but will not affect the finished drawing size.
Title: Inserting blocks with Tablesearch??
Post by: rude dog on August 11, 2004, 11:53:56 PM
you are probably correct KB...thanks

Quote

That may reduce your processing time


if it can do this that would still be cool
Title: Inserting blocks with Tablesearch??
Post by: CADaver on August 12, 2004, 07:48:18 AM
Code: [Select]
(defun blkchk (nblkname)
  (if (/= (tblsearch "block" nblkname) nil)
    (setq blkchk1 "Y")
    (progn
      (princ "\nBlock not found . . . creating shape.")
      (setq blkchk1 nil)
    )
  )
)


The above subfunction looks for the supplied <nblkname> from some other function in the existing block list for the drawing.  IF found sets "BLKCHK1" to "Y", if not, sets it to nil (i know, i know)

So in the body of your routine you could use something like:

Code: [Select]

(setq blkname <however_it_is_you_get_the_blockname_defined>)      
(blkchk blkname)      
(if (/= blkchk1 "Y")
  (progn
    ( <insert_the_blinking_thing> )
  )
  (progn
    ( <build_the_blinking_thing> )
  )
)


I'm quite sure the masters lurking here can produce a much more elegant code structure, but this concept fits in my head.
Title: Inserting blocks with Tablesearch??
Post by: rude dog on August 12, 2004, 09:31:11 PM
Appreciate the insight....
mabye Texas aint' so bad after all y'all
thanks cadaver i will study this and try it out when my kids let me use my computer  :)