Author Topic: Is there a way to insert & update multiple blocks at a time?  (Read 8412 times)

0 Members and 2 Guests are viewing this topic.

sezbw

  • Guest
Is there a way to insert & update multiple blocks at a time?
« on: October 23, 2007, 10:22:14 PM »
OK so being the block loving nerd I am, I have got myself in a bit of a tricky spot.

I have a whole bunch of blocks (column) in numerous drawing plans ie, C1-800x300, C2-600DIA ETC... 

The blocks are saved outside my drawings in a folder.  I have updated these files now I need to re-import them & update them in a load of plans.  Is there a way to insert & update multiple blocks at a time, so I don't have to do them individually.

In the past on swamp I have found a fantastic block swap command, but this time I just want to globally change all blocks of one name to be the same as an external file of the same name.
 :ugly:
Sorry my powers of explanation seem to be failing me...


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

FengK

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #2 on: October 24, 2007, 03:19:28 AM »
i didn't finish reading the posts in the threads that Alan listed, but it appears to me the lisp commands in those posts are used for replacing block "A" with block "B" which is already in the drawing. and the problem sezbw is trying to solve is different.

don't quote me on this: suppose he has a block named "A" in drawing, and he has another drawing named "A.dwg" which is the new block he wants to replace the old one with. when manually inserting the block (type command "INSERT" and browse that "A.dwg" file), user will be prompted whether to replace the old block definition in drawing or not. but if the block is inserted via lisp, the old block definition will be used.

if what i said above was correct, one way to resolve it would be renaming the old block (to some unique name) in drawing first, inserting the new block, deleting the old block and purging the block definition with the "unique name". this seems to be a good opportunity to use objectDbx.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #3 on: October 24, 2007, 07:31:34 AM »
sounds like you should have used xrefs . . .
James Buzbee
Windows 8

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #4 on: October 24, 2007, 07:41:16 AM »
sounds like you should have used xrefs . . .
:? :?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #5 on: October 24, 2007, 08:52:02 AM »
sounds like you should have used xrefs . . .
:? :?


Quote
The blocks are saved outside my drawings in a folder.  I have updated these files now I need to re-import them & update them in a load of plans.

Am I missing something here??
James Buzbee
Windows 8

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #6 on: October 24, 2007, 08:53:20 AM »
Have a look at Post Reply #7 here .. does that suit you ?

http://www.theswamp.org/index.php?topic=9229.msg118979#msg118979


added:

Though you could make a selectionSet of inserted blocks and only replace those from the FolderList ...
« Last Edit: October 24, 2007, 08:56:19 AM by Kerry Brown »
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #7 on: October 24, 2007, 09:07:53 AM »
sounds like you should have used xrefs . . .
:? :?


Quote
The blocks are saved outside my drawings in a folder.  I have updated these files now I need to re-import them & update them in a load of plans.

Am I missing something here??
You first statement sounded very opinionated, implying that xrefs is the only way.  That is all.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

daron

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #8 on: October 24, 2007, 09:16:58 AM »
That was my first thought as well, that he should have used xrefs. There is an express tool for that purpose, but it's painfully slow. Another thought I also had in regards to xrefs is that if you have multiple xrefs in one drawing you end up with slower load time, so sometimes you are better off not using xrefs. I would assume that would be part of the reasoning for not having used them, but that's just me. They have their purpose, but not at the expense of load times. Wouldn't ODBX be usable here?

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #9 on: October 24, 2007, 09:28:00 AM »
Before Project Navigator I used to use a routine that would "attach" attributes to an XREF.  Basically you inserted the file first (became a block with attributes), renamed it, then Xrefed it.  Then I used entmod to change the xref to the inserted block and deleted the old reference.  You could attach the drawing as an xref then use something like the following to "point" the existing blocks to the xref: (you'll needd to make sure the two don't share a common name)

Code: [Select]
(setq block (entget (car(entsel"\nSelect Block")))
      xref-name(cdr(assoc 2(entget(car(entsel "\nSelect Xref"))))))
      (setq new-blk (subst (cons 2 xref-name) (assoc 2 block) block))
      (entmod new-blk)

(warning: this is very bad coding - only used as an illustration!)
James Buzbee
Windows 8

CADaver

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #10 on: October 24, 2007, 10:25:23 AM »
Have a look at Post Reply #7 here .. does that suit you ?

http://www.theswamp.org/index.php?topic=9229.msg118979#msg118979


added:

Though you could make a selectionSet of inserted blocks and only replace those from the FolderList ...
If you select the title link of the specific post in a thread you can paste it here, like this:

