TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: BazzaCAD on April 10, 2018, 01:22:59 PM

Title: re-define existing block with script
Post by: BazzaCAD 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?
Title: Re: re-define existing block with script
Post by: ronjonp on April 10, 2018, 01:29:31 PM
Try:
Code - Auto/Visual Lisp: [Select]
  1. (command ".-insert" (strcat blkname "=" filename) nil)
Title: Re: re-define existing block with script
Post by: Lee Mac 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)
Title: Re: re-define existing block with script
Post by: BazzaCAD on April 10, 2018, 02:27:30 PM
Thanks Lee, that's pretty much the direction I was already going.
Title: Re: re-define existing block with script
Post by: ronjonp 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")