Author Topic: re-define existing block with script  (Read 1303 times)

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Guest
re-define existing block with script
« on: April 10, 2018, 01:22:59 PM »
I have a lisp routine that re-defines existing blocks in the dwg:
Code - Auto/Visual Lisp: [Select]
  1. (command ".-insert" (strcat blkname "=" filename) "Y")(command)

It works fine when called from lisp, but when I try to run it within a script file, I think the (command) is canceling the running script.
Any ideas how to get this to work in both situations?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: re-define existing block with script
« Reply #1 on: April 10, 2018, 01:29:31 PM »
Try:
Code - Auto/Visual Lisp: [Select]
  1. (command ".-insert" (strcat blkname "=" filename) nil)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: re-define existing block with script
« Reply #2 on: April 10, 2018, 01:41:51 PM »
I believe any form of cancelling a command will interrupt the processing of a Script - instead, you may need to use something like:

Code - Auto/Visual Lisp: [Select]
  1. (command "_.-insert" (strcat blkname "=" filename) "_Y" "_S" "1" "_R" "0" "_non" "0,0")

(With additional checks to ensure that it is in fact the block that will be deleted by the entdel expression)

BazzaCAD

  • Guest
Re: re-define existing block with script
« Reply #3 on: April 10, 2018, 02:27:30 PM »
Thanks Lee, that's pretty much the direction I was already going.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: re-define existing block with script
« Reply #4 on: April 10, 2018, 04:29:59 PM »
Guess you could do something like this too:

Code - Auto/Visual Lisp: [Select]
  1. (defun _updateblock (dwg / b ms)
  2.   ;; Must provide full path to update definition
  3.   (and (findfile dwg)
  4.        (setq b (vla-insertblock ms (vlax-3d-point 0 0) dwg 1. 1. 1. 0.))
  5.        (vl-catch-all-apply 'vla-delete (list b))
  6.   )
  7. )
  8. ;; (_updateblock "G:\\Ron\\123.dwg")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC