TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on August 19, 2011, 02:04:43 PM
-
does anyone have any suggestions on what would be the best way via lisp code to do the follow:
lets say you have dwg A opened, you do some work and dont sve and you want to open dwg B but before dwg B can open dwg A is automatically saved and then dwg B can now open
-
A command reactor comes to mind:
(or *cmdreactors*
(setq *cmdreactors* (vlr-command-reactor nil '((:vlr-commandwillstart . strtcmd))))
)
(defun strtcmd (calling-reactor strtcmdinfo /)
(or *adoc* (setq *adoc* (vla-get-activedocument (vlax-get-acad-object))))
(if (and (wcmatch (car strtcmdinfo) "OPEN") (= (getvar 'dwgtitled) 1))
(vla-save *adoc*)
)
)
Note this will not work when "tabbing" through drawings.
-
I thought something like this:
(if (null *save-reactor*)
(setq *save-reactor* (vlr-editor-reactor nil '((:vlr-begindwgopen . savedrawing))))
)
(defun savedrawing ( reactor params )
(if (= 1 (getvar 'DWGTITLED))
(vla-save
(cond
( *activedoc* )
( (setq *activedoc* (vla-get-activedocument (vlax-get-acad-object))) )
)
)
)
(princ)
)
Since a drawing may be opened from Windows Explorer, without using the Open command, but I can't get it to fire :-(
-
I use, simply this :
(defun c:opsave ( / aobj adoc )
(vl-load-com)
(setq aobj (vlax-get-acad-object))
(setq adoc (vla-get-activedocument aobj))
(vla-save adoc)
(vlax-release-object adoc)
(vla-open (vla-get-documents aobj) (getfiled "Open dwg file" "" "dwg" 4) :vlax-false)
(vl-cmdf "close" "")
(princ)
)
-
I use, simply this :
(defun c:opsave ( / aobj adoc )
(vl-load-com)
(setq aobj (vlax-get-acad-object))
(setq adoc (vla-get-activedocument aobj))
(vla-save adoc)
(vlax-release-object adoc)
(vla-open (vla-get-documents aobj) (getfiled "Open dwg file" "" "dwg" 4) :vlax-false)
(vl-cmdf "close" "")
(princ)
)
:whistle:
(vla-open (vla-get-documents aobj) nil :vlax-false)
-
Building on my last post, I'd slightly revise Marko's code:
(defun c:OPSAVE ( / file)
(vl-load-com)
(if (setq file (getfiled "Open dwg file" "" "dwg" 4))
((lambda (acObj)
(vla-save (vla-get-activedocument acObj))
(vla-open (vla-get-documents acObj) file :vlax-false)
(vl-cmdf "close" ""))
(vlax-get-acad-object)))
(princ))
@ Marko - While it is good practice to release vla-objects, there's no need to do so with internal objects such as the acad-object, and activeDocument. Just saying.
-
lets say you have dwg A opened, you do some work and dont sve and you want to open dwg B but before dwg B can open dwg A is automatically saved and then dwg B can now open
FWIW - You could also explore the SDI System Variable (not sure of what version, or vertical you work with?). SDI = 1 the user is prompted for save upon OPEN command.
-
maybe someone can help me get this code modified
i got this code form the augi forums here
http://forums.augi.com/showthread.php?t=27428
it saves your dwg after 10 commands and
I want to use my custom save lisp instead of the VLA-SAVE function
but when i try to put my lisp call in there it comes up as an invalid command
can anyone guide me on how i can get my callout working
(defun C:Vas ()
(vl-load-com)
(setq ASRXN1 (vlr-editor-reactor nil '((:vlr-commandended . ASCOM1)))
ASRXN2 (vlr-lisp-reactor nil '((:vlr-lispWillStart . ASCOM2)))
ASRXN3 (vlr-lisp-reactor nil '((:vlr-lispended . ASCOM3)))
)
)
(defun ASCOM1 (CALL CALLBACK)
(if (not LISPRUN)
(progn
(cond
((= (car CALLBACK) "SAVE")
(setq ASCOUNT 0)
)
((= (car CALLBACK) "QSAVE")
(setq ASCOUNT 0)
)
)
(if (not ASCOUNT)
(setq ASCOUNT 0)
(if (> ASCOUNT 9)
(progn
(setq ASCOUNT 0)
;(vla-save (vla-get-activedocument (vlax-get-acad-object)))
(c:nsave)
; (print "AutoSave")
)
(progn
(setq ASCOUNT (1+ ASCOUNT))
(print ASCOUNT)
)
)
)
)
)
)
(defun ASCOM2 (CALL CALLBACK)
(setq LISPRUN 'T)
)
(defun ASCOM3 (CALL CALLBACK)
(setq LISPRUN nil)
)
-
What is (c:nsave)? If I remember correctly, command calls will error in a reactor.
-
What is (c:nsave)? If I remember correctly, command calls will error in a reactor.
that is a custom lisp call
i modified the code to work for me, however if i use a custom macro this code countdown returns back to 1
anyone have any thoughts on why?
(defun copy_backup_as (/ activedoc docfullname backuppath archivename)
(setq activedoc (vla-get-activedocument (vlax-get-acad-object)))
;;
;;----- Main --------------------------
;;
(if (and (not (= 0 (strlen (setq docfullname (vla-get-fullname activedoc)))))
(setq backuppath "C:\\ACADBACK\\")
(setq archivename (strcat backuppath
(vl-filename-base (vla-get-name activedoc))
".dwg"
)
)
)
(vl-file-copy docfullname archivename)
(alert "Ooooops. Unable to establish ArchiveName.")
)
(prompt (strcat "\nFile Saved..." archivename))
(princ)
)
(defun asave ()
(vl-load-com)
(setq ASRXN1 (vlr-editor-reactor nil '((:vlr-commandended . ASCOM1)))
ASRXN2 (vlr-lisp-reactor nil '((:vlr-lispWillStart . ASCOM2)))
ASRXN3 (vlr-lisp-reactor nil '((:vlr-lispended . ASCOM3)))
)
(princ)
)
(defun ASCOM1 (CALL CALLBACK)
(if (not LISPRUN)
(progn
(cond
((= (car CALLBACK) "SAVE")
(setq ASCOUNT 0)
)
((= (car CALLBACK) "QSAVE")
(setq ASCOUNT 0)
)
)
(if (not ASCOUNT)
(setq ASCOUNT 0)
(if (> ASCOUNT 9)
(progn
(setq ASCOUNT 0)
(vla-save (vla-get-activedocument (vlax-get-acad-object)))
(vl-file-delete (strcat "C:\\ACADBACK\\"
(vla-get-name
(vla-get-activedocument (vlax-get-acad-object))
)
)
)
(copy_backup_as)
(prompt (strcat "\nFile Saved..." (vla-get-fullname (vla-get-activedocument (vlax-get-acad-object)))))
)
(progn
(setq ASCOUNT (1+ ASCOUNT))
(print ASCOUNT)
)
)
)
)
)
)
(defun ASCOM2 (CALL CALLBACK)
(setq LISPRUN 'T)
)
(defun ASCOM3 (CALL CALLBACK)
(setq LISPRUN nil)
)
(asave)
-
I use this vba proggie:
http://www.afralisp.net/visual-basic-for-applications/tutorials/a-better-autosave.php (http://www.afralisp.net/visual-basic-for-applications/tutorials/a-better-autosave.php)
This works by setting a counter that starts when a command is called - it then resets on the user set interval/time. Sometimes in a hurry you forget to save the drawing you've worked on...this way you'll always lose only the last 10mins of your work :mrgreen:
The code needed to be modified though; I'll post the .dvb file later tonight.
Perhaps someone here can also expand it to include an error check; for say when you open a read only drawing or the location of the save is write protected (thick CD).
-
heres the modded vba code:
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
Dim OldTime
Dim NewTime
Select Case CommandName
'trigger when user selects
Case "LINE", "PLINE", "DDEDIT", "DIMLINEAR", "COPY", "MOVE", "ZOOM"
'get the time now
NewTime = (Hour(Time) * 60) + Minute(Time)
'get the time stored in USERI2
OldTime = ThisDrawing.GetVariable("Useri2")
'If the time has not been set
If OldTime = 0 Then
'set the time
ThisDrawing.SetVariable ("Useri2"), NewTime
'then end
End
End If
'if the difference is greater that 15 minutes
If (NewTime - OldTime) > 5 Then
'save the drawing
ThisDrawing.Save
'and then reset Useri2
ThisDrawing.SetVariable ("Useri2"), NewTime
End If
'end of the Select
End Select
End
End Sub
Private Sub AcadDocument_BeginSave(ByVal FileName As String)
End Sub
also attached the compiled dvb