Author Topic: Stop opening with wrong version of Civil 3D  (Read 7263 times)

0 Members and 1 Guest are viewing this topic.

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
Stop opening with wrong version of Civil 3D
« on: July 15, 2013, 12:07:41 PM »
I'm trying to stop a drawing from being opened with the wrong version of Civil 3D. All I want to do is abort the open process if the file path is wrong and notify the user to use C3D 2011 instead.

I'm attempting to utilize reactors and specifically :vlr-beginDWGOpen but it doesn't seem to be firing ever. For that matter, neither is :vlr-endDWGOpen. I think my code isn't the issue because :vlr-beginClose is working :-/

It should be noted ... my lisp skills are almost non-existent ... I do not know what I am doing.

This is not working in ACADDOC.lsp

(vl-load-com)
;--------------------------------------------------------------------
(defun HASD_LoadReactors( / )
  (vlr-dwg-reactor nil '(
    (:vlr-beginClose . HASD_VersionCheck)
    (:vlr-beginDwgOpen . HASD_VersionCheck)
    (:vlr-endDwgOpen . HASD_VersionCheck)
    (:vlr-beginSave . beginSaveCallback)
    (:vlr-saveComplete . saveCompleteCallback))))

(HASD_LoadReactors)
;--------------------------------------------------------------------
; read list of 2014 Paths
(defun HASD_VersionCheck (ro args /)
  (alert "We are using a reactor now ...")
)
Donald Broussard
Fusion Engineering and Technology

BlackBox

  • King Gator
  • Posts: 3770
Re: Stop opening with wrong version of Civil 3D
« Reply #1 on: July 15, 2013, 06:07:48 PM »
Welcome to TheSwamp, and congrats on your first post! :beer:



Firstly, reactors are usually something that even adept LISP developers can struggle with, so kudos for jumping into the deep end!

LISP is a Document (Drawing) level language, and needs to be loaded into each-and-every-single-Document before it (the code) can be evaluated.

That said, presuming you're loading your code via AcadDoc.lsp (which is a user-defined file that does not come with AutoCAD products OOTB, but is loaded automagically if found with one's SFSP), the source-code itself is being loaded _after_ the Document has already been opened in the database.



Here's a quick demonstration using an AcadDoc.lsp file that contains this code:
Code - Auto/Visual Lisp: [Select]
  1. (prompt "\n... AcadDoc.lsp loaded. ")
  2.  

... And here's the resultant command line output using MgdDbg showing Document Manager Events:
Code - Auto/Visual Lisp: [Select]
  1. [Doc Mgr Event] : Document Create Started   :
  2. [Doc Mgr Event] : Document Lock Mode Will Change :
  3. [Doc Mgr Event] : Document Lock Mode Changed :
  4. [Doc Mgr Event] : Document To Be Deactivated : Drawing1.dwgRegenerating model.
  5. [Doc Mgr Event] : Document Activation Changed : True
  6. [Doc Mgr Event] : Document Created          : Drawing7.dwg
  7. [Doc Mgr Event] : Document Activated        : Drawing7.dwg
  8. [Doc Mgr Event] : Document Became Current   : Drawing7.dwg
  9. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  10. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  11. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  12. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  13. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  14. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  15. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  16. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  17. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  18. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  19. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  20. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  21. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  22. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  23. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  24. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  25. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  26. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  27. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  28. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  29. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  30. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  31. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  32. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  33. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  34. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  35. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  36. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  37. AutoCAD menu utilities loaded.
  38. ... AcadDoc.lsp loaded.
  39. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  40. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  41. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  42. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  43. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  44. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  45. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  46. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  47. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  48. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  49. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  50. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  51. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  52. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  53. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  54. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  55. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  56. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  57. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  58. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  59. [Doc Mgr Event] : Document Activation Changed : False
  60. [Doc Mgr Event] : Document Activation Changed : True
  61. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  62. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  63. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  64. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  65. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  66. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  67. Command: _ai_selall
  68. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  69. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  70. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  71. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  72. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  73. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  74. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  75. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  76. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  77. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwgSelecting objects...
  78. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  79. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  80. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  81. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  82. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  83. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  84. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  85. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  86. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  87. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  88. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  89. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  90. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  91. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  92. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  93. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwgdone.
  94. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  95. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  96. [Doc Mgr Event] : Document Lock Mode Will Change : Drawing7.dwg
  97. [Doc Mgr Event] : Document Lock Mode Changed : Drawing7.dwg
  98.  



In order to properly catch the event(s) you're after, you'll have to resort to being reactionary during AcadDoc.lsp load (i.e., closing the Document after the fact), or step up into the .NET API with an assembly that implements the IExtensionApplication.Initialize() Method.
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Stop opening with wrong version of Civil 3D
« Reply #2 on: July 15, 2013, 06:13:11 PM »
Also worthy of note, here's more on the startup sequence (i.e., which file is loaded when, etc.):


<snip>

Consider the load order at startup:
linky

Quote
A. CUI files loaded:
1. Enterprise
2. Main
3. Partials to Main
4. Partials to Enterprise

B. acad*.* files loaded:
1. Files listed in acad.rx
2. acad2009.lsp
3. acad.lsp  <--
4. acad2009doc.lsp
5. acaddoc.lsp
6. acad.dvb