http://www.theswamp.org/index.php?topic=9229.msg119393#msg119393

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #11 on: October 24, 2007, 10:36:51 AM »
Have a look at Post Reply #7 here .. does that suit you ?

http://www.theswamp.org/index.php?topic=9229.msg118979#msg118979


added:

Though you could make a selectionSet of inserted blocks and only replace those from the FolderList ...
If you select the title link of the specific post in a thread you can paste it here, like this:

http://www.theswamp.org/index.php?topic=9229.msg119393#msg119393

Yes, I know. All the posts are tied together in my mind .. and I did say reply 7 ... do you think I made it too difficult for the OP ?
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.

CADaver

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #12 on: October 24, 2007, 10:51:11 AM »
Have a look at Post Reply #7 here .. does that suit you ?

http://www.theswamp.org/index.php?topic=9229.msg118979#msg118979


added:

Though you could make a selectionSet of inserted blocks and only replace those from the FolderList ...
If you select the title link of the specific post in a thread you can paste it here, like this:

http://www.theswamp.org/index.php?topic=9229.msg119393#msg119393

Yes, I know. All the posts are tied together in my mind .. and I did say reply 7 ... do you think I made it too difficult for the OP ?
Just offering the suggestion that in the time it took you to count the seventh post you could have linked it directly.  Silly of me to interfere.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #13 on: October 24, 2007, 11:04:02 AM »
 Re: Is there a way to insert & update multiple blocks at a time?
« Reply #12 on: Today at 00:51:11 »

Quote
.. Silly of me to interfere.
Perhaps it was.
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.

CADaver

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #14 on: October 24, 2007, 11:09:52 AM »
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #12 on: Today at 00:51:11 »

Quote
.. Silly of me to interfere.
Perhaps it was.
Sometimes suggestions are appreciated, sometimes not.  I'll make a note that Kerry never needs any kind of suggestions, thanks for the heads-up.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #15 on: October 24, 2007, 12:16:07 PM »
What's wrong with using the plan old INSERt command?

From the Help file on INSERT command

Updating a Block Path: If you enter a block name without a path name, AutoCAD
first searches the current drawing data for an existing block definition by that
name. If no such block definition exists in the current drawing, AutoCAD
searches the library path for a file of the same name. If AutoCAD finds such a
file, it uses the file name for the block name upon insertion of the block
definition. AutoCAD uses the same block definition for subsequent insertions of
that block. You can replace an existing block definition with an external file
by entering the following at the Enter Block Name prompt:

block name=file name


You can simply use the command line version of the INSERT command like this:

Code: [Select]
(command "-INSERT" "YourBlockName=YourBlockName")
(command)

Your block name must be in the path else use this:

Code: [Select]
(command "-INSERT" (strcat "YourBlockName="  path "YourBlockName") )
(command)

The (command) aborts the INSERT but not before the block definition has been updates.

You can process a list of block names like this:

Code: [Select]
(foreach name '("b1" "b2" "b3")
  (command "-INSERT" (strcat name "=" name)
  (command)
)


You can add this to a script. The problem comes when the block is not found.
An error occurs and your script is stopped.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #16 on: October 24, 2007, 12:33:19 PM »
Quote
...The problem comes when the block is not found.
An error occurs and your script is stopped.

Here is one to check if the block definition exists before trying to insert:

Code: [Select]
(foreach name '("b1" "b2" "b3")
  (if (tblsearch "block" name)
    (command "-INSERT"
     (strcat name "=" name)
    )
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

FengK

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #17 on: October 24, 2007, 01:10:37 PM »
Thanks Alan & ronjonp, i didn't know about this one:

(command "-INSERT" "YourBlockName=YourBlockName")
(command)

CADaver

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #18 on: October 24, 2007, 05:30:51 PM »
Thanks Alan & ronjonp, i didn't know about this one:

(command "-INSERT" "YourBlockName=YourBlockName")
(command)
Just a suggestion, but the names can be different as well

Code: [Select]
(command "-INSERT" "YourBlockName=c:/MyDirOfSomeName/peanut/butter/SomeOtherDwgName")
(command)

FengK

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #19 on: October 24, 2007, 09:55:41 PM »
Thanks Randy.

CADaver

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #20 on: October 24, 2007, 11:25:14 PM »
Thanks Randy.
You're quite welcome.

Luke

  • Guest
Re: Is there a way to insert & update multiple blocks at a time?
« Reply #21 on: April 11, 2008, 03:30:32 PM »
OK so my code is as follows:
Quote
(command "-INSERT" "YourBlockName1=c:/MyDirOfSomeName/peanut/butter/YourBlockName1")
(command)

I'm almost embarrassed asking (but will anyhow..) how do i add a second line to get it to replace old block2 with newblock2?