Jump to content

Recommended Posts

Posted

I use Lee Mac's BAtteV1-4.lsp (which is amazing) all the time to update my titleblock and other block attributes on a drawing set basis. I have created a dynamic block that seems to stop the lisp when the lisp encounters a drawing containing this dynamic block. The dynamic block contains a linear parameter with a scale action that increases the size of some of the objects (including a wipeout).

 

The lisp gets hung up on the drawing containing the block at the command line.

 

Command: (if (and BAtte:SetAttributes (vl-bb-ref 'BAtte:data)) (BAtte:SetAttributes (vl-bb-ref 'BAtte:data)))

Command: (if (vl-bb-ref 'BAtte:dwgcounter) (vl-bb-set 'BAtte:dwgcounter (1+ (vl-bb-ref 'BAtte:dwgcounter)))) 1

Command: _.qsave

Command: _.close

Really want to discard all changes to drawing? _.open

Yes or No, please.

Really want to discard all changes to drawing? *Cancel*

 

See drawing attached. Any ideas how to fix Batte.lsp or block?

PIER.dwg

Posted

I believe the way that AutoCAD closes drawings (or at least, the operations that are performed in the background when a drawing is closed) has changed with more recent versions of AutoCAD. As you can see by the command-line history, my application issues a QSAVE immediately before closing the drawing, and yet AutoCAD still prompts whether or not to discard changes, when there should be no changes to discard...

 

I'll look to release a fix shortly.

Posted

I thought that was a bug, but maybe not.

 

If I close AutoCAD or close all of the drawings with several drawings open and all have been saved, it only asks again to save on the first drawing closed. Knowing Autodesk, they will probably never fix this.

  • 10 months later...
Posted

Has there been a solution for this problem posted?

 

Posted
1 hour ago, bonehead_96 said:

Has there been a solution for this problem posted?

 

I have a new version of this program in the pipeline, but need to work on the documentation before releasing.

Posted

I do not insist, it is only for possible options ...

(if I interfered with the topic - I can delete this message)

If there is no ready solution yet...
Maybe this will help you:

 

ReplaceAtr.png

Posted

At line 1017 of BAtteV1-4.lsp code, I added a second qsave.

"_.qsave _.qsave _.close"

 

It's been working since 05/30/2018.

  • Thanks 1
Posted
14 hours ago, amrichter998 said:

At line 1017 of BAtteV1-4.lsp code, I added a second qsave.

"_.qsave _.qsave _.close"

 

It's been working since 05/30/2018.

 

Many thanks for proposing this alternative solution - I may well implement this in the new version, as it is cleaner than my current solution.

Posted

I wanted to say thanks for the tip too, I changed my hard codes lisps that were using SCRIPT command... Still this fix gives not expected *.bak files (the same as saved dwg) which is not the case with single QSAVE... But then again it works fine and on my A2018... Maybe some kind of possible solution is to make backup folder(s) firstly and then, only then apply double qsaves...

Posted (edited)

Couple of questions still occupy my mind...

1. When script active and performing open, do things, qsave, close on many files, is there a way to be checked if dialog box Discard changes (yes/no) pops up? Something like (if (< 0 (getvar 'cmdactive)) "Y" (command)) inside script file after close line?

2. If answer 1. is no - there is no way of checking pop up, do we have knowledge from which version CAD release this firstly came as an issue... Maybe hard coding for 2 different versions of scr file is possible and only one correct is generated and executed after checking for CAD version currently active...

So my question : From which release this came as a problem and is it still present in newest A2020?

3. Lee, if you have an alternative, can you shed some light, I and I suppose someone else would also be happy to see if your snippet could be still useful without implementing double qsave?

 

For now I have double *.lsp files that calls SCRIPT command and generate 2 different *.scr versions (with double qsave, close and other one with just single qsave, close and blank line at end before next open, do things, qsave, close, blank line)... But this is all for newer releases and I don't know if that blank line is needed if some different version is currently active... Now when I thought once again about this I still think that version with blank line is better solution as it creates correct *.bak files as I mentioned in my previous post... So I am open to hear some opinion or an answer if there is some on my questions and I believe that this problem solved would be proved as useful for some future projects involving scripting without other alternatives like ObjectDBX of VB(A) approaches or even more complex C,C++,C# implementations...

 

Thanks, M.R.

Edited by marko_ribar
Posted (edited)

I just realized that my script was written badly... If everything is correct, CAD now never asks Do you want to discard changes (Yes/No)... So I suppose that I run at the issue user before me had too : "badly written script"... I'll post my code to see that I now used only once QSAVE and it worked very well... Here is my hard coded script inside lisp :

 

;; This is sub function that is used for replacement of block "Can Light" to "RecessedLight" from DWG "RecessedLight.dwg" placed in AutoCAD Support File Search Path
;|
(defun replaceblk ( / oldname newblk newname )
  (setq oldname "Can Light")
  (setq newblk (findfile "RecessedLight.dwg"))
  (setq newname (cadr (fnsplitl newblk)))
  (command "_.rename" "_b" oldname newname)
  (command "_.-insert" (strcat newname "=" newblk) "_non" (list 0.0 0.0 0.0))
  (while (< 0 (getvar 'cmdactive)) (command ""))
  (command "_.erase" "_l" "")
)
|;

(defun mr nil
  (vl-file-copy (strcat (car (fnsplitl adfn)) "oldacaddoc.txt") adfn)
  (vl-file-delete (strcat (car (fnsplitl adfn)) "oldacaddoc.txt"))
  (vl-file-delete scrfn)
  (setq adfn nil scrfn nil)
  (princ)
)

;; This command function (c:runscript) creates "replaceblk.scr" script file that is placed in folder where reside DWG files you want to process through scripting - all DWG files must have block "Can Light" that is to be replaced with block "RecessedLight" as block-DWG "RecessedLight.dwg" that is placed in AutoCAD Support File Search Path
(defun c:runscript ( / path files )
  (alert "After script operation complete type (mr) at command prompt to restore erased acaddoc.lsp file from your support folder...")
  (setq adfn (findfile "acaddoc.lsp"))
  (vl-file-copy adfn (strcat (car (fnsplitl adfn)) "oldacaddoc.txt"))
  (vl-file-delete adfn)
  (setq path (acet-ui-pickdir "Select folder with DWG files to process replace block procedure..."))
  (setq files (vl-directory-files path "*.dwg"))
  (setq scrfn (open (strcat path "\\replaceblk.scr") "w"))
  (foreach filen files
    (write-line "OPEN" scrfn)
    (write-line (strcat path "\\" filen) scrfn)
    (write-line "((lambda ( / oldname newblk newname )(setq oldname \"Can Light\")(setq newblk (findfile \"RecessedLight.dwg\"))(setq newname (cadr (fnsplitl newblk)))(command \"_.rename\" \"_b\" oldname newname)(command \"_.-insert\" (strcat newname \"=\" newblk) \"_non\" (list 0.0 0.0 0.0))(while (/= 4 (getvar 'cmdactive))(command \"\"))(command \"_.erase\" \"_l\" \"\")))" scrfn)
    (write-line "QSAVE" scrfn)
    (write-line "CLOSE" scrfn)
  )
  (close scrfn)
  (vl-cmdf "_.script" (setq scrfn (strcat path "\\replaceblk.scr")))
  (princ)
)

Thanks for no reply, as I figured that something with me was an issue and not CAD...

 

[EDIT : More info about posted code you can find here as also necessary *.dwg files] : https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-to-replace-block-with-dynamic-block/td-p/8672601

 

Regards, M.R.

Edited by marko_ribar
  • 1 year later...
Posted

I am trying to adapt this to replace a block named GARBAGE with a block named TTBLK. I am not as knowledgeable as you are and cannot figure it out as your script is written. Can you assist me with putting the information into your script? My files will be in the folder C:\LISP. Thank you.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...