C. CUI-associated MNL and LSP files loaded:
1. Enterprise named MNL
2. Enterprise loaded LSP and MNL
3. Main named MNL
4. Main loaded LSP and MNL
5. Partials to Main named MNLs
6. Partials to Main loaded LSPs and MNLs
7. Partials to Enterprise named MNLs
8. Partials to Enterprise loaded LSPs and MNLs

D. Startup suite files loaded

E. Startup routines run:
1. AcadStartup() called (AutoCAD startup)
2. AcadDocument_Activate() called (Drawing startup)
3. (S::STARTUP) called
4. SCR loaded from /b switch

Edit: ^^ Corrected
"How we think determines what we do, and what we do determines what we get."

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
Re: Stop opening with wrong version of Civil 3D
« Reply #3 on: July 15, 2013, 07:58:40 PM »
So ... that makes sense, the drawing is already opened when ACADDOC.lsp executes. Any recommendations on a way to accomplish my goal? Can I set it so the drawing cannot be saved? then I could just notify the user...

dot net is going to be too large a leap at this point :o(
Donald Broussard
Fusion Engineering and Technology

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: Stop opening with wrong version of Civil 3D
« Reply #4 on: July 16, 2013, 04:03:14 AM »
Can't you just show a message and leave it to the user to follow the proper work process? If you really want to block the open/save actions you better deinstall the wrong Civil3D versions :-)
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Stop opening with wrong version of Civil 3D
« Reply #5 on: July 16, 2013, 07:31:10 AM »
When we upgraded from 2009 to 2011, we had an issue with some old projects we didn't want moved to 11 since they were basically finished and we didn't want to screw up any xrefing, etc.
I put this at the start of the acaddoc.lsp file:

Code: [Select]
;; check if user is trying to open a 2009 saved file in 2011
((lambda (/ foo)
   (defun foo (/ file header)
     (setq file (open (strcat (getvar 'dwgprefix) (getvar 'dwgname)) "R"))
     (setq header (substr (read-line file) 1 6))
     (close file)
     header
   )

   (if (and (not (wcmatch (strcase (getvar 'dwgname)) "DRAWING*"))
            (equal (cons (foo) (atof (getvar 'acadver))) '("AC1021" . 18.1))
       )
     (if (eq 6
             (acet-ui-message
               "Are you sure you want to open a 2009 saved DWG in 2011?"
               "Be sure you don't screw up a drawing!!"
               308
             )
         )
       (alert "Alright, but you have been warned!")
       (progn (command "_.close") (while (eq 1 (logand 1 (getvar 'cmdactive))) (command "_Y")))
     )
   )
 )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
Re: Stop opening with wrong version of Civil 3D
« Reply #6 on: July 16, 2013, 08:56:08 AM »
@huiz - I wish it were that simple, really I do! A project isn't limited to personnel in our office or in our firm for that matter. Limitations of Civil 3D and backwards compatibility is a very ugly issue.

@alanjt - I'll give that a try ...
Donald Broussard
Fusion Engineering and Technology

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: Stop opening with wrong version of Civil 3D
« Reply #7 on: July 16, 2013, 09:51:59 AM »
If you need to do projects in a certain version because of sharing with externals, you probably can put the Civil3D version in the project map name. I.e. "Project X (2009)".

You have to deal with people, the harder you try to force them do the right thing, the harder they try to break the system :-)
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Stop opening with wrong version of Civil 3D
« Reply #8 on: July 16, 2013, 09:56:54 AM »
@alanjt - I'll give that a try ...
It's far from perfect, but it served it's purpose and saved some headaches.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Stop opening with wrong version of Civil 3D
« Reply #9 on: July 16, 2013, 10:02:32 AM »
@alanjt - I'll give that a try ...
It's far from perfect, but it served it's purpose and saved some headaches.

It's a good demonstration of the reactionary nature required, given LISP's limitation(s), and the OP's request.

Cheers
"How we think determines what we do, and what we do determines what we get."

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
Re: Stop opening with wrong version of Civil 3D
« Reply #10 on: July 18, 2013, 11:31:51 AM »
I appears this is going to work in ACADDOC.lsp

(defun-q S::Startup ()

   ... a bunch of code

;if version is wrong, close the drawing
(command "vbastmt" "activedocument.close false")
)
Donald Broussard
Fusion Engineering and Technology

BlackBox

  • King Gator
  • Posts: 3770
Re: Stop opening with wrong version of Civil 3D
« Reply #11 on: July 18, 2013, 12:17:26 PM »
I appears this is going to work in ACADDOC.lsp

(defun-q S::Startup ()

   ... a bunch of code

;if version is wrong, close the drawing
(command "vbastmt" "activedocument.close false")
)

By appending your check to S::Startup (the second to last item in the startup sequence), you may be unnecessarily performing any/all action, loading of code, etc. prior to that... Why not instead simply make it the first thing done at the top of AcadDoc.lsp?  :?

Cheers
"How we think determines what we do, and what we do determines what we get."

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
Re: Stop opening with wrong version of Civil 3D
« Reply #12 on: July 22, 2013, 05:42:58 PM »
I tried, unsuccessfully. AutoCAD and Civil 3D 2014 crash with a fatal error if I try to close the drawing during normal execution of ACADDOC.LSP.

Moving the code to S::Startup worked around the limitation (or bug).

As always I appreciate your help and suggestions ... I am open to anymore you might have!



Donald Broussard
Fusion Engineering and Technology