Jump to content

AEC DWG Version Lisp


ishka

Recommended Posts

I have a code that can check a file to see what kind of DWG version if a file, so when you open a file, it will prompt you if you want to continue knowing the version. This is a great start. However I wanted to rewrite the code to check for what version of Civil 3D the CAD file is open rather than the dwg version. The only way I could find the version was via the AECDWGVERSION command that outputs a long string. So original code is in ESD_AECDWGVERSION. The code i rewrote is in the ESD_AECC3DVERSION.

The issue I have is that the code does not run the command when I open the saved file. Both lisps are attached to my acaddoc lsp.

(if (findfile "ESD_AECDWGVERSION.lsp")(progn (load "ESD_AECDWGVERSION.lsp")(C:ESDDWGVER)))
 (if (findfile "ESD_AECC3DDVERSION.lsp")(progn (load "ESD_AECC3DDVERSION.lsp")(C:ESDC3DVER)))

So the DWG version fires and sees the file and delivers the prompt and the option, while the C3D does not fire. However, I can see they are loaded in the file, since their command can be found and fired from within the file. I just want the C3D version to fire with each saved file I open to give me the option to either go ahead, or close it....

 

ESD_AECDWGVERSION.lsp ESD_AECC3DDVERSION.lsp

Link to comment
Share on other sites

This could be an automation problem,  with the code to execute the lisp immediately following the load. Lisp will initiate the load then move onto the execute. It doesn't wait for the code to load.

 

Try seperating the load and execute

(setq ESD_AECD nil)
.....
.....
(if (findfile "ESD_AECDWGVERSION.lsp")(progn (load "ESD_AECDWGVERSION.lsp")(setq ESD_AECD T)))
.....
.....
(if ESD_AECD (C:ESDDWGVER))

 

Edited by dlanorh
Link to comment
Share on other sites

Well, so this did not change anything much. It performs identically as the one before. So the idea is from what I notice is that the code run ends midway. To explain, if I run the lisp within the file after the file is loaded, it acts as expected. If I run the lisp on opening the file, the code ends the run after the AECDWGVERSION command

 

