Author Topic: SSV (Save as Same Version)  (Read 3489 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
SSV (Save as Same Version)
« on: August 12, 2013, 02:59:56 PM »
Hi all,..

here is a little routine allowing users to prevent saving in another DWG format.
have a good day all.

Code: [Select]

;;SSV SAVE SAME VERSION v.1 ;;
;;By: Andrea Andreetti 2013-06-01 ;;
;;Allow to save drawing in same version as it was opened. ;;


(defun SSV (_SSVCR / versionlist odn FL NewDefault drawingname) ; Save Same Version
 
  (if (findfile (setq drawingname (strcat (getvar 'dwgprefix) (getvar 'dwgname))))
    (progn
      (setq versionlist '(("AC1014" 8) ("AC1015" 12) ("AC1018" 24) ("AC1021" 36) ("AC1024" 48) ("AC1027" 60)))
      (setq odn (open drawingname "r"))
      (setq FL (read-line odn))
      (close odn)

      (if (and
    (setq NewDefault (cadr (assoc (substr FL 1 6) versionlist)))
    (/= _SSVCR (itoa NewDefault))
  )
(setenv "DefaultFormatForSave" (itoa NewDefault))
      )
    )
  )
)



(defun *SSV_OnSave_Reactor_Start* (call-reactor sci /)
  (if (eq (strcase (car sci)) "QSAVE")     
      (SSV (setq SSVCR (getenv "DefaultFormatForSave")))
  )
  (princ)
)


(defun *SSV_OnSave_Reactor_Ended* (call-reactor sci /)
  (if (eq (strcase (car sci)) "QSAVE")
    (progn     
      (if SSVCR (progn
  (setenv "DefaultFormatForSave" SSVCR)
  (setq SSVCR nil)
)
      )
    )
  )
  (princ)
)



;;command WillStart
(if SSV_OnSave_Reactor_Start
    (progn (vlr-remove SSV_OnSave_Reactor_Start)
           (setq SSV_OnSave_Reactor_Start nil)
    )
  )
(setq SSV_OnSave_Reactor_Start
         (vlr-command-reactor nil
                              '((:vlr-commandWillStart . *SSV_OnSave_Reactor_Start*))
         )
  )

;;command Ended
(if SSV_OnSave_Reactor_Ended
    (progn (vlr-remove SSV_OnSave_Reactor_Ended)
           (setq SSV_OnSave_Reactor_Ended nil)
    )
  )
(setq SSV_OnSave_Reactor_Ended
         (vlr-command-reactor nil
                              '((:vlr-commandended . *SSV_OnSave_Reactor_Ended*))
         )
  ) 




;|refrrences

MC0.0 - DWG from Rel. 1.1
AC1.2 - DWG from Rel. 1.2
AC1.4 - DWG from Rel. 1.4
AC1.50 - DWG from Rel. 2.0
AC2.10 - DWG from Rel. 2.10
AC1002 - DWG from Rel. 2.5
AC1003 - DWG from Rel. 2.6
AC1004 - DWG from Rel.9
AC1006 - DWG from Rel.10
AC1009 - DWG from Rel.11/12 (or LT R1/R2)
AC1012 - DWG from Rel.13 (or LT95)
AC1014 8 - DWG from Rel.14, 14.01 (or LT97/LT98)
AC1015 12 - DWG from AutoCAD 2000/2000i/2002 (or LT, Map or relative Desktop version)
AC1018 24 - DWG from AutoCAD 2004/2005/2006 (or other product in the "2004", "2005" or "2006" family)
AC1021 36 - DWG from AutoCAD 2007/2008/2009 (or other product of the "2007", "2008" and "2009" families)
AC1024 48 - DWG from AutoCAD 2010/2011/2012 (or other product of the "2010", "2011" and "2012" families)
AC1027 60 - DWG from AutoCAD 2013/2014 (or other product of the "2013" "2014" family)


(vla-get-SaveAsType
    (vla-get-OpenSave
      (vla-get-preferences
(vlax-get-acad-object)))
)

(getenv "DefaultFormatForSave")

|;

« Last Edit: August 14, 2013, 01:14:42 PM by Andrea »
Keep smile...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SSV (Save as Same Version)
« Reply #1 on: August 13, 2013, 05:06:06 AM »
Maybe there is a copy-paste error here:
Code: [Select]
(setq SSV_OnSave_Reactor_Ended
  (vlr-command-reactor
    nil
    '((:vlr-commandWillStart . *SSV_OnSave_Reactor_Ended*)) ; <<< error?
  )
)

It seems wise to also handle :vlr-commandcancelled and :vlr-commandfailed?
« Last Edit: August 13, 2013, 05:13:52 AM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SSV (Save as Same Version)
« Reply #2 on: August 13, 2013, 05:09:42 AM »
... Although it is unlikely that QSAVE is ever cancelled.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: SSV (Save as Same Version)
« Reply #3 on: August 13, 2013, 06:38:56 AM »
An original idea Andrea - thank you for sharing  :-)

You are welcome to use ideas from this simple function to account for other drawing formats, such as DXF  :-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: SSV (Save as Same Version)
« Reply #4 on: August 13, 2013, 09:24:18 AM »
Maybe there is a copy-paste error here:
Code: [Select]
(setq SSV_OnSave_Reactor_Ended
  (vlr-command-reactor
    nil
    '((:vlr-commandWillStart . *SSV_OnSave_Reactor_Ended*)) ; <<< error?
  )
)

It seems wise to also handle :vlr-commandcancelled and :vlr-commandfailed?

Hi Roy,..thank you for your feedback..
may you explain what the error is ?

vlr-commandfailed will be added.
thank you.
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: SSV (Save as Same Version)
« Reply #5 on: August 13, 2013, 09:31:56 AM »
An original idea Andrea - thank you for sharing  :-)

You are welcome to use ideas from this simple function to account for other drawing formats, such as DXF  :-)

thanks for the Link Lee.. :)

I'm using..
Code: [Select]
(vla-get-SaveAsType
    (vla-get-OpenSave
      (vla-get-preferences
(vlax-get-acad-object)))
)

(getenv "DefaultFormatForSave")

who work also for DXF. :P

by the way,...you'r website is one of the best reference site.
nice work Lee.
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: SSV (Save as Same Version)
« Reply #6 on: August 13, 2013, 09:40:58 AM »
I'm using..
Code: [Select]
...
who work also for DXF. :P

Sorry, I meant to determine the current version of the active drawing file, whether it be dwg/dws/dwt/dxf  :wink:

by the way,...your website is one of the best reference site.
nice work Lee.

Many thanks Andrea!
That means a great deal coming from you, I appreciate your kind feedback  :-)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SSV (Save as Same Version)
« Reply #7 on: August 14, 2013, 03:00:25 AM »
... may you explain what the error is ?
may you explain what the error is ?

Code: [Select]
(setq SSV_OnSave_Reactor_Ended
  (vlr-command-reactor
    nil
    '((:vlr-commandWillStart . *SSV_OnSave_Reactor_Ended*)) ; <<< Error?: should be :vlr-commandended
  )
)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: SSV (Save as Same Version)
« Reply #8 on: August 14, 2013, 01:14:11 PM »
... may you explain what the error is ?
may you explain what the error is ?

Code: [Select]
(setq SSV_OnSave_Reactor_Ended
  (vlr-command-reactor
    nil
    '((:vlr-commandWillStart . *SSV_OnSave_Reactor_Ended*)) ; <<< Error?: should be :vlr-commandended
  )
)

Oops....:)
thank you.
(bad cut&paste)
Keep smile...