Author Topic: Reactor for logging, file path recognition?  (Read 1910 times)

0 Members and 1 Guest are viewing this topic.

KewlToyZ

  • Guest
Reactor for logging, file path recognition?
« on: March 17, 2009, 03:24:07 PM »
I was reading through the methods on these posts:
This reactor was pretty slick by Jurg Menzi:
http://www.theswamp.org/index.php?topic=5446.0

I'm trying to write my log dynamically to the folder the current file is open in.
The problem is I am using the mdiTab17.arx application for multiple document tabs.
If I try to reference DWGPREFIX it only recognizes the path of the default Drawing1.dwg which is of course %UserProfile%\My Documents folder if it isn't saved from when cad first opened its default template file.

Whatever the first drawing of the AutoCAD session is opened from, that becomes the default for DWGPREFIX for all other files opened in that session. Here is the snippet I added to the reactor Jurg Menzi posted
Code: [Select]
; - Write to log function
(defun MeWriteToLog ()
 (setq FormatDate (rtos (getvar "CDATE") 2 6)
       Year (substr FormatDate 3 2)
       Month (substr FormatDate 5 2)
       Day (substr FormatDate 7 2)
       Hour (substr FormatDate 10 2)
       Minutes (substr FormatDate 12 2)
 )
 (setq DirPath (getvar "DWGPREFIX"))
 (if (setq LogPath (strcat DirPath "Z_User_Drawing.log"))
     (progn
        (setq FILEDESC (open LogPath "a"))
          (write-line
             (strcat Month "/" Day "/" Year " - " Hour ":" Minutes " " " [ User ID: " (getvar "LOGINNAME") " ] => " (getvar "DWGNAME")
          )
          FILEDESC
     )
    (close FILEDESC)
    (setq FILEDESC nil)
   
  )
)
 
 (alert (strcat
         "Drawing name:\t\t" Me:DwgNme
         "\nTotal command time:\t" (MeCalcTime Me:CmdTim)
         "\nTotal commands called:\t" (itoa Me:CmdCnt)
         "\nLog File Path:\t\t " LogPath
         
        )
 )
 (setq DirPath nil)
 (princ)

With the reactor I wasn't sure how else to get the path of the current files folder of the open files being closed?
Any hints would be appreciated  :|


KewlToyZ

  • Guest
Re: Reactor for logging, file path recognition?
« Reply #1 on: March 17, 2009, 04:17:58 PM »
OK I figured why kill myself, use the file name for the log name.

Code: [Select]
; - Write to log function
(defun MeWriteToLog ()
 (setq FormatDate (rtos (getvar "CDATE") 2 6)
       Year (substr FormatDate 3 2)
       Month (substr FormatDate 5 2)
       Day (substr FormatDate 7 2)
       Hour (substr FormatDate 10 2)
       Minutes (substr FormatDate 12 2)
 )
 (setq DirPath nil)
 ;(setq DirPath (vla-get-Path Obj))    ;Me:DwgPath
 (setq DirPath Me:DwgNme)
 ;(setq DirPath (getvar "DWGPREFIX"))
 (if (setq LogPath (strcat DirPath ".log"))
     (progn
        (setq FILEDESC (open LogPath "a"))
          (write-line
             (strcat Month "/" Day "/" Year " - " Hour ":" Minutes " " " [ User ID: " (getvar "LOGINNAME") " ] => " (getvar "DWGNAME")
          )
          FILEDESC
     )
    (close FILEDESC)
    (setq FILEDESC nil)
   
  )
)
 
 (alert (strcat
         "Drawing name:\t\t" Me:DwgNme
         "\nTotal command time:\t" (MeCalcTime Me:CmdTim)
         "\nTotal commands called:\t" (itoa Me:CmdCnt)
         "\nLog File Path:\t\t " LogPath       
        )
 )
 (princ)
)

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Reactor for logging, file path recognition?
« Reply #2 on: March 17, 2009, 04:53:00 PM »
you can use this to shorten your code a bit
Code: [Select]
(strcat (menucmd "M=$(edtime,$(getvar,date),MO/DD/YY - HH:MM)")
" "
" [ User ID: "
(getvar "LOGINNAME")
" ] => "
(getvar "DWGNAME")
)

KewlToyZ

  • Guest
Re: Reactor for logging, file path recognition?
« Reply #3 on: March 18, 2009, 12:53:05 PM »
Thanks Vovka.
I was not sure if Menu commands would act any slower in response or not.

I am running into a problem with the system overall as a reactor though.
If I open drawings from inside AutoCAD it works fine.
If I select multiple files to open it is fine.
If I have AutoCAD closed, select *.dwg files in windows explorer to open, I get an error alert.

Crazy looking error too....
It still opens the rest of the files without issue but still a problem for the first file.

Not an issue if AutoCAD is already running either.

KewlToyZ

  • Guest
Re: Reactor for logging, file path recognition?
« Reply #4 on: March 19, 2009, 03:33:27 PM »
Found the cause of the access error and why I was having trouble with getvar.... forgot the '
Before the getvar, should have used (getvar 'DWGPREFIX)

Ended up using a different approach to centralize items but the deployment issue has another obstacle.
I want to use a parse of the dwgprefix as the file name and I can't seem to get the right combo.

Code: [Select]
;=============================================================================================== Begin writing the log
;
; - Write to log function
(defun MeWriteToLog ()
 (setq FormatDate (rtos (getvar "CDATE") 2 6)
       Year (substr FormatDate 3 2)
       Month (substr FormatDate 5 2)
       Day (substr FormatDate 7 2)
       Hour (substr FormatDate 10 2)
       Minutes (substr FormatDate 12 2)
 )
 ;(setq DirPath nil)

 ;(setq DirPath "N:\\IT\\")
 (setq DirPath "X:\\Z\\Z00001.00\\Logs\\")

 (if (setq LogPath (strcat DirPath (getvar 'DWGNAME) ".log"))
     (progn
        (setq FILEDESC (open LogPath "a"))
          (write-line
             (strcat Month "/" Day "/" Year " - " Hour ":" Minutes " "  " [User_ID: " (getvar "LOGINNAME") "] " " Total commands called: (" (itoa Me:CmdCnt) ") => " (getvar "DWGNAME")
          )
          FILEDESC
     )
    (close FILEDESC)
    (setq FILEDESC nil)
   
  )
)
;=================================================================== Prompting the log routine key variables
 ;(prompt (strcat "\n   Log File Path: [ " LogPath " ] " ))
 ;(prompt (strcat "\n   Log File Name: [ " Me:DwgNme " ] " ))
 ;(prompt (strcat "\n     Folder Path: [ " MyPath " ] " ))
 ;(prompt (strcat "\n   Command Count: [ " (itoa Me:CmdCnt) " ] " ))
 ;(prompt (strcat "\n Total Work time: [ " (MeCalcTime Me:CmdTim) " ] " ))
 ;(prompt "\n  Cleaning up for close....... \n  Goodbye.............:)")
;=================================================================== End Prompting the log routine key variables
 
 
;=================================================================== Begin Debugging the log routine (normally turned off
(alert (strcat
          "Drawing name:\t\t" Me:DwgNme
          "\nTotal command time:\t" (MeCalcTime Me:CmdTim)
          "\nTotal commands called:\t" (itoa Me:CmdCnt)
          "\n  Log File Path:\t\t [ " LogPath  " ] "
          "\n  My Path:\t\t\t [ " DirPath  " ] "
         )
 )
;=================================================================== End of Debugging the log routine
 (princ)
) ; End of MeWriteToLog

;=============================================================================================== End writing the log

I was trying to strip the beginning of the full path at first but couldn't get this line formatted correctly:
Code: [Select]
(setq MyPath (vl-string-left-trim "X:" Me:DwgNme)) Where Me:DwgName would be (example) X:\X\X0001.00\CADD\FILE\DrawingName.dwg

Truthfully I was wondering what the string formatting would be to parse the \'s & :'s from the string?


KewlToyZ

  • Guest
Re: Reactor for logging, file path recognition?
« Reply #5 on: March 19, 2009, 04:23:32 PM »
Nevermind found my way around with the translation.
Thanks though  :angel:

Code: [Select]
;=============================================================================================== Begin writing the log
;
; - Write to log function
(defun MeWriteToLog ()
 (setq FormatDate (rtos (getvar "CDATE") 2 6)
       Year (substr FormatDate 3 2)
       Month (substr FormatDate 5 2)
       Day (substr FormatDate 7 2)
       Hour (substr FormatDate 10 2)
       Minutes (substr FormatDate 12 2)
 )
 ; (setq DirPath nil)
 ; (setq TransThing (vl-string-translate ":\\" "--" (getvar 'DWGPREFIX) ))
  (setq TransThing (vl-string-translate ":\\" "--" Me:DwgNme ))
  ;(setq OddName (substr (getvar 'DWGPREFIX) 4))
 ; (setq DirPath "N:\\IT\\")
 (setq DirPath "J:\\Z\\Z00001.00\\Logs\\")

 ;(if (setq LogPath (strcat DirPath (getvar 'DWGNAME) ".log"))
 (if (setq LogPath (strcat DirPath TransThing ".log"))
 
     (progn
        (setq FILEDESC (open LogPath "a"))
          (write-line
             (strcat Month "/" Day "/" Year " - " Hour ":" Minutes " "  " [User_ID: " (getvar "LOGINNAME") "] " " Total commands called: (" (itoa Me:CmdCnt) ") => " (getvar "DWGNAME")
          )
          FILEDESC
     )
    (close FILEDESC)
    (setq FILEDESC nil)
   
  )
)
;=================================================================== Prompting the log routine key variables
 ;(prompt (strcat "\n   Log File Path: [ " LogPath " ] " ))
 ;(prompt (strcat "\n   Log File Name: [ " Me:DwgNme " ] " ))
 ;(prompt (strcat "\n     Folder Path: [ " MyPath " ] " ))
 ;(prompt (strcat "\n   Command Count: [ " (itoa Me:CmdCnt) " ] " ))
 ;(prompt (strcat "\n Total Work time: [ " (MeCalcTime Me:CmdTim) " ] " ))
 ;(prompt "\n  Cleaning up for close....... \n  Goodbye.............:)")
;=================================================================== End Prompting the log routine key variables
 
 
;=================================================================== Begin Debugging the log routine (normally turned off)
(alert (strcat
          "Drawing name:\t\t" Me:DwgNme
          "\nTotal command time:\t" (MeCalcTime Me:CmdTim)
          "\nTotal commands called:\t" (itoa Me:CmdCnt)
          "\n  Log File Path:\t\t [ " LogPath  " ] "
          "\n  My Path:\t\t\t [ " DirPath  " ] "
          ;"\n  Odd Name:\t\t\t [ " OddName  " ] "
          "\n  Trans :\t\t\t [ " TransThing  " ] "
         )
 )
;=================================================================== End of Debugging the log routine
 (princ)
) ; End of MeWriteToLog

;=============================================================================================== End writing the log