Overwriting Old Blocks when importing

Overwriting Old Blocks when importing

Domzinator
Advocate Advocate
225 Views
6 Replies
Message 1 of 7

Overwriting Old Blocks when importing

Domzinator
Advocate
Advocate

Hi All

We use Dynamic Blocks for all our standards and we are facing an issue where if we try and import a New Block with the same name as the old one it uses the outdated block that is currently in the drawing and not the new block. we use lisp for this, is there a way to do this without changing the block name?

Snip of  one of our blocks :

defun AXMC3D_ImportBatteryLimit (/)
(setvar "clayer" ".STANDARDS")
(command "Insert" "CUSTOM_BATTERY LIMIT" "s" "1000" PAUSE "")
(setvar "clayer" "0")
(prompt "\nBattery Limit Succesfully Imported! ")
(MC3D_SetAllSystemVars)
(princ)
)




Civil 3D Certified Professional
0 Likes
226 Views
6 Replies
Replies (6)
Message 2 of 7

Moshe-A
Mentor
Mentor

@Domzinator hi,

 

first the following will not work, you should drop the the prefix dot and layer standards must be exist

(setvar "clayer" ".STANDARDS")

 

next this will insert "custom_battery limit" but not update

(command "Insert" "CUSTOM_BATTERY LIMIT" "s" "1000" PAUSE "")

 

to force update block use this call:

(command "insert" "custom_battrey limit=c:/library/blocks/custom_battery limit")

(command) ; as cancel

 

Moshe

 

 

 

0 Likes
Message 3 of 7

Domzinator
Advocate
Advocate
(setvar "clayer" ".STANDARDS")


this does work and works fine, we have a separate Lisp file that creates our Standard Layers ect. all our layers has a . Before the name that is how our company policy is set up,

our  snip you send comes back with a error

Civil 3D Certified Professional
0 Likes
Message 4 of 7

Moshe-A
Mentor
Mentor

post your exec code

0 Likes
Message 5 of 7

Moshe-A
Mentor
Mentor

@Domzinator ,

 

check this update

 

 

; Update a block from outsize dwg block (wblock)
(defun AXMC3D_ImportBatteryLimit (/ BLKNAME savLayer)
 (setq BLKNAME "CUSTOM_BATTERY LIMIT")
  
 (if (findfile (strcat BLKNAME ".DWG"))
  (progn
   (setq savLayer (getvar "clayer")) ; save current layer
   
   (if (tblsearch "layer" ".STANDARDS")
    (setvar "clayer" ".STANDARDS")
   )
   
   (command "._insert" (strcat BLKNAME "=" BLKNAME) "_scale" "1000" PAUSE "")
   
   (setvar "clayer" savLayer ) ; restore layer
   (prompt "\nBattery Limit Succesfully Imported! ")
   
   (MC3D_SetAllSystemVars)
  ); progn
  (progn
   (vlr-beep-reaction)
   (prompt (strcat "\n" BLKNAME ".dwg is not found."))
  )
 ); if
); AXMC3D_ImportBatteryLimit


0 Likes
Message 6 of 7

komondormrex
Mentor
Mentor

@Domzinator 

hey there,

try changing 3rd line in your code with

(command "-Insert" "CUSTOM_BATTERY LIMIT=CUSTOM_BATTERY LIMIT" "s" "1000" PAUSE "")

and add opening parenthesis at the very beginning.

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@Moshe-A wrote:
....
(command "insert" "custom_battrey limit=c:/library/blocks/custom_battery limit")

....


If the new definition is a drawing file with the same name [plus .dwg] as the existing Block name, then you can end it with the equal sign, which means reach outside for a drawing file with the same name.  That's assuming the drawing is in a folder location where AutoCAD knows to look.  It will ask whether you want to update the definition, so you need to answer that prompt.

(command "insert" "custom_battrey limit=" "_yes" "s" "1000" PAUSE "")

And you presumably need more at the end, for a Y scale factor if not defined for uniform scale, and rotation.  But if you only want to update the definition, and not actually Insert another one, you can just have it cancelled once the definition update has happened.

(command "insert" "custom_battrey limit=" "_yes" nil)

See Help for the -INSERT command.

Kent Cooper, AIA
0 Likes