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

0 Members and 1 Guest are viewing this topic.

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: 7526
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?