(defun c:ESDC3DVER()
 
(setq closefile nil)
(if (zerop (getvar 'dwgtitled))
(progn (princ "\nThe current drawing is unsaved."))
(progn
(setvar "cmdecho" 0)
(command "aecdwgversion") This is where the script ends when applied to file open ( Seems that it runs once per session and ends at this location for every dwg I open)
(setq AECVERSION(getvar "lastprompt"))
    (cond
        ( (= AECVERSION "This DWG file was last saved by version 7, 8, 41, 0")
            (progn (setq df (acet-ui-message
                   (strcat "You opened a 2016 Civil 3D CAD File" "\n\nDo you wish to proceed ?")
                   "Warning !!"
                   4
                            )
                    )
                (if    (equal df 6)
                    (progn (setq df (acet-ui-message "Are you sure you wish to proceed ?" "Warning !!" 4))
                (if (equal df 6)
                    (progn (setq df (acet-ui-message "Are you still sure you wish to proceed ?" "Warning !!" 4))
                      (if (not (equal df 6))
                    (setq closefile T)
                      )
                    )
                   (progn (setq closefile T))
                )
                    )
              (progn (setq closefile T))
                )
            )
        )
        ( (= AECVERSION "This DWG file was last saved by version 7, 9, 45, 0")
            (progn (setq df (acet-ui-message
                   (strcat "You opened a 2017 Civil 3D CAD File" "\n\nDo you wish to proceed ?")
                   "Warning !!"
                   4
                            )
                    )
                (if    (equal df 6)
                    (progn (setq df (acet-ui-message "Are you sure you wish to proceed ?" "Warning !!" 4))
                (if (equal df 6)
                    (progn (setq df (acet-ui-message "Are you still sure you wish to proceed ?" "Warning !!" 4))
                      (if (not (equal df 6))
                    (setq closefile T)
                      )
                    )
                   (progn (setq closefile T))
                )
                    )
              (progn (setq closefile T))
                )
            )
        )
        ( (= AECVERSION "This DWG file was last saved by version 8, 0, 53, 0")
            (progn (setq df (acet-ui-message
                   (strcat "You opened a 2018 Civil 3D CAD File" "\n\nDo you wish to proceed ?")
                   "Warning !!"
                   4
                            )
                    )
                (if    (equal df 6)
                    (progn (setq df (acet-ui-message "Are you sure you wish to proceed ?" "Warning !!" 4))
                (if (equal df 6)
                    (progn (setq df (acet-ui-message "Are you still sure you wish to proceed ?" "Warning !!" 4))
                      (if (not (equal df 6))
                    (setq closefile T)
                      )
                    )
                   (progn (setq closefile T))
                )
                    )
              (progn (setq closefile T))
                )
            )
        )
        ( (= AECVERSION "This DWG file was last saved by version 8, 1, 48, 0")
            (progn (setq df (acet-ui-message
                   (strcat "You opened a 2019 Civil 3D CAD File" "\n\nDo you wish to proceed ?")
                   "Warning !!"
                   4
                            )
                    )
                (if    (equal df 6)
                    (progn (setq df (acet-ui-message "Are you sure you wish to proceed ?" "Warning !!" 4))
                (if (equal df 6)
                    (progn (setq df (acet-ui-message "Are you still sure you wish to proceed ?" "Warning !!" 4))
                      (if (not (equal df 6))
                    (setq closefile T)
                      )
                    )
                   (progn (setq closefile T))
                )
                    )
              (progn (setq closefile T))
                )
            )
        )
    )
        (if closefile
         (command "_.close")
        )
    )
    )
(setvar "cmdecho" 1)
  (princ)
) This is where the script ends when firing from within the CAD file ( As expected)

 

So I need the script to run in its entirety and have check the file on open and provide the info and the steps as shown. Otherwise I have to ask the user to run the script once the file is loaded and then proceed.... Just want for the script to check the file before is open for the user, so to force the user to take the action.

 

Link to comment
Share on other sites

The drawing is selected to open.

The lisp fires.

It reaches the command, but the drawing isn't fully open so fails.

 

Try adding a delay before the command call

 

(command "_.delay" 5000) 

 

This will pause the lisp for 5 seconds

Edited by dlanorh
added code
Link to comment
Share on other sites

Thanks for the suggestion. No go on that either.

It seems that the only way it would work, it would be to run the lisp when the file is fully open. So I guess what I would look is a reactor that maybe after the file is opened for 1 minute, the lisp will fire only once, asking the user if he wants to continue since this is a different version of file then the one he edits. I don't know if that is possible, and even if it is, I don't have as much knowledge to code it...

Link to comment
Share on other sites

When is your lisp being called is it the very last lisp called, is it added to acaddoc.lsp etc. There is a load on every dwg open need to do some homework.

 

 

Link to comment
Share on other sites

So, no matter how I spin it, it seems that the Civil 3D check cannot happen unless the file is fully open and the acaddoc.lsp has finished running. And since a command reactor does not allow for a command to be run at the end of another command, then I guess it is safe to think that the only way to achieve its purpose other than at the opening of a file, would be a prompt at save of the file that would make aware the user that the file would be saved in a new version.

Link to comment
Share on other sites

Well , more progress now. I added the lisp at the qsave command. So i undefined the qsave command, then added the check command before the redefined qsave and I got two behaviors. If I execute the qsave command from the command line, it works perfect. If I execute the qsave command via the button in the ribbon, it acts in the same way as when the open case. So I get to assume that the command works perfect from the command line, but as soon as some UI element is used, it does not fully execute as desired. So what is the difference between the running the QSAVE command from line and clicking on the SAVE button? It is the same command, why two different behaviors?

Link to comment
Share on other sites

So looking at this. If I run QSAVE from the button, the ESDC3DVER command does not acts as expected. If I type in at the command line QSAVE and run it, it acts as expected.

 

 

(command "_undefine" "qsave")
(command "_undefine" "_qsave")
(defun C:qsave()
(progn
        (if (not c:ESDC3DVER)(load "ESD_AECC3DVersion.lsp"))
        )
(C:ESDC3DVER)
(command ".qsave")
(alert "\nCompleted Save.")
(princ)
)

(defun C:_qsave()
(progn
        (if (not c:ESDC3DVER)(load "ESD_AECC3DVersion.lsp"))
        )
(C:ESDC3DVER)
(command ".qsave")
(alert "\nCompleted Save.")
(princ)
)

Link to comment
Share on other sites

5 hours ago, ishka said:

So, no matter how I spin it, it seems that the Civil 3D check cannot happen unless the file is fully open and the acaddoc.lsp has finished running. And since a command reactor does not allow for a command to be run at the end of another command, then I guess it is safe to think that the only way to achieve its purpose other than at the opening of a file, would be a prompt at save of the file that would make aware the user that the file would be saved in a new version.

 

You cannot run this lisp from within the acaddoc.lsp file, as it contains (command calls).  Did you try Roy_043 S::STARTUP suggestion HERE

Edited by dlanorh
Link to comment
Share on other sites

To quote Roy_043 link

 

If one of these files defines a function of the special type S::STARTUP, this routine runs immediately after the drawing is fully initialized. As an alternative, the APPLOAD command provides a Startup Suite option that loads the specified applications without the need to edit any files.

Link to comment
Share on other sites

I got it fixed with the help of a Civil 3D user group local user that had to re-write the code to search for the version number in the string, rather than looking at the whole string in the condition. The lastprompt was concatenating the result of the AECDWGVERSION with some other prompt that happened before. So searching in the whatever concatenation the software was providing resulted in a correct output for the lisp on opening the file.

Link to comment
Share on other sites

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...