Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Prompt to update through Lisp

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
JCprog
703 Views, 14 Replies

Prompt to update through Lisp

Hello Everyone!!!!!


A dozen of computers have a Partial cuix stored locally (C:\My cui) and in the network (N:\Network). These computers gets there cui updated through a batch file (.bat) that just simply copies the files from the network to (C:\My cui). All computers needs to be independent and not tied to the network thats why I set it this way.

Need help on a lisp that will compare (C:\My cui\updatelog.txt) & (N:\Network\updatelog.txt). If the txt files dont match prompt the user with a popup asking if he wants to update (yes\no) if yes then run batch (C;\My cui\run.bat) file otherwise cancel.


Thanks in advanceSmiley Happy

14 REPLIES 14
Message 2 of 15
dgorsman
in reply to: JCprog

- connect to each file

- read the contents of each file into a list of strings

- shortcut test: compare number of lines

- for each line in one list (shouldn't matter which one)

   - if the contents of the matching index of the other list don't match the current line

      - set a flag

      - shortcut the loop

- next list entry

 

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 3 of 15
BlackBox_
in reply to: JCprog

You might consider the vl-File-Systime function:

 

(vl-load-com)

(defun _FilesAreUpToDate (local network)
  (equal (vl-file-systime local) (vl-file-systime network))
)

 



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

Message 4 of 15
Shneuph
in reply to: BlackBox_

My company started using Dropbox.  Putting CAD support files in a Dropbox (or other cloud hosting service) folder and mapping it to a drive letter is extremely useful for managing CAD standards while making them available to users who are not connected to your netowrok.  The files all live on each workstation and dropbox handles all the syncing through any internet connection.  You may consider implementing something similar.  Our version does not have permission management but I believe Dropbox released a professional version last Nov. that does allow read/write permission settings.

Message 5 of 15
BlackBox_
in reply to: Shneuph


@Shneuph wrote:

My company started using Dropbox.  Putting CAD support files in a Dropbox (or other cloud hosting service) folder and mapping it to a drive letter is extremely useful for managing CAD standards while making them available to users who are not connected to your netowrok.  The files all live on each workstation and dropbox handles all the syncing through any internet connection.  You may consider implementing something similar.  Our version does not have permission management but I believe Dropbox released a professional version last Nov. that does allow read/write permission settings.


I agree that such file-sync services are useful; just be mindful that read-only files (those that are currently open in AutoCAD; CUIx, DLL, etc.) are not able to be overwritten... Thus, an 'update' may not necessarily be performed automagically... And may still require similar mechanism by which to notify user, and prompt to update now, etc.

 

Cheers

 



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

Message 6 of 15
JCprog
in reply to: BlackBox_

Hello BlackBox, 

 

Thanks for the reply! I took a stab at it and returns "Too few arguments". this is just beyond me.

(vl-load-com)

(defun c:FilesAreUpToDate (local network)
  (equal (vl-file-systime "C:/folder1/local.txt") 
	(vl-file-systime C:/folder1/network.txt))
)

 I tend to:

1. compare the files first (the code above)

2. prompt user to update if files not equal

3. when "Yes" then run batch file

 

Message 7 of 15
BlackBox_
in reply to: JCprog


@JCprog wrote:

Hello BlackBox, 

 

Thanks for the reply! I took a stab at it and returns "Too few arguments". this is just beyond me.

(vl-load-com)

(defun c:FilesAreUpToDate (local network)
  (equal (vl-file-systime "C:/folder1/local.txt") 
	(vl-file-systime C:/folder1/network.txt))
)

 I tend to:

1. compare the files first (the code above)

2. prompt user to update if files not equal

3. when "Yes" then run batch file

 


You've unintentionally broken the code by adding the "c:" prefix to a sub-function that requires two arguments... LISP Commands (those that include the "c:" prefix) should not require parameters in this way. Also, your second, network path is missing quotes.

 

Instead, consider this example (batch file not required):

 

(vl-load-com)

(defun c:UPDATE (/ _FilesAreUpToDate local network)

  (defun _FilesAreUpToDate (local network)
    (equal (vl-file-systime local) (vl-file-systime network))
  )

  (if
    (_FilesAreUpToDate
      (setq local "C:/folder1/local.txt")
      (setq network "C:/folder1/network.txt")
    )
     (prompt "\n** No update required ** ")
     (if (vl-file-delete local)
       (progn
	 (vl-file-copy network local)
	 (prompt "\n** Local file updated ** ")
       )
       (prompt "\n** Unable to delete local file ** ")
     )
  )
  (princ)
)

 



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

Message 8 of 15
JCprog
in reply to: BlackBox_

That worked flawlessly!

 

Comparing the two text files and updating both is achieved.

The updating part needs to be the whole folder. Inside folder contains various files including the text file. I would just like the text file to be the key for comparison but update the entire folder contents.

Message 9 of 15
JCprog
in reply to: JCprog

......Or can I just simply use the two folders to compare instead of the text files?

 

Edit: 

I stand corrected, It doesnt recognize the folders modified date

Message 10 of 15
BlackBox_
in reply to: JCprog


@JCprog wrote:

 

That worked flawlessly!


That is kind of you to say, JCprog.

 

 


@JCprog wrote:

 

Comparing the two text files and updating both is achieved.

The updating part needs to be the whole folder. Inside folder contains various files including the text file. I would just like the text file to be the key for comparison but update the entire folder contents.



Perhaps I overlooked your stating that you needed to update the entire folder earlier... For that you can do (at least) one of two things:

 

1) Iterate the contents of the network folder's files, and compare them each, updating if either out of date, or if the local version does not exist.

 

2) Instead rely on your batch file.

 

I'd personally opt for the former (others may disagree, and may also be smarter than I), for the simple reason of only updating what needs to be updated.

 

Here's a quick example of that (untested):

 

(vl-load-com)

(defun c:UPDATE (/ local network _FilesAreUpToDate file)

  ;; set local and network folders
  (setq local "C:/folder1/")
  (setq network "N:/folder1/")

  ;; file check sub-function
  (defun _FilesAreUpToDate (local network)
    (equal (vl-file-systime local) (vl-file-systime network))
  )

  ;; foreach file found in the network folder
  (foreach netFile (vl-directory-files network "*.*" 1)

    ;; if the file can be found locally
    (if (findfile (setq file (strcat local netFile)))

      ;; then, if the files are up-to-date
      (if (_FilesAreUpToDate file (strcat network netFile))

	;; then, no update required
	(prompt "\n** No update required ** ")

	;; else, if the local file can be deleted
	(if (vl-file-delete local)

	  ;; then,
	  (progn

	    ;; copy the network file to local
	    (vl-file-copy network local)

	    ;; notify user of successful file update
	    (prompt (strcat "\n** File \"" netFile "\" updated ** "))
	  )

	  ;; else, notify user file cannot be deleted
	  (prompt (strcat "\n** Unable to delete file \"" netFile "\" ** "))
	)
      )

      ;; else, copy the network file to local
      (vl-file-copy (strcat network netFile) file)
  )
  (princ)
)

 

 

... Just be mindful of local, read-only files not being updated... That may require an alternative means by which to update, if said files become read-only prior to AcadDoc.lsp being loaded in the startup sequence.

 

Cheers



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

Message 11 of 15
JCprog
in reply to: BlackBox_

been playing with the code a lil but bumped into a minor hiccup:

(vl-load-com)

(defun c:UPDATE (/ _FilesAreUpToDate local network)

  (defun _FilesAreUpToDate (local network)
    (equal (vl-file-systime local) (vl-file-systime network))
  )

  (if
    (_FilesAreUpToDate
      (setq local "C:/folder1/local.txt")
      (setq network "N:/folder1/network.txt")
    )
     (prompt "\n** No update required ** ")
     (if (startapp "C:/copyNET2LOCALtest.bat")
       (progn
	 (prompt "\n** Local file updated ** ")
       )
     )
  )
  (princ)
)

 The hiccup:

The code above runs the batch file but seems to skip comparing the two text files and just run the batch file whether text files are equal or not.

Message 12 of 15
BlackBox_
in reply to: JCprog


@JCprog wrote:

been playing with the code a lil but bumped into a minor hiccup:

(vl-load-com)

(defun c:UPDATE (/ _FilesAreUpToDate local network)

  (defun _FilesAreUpToDate (local network)
    (equal (vl-file-systime local) (vl-file-systime network))
  )

  (if
    (_FilesAreUpToDate
      (setq local "C:/folder1/local.txt")
      (setq network "N:/folder1/network.txt")
    )
     (prompt "\n** No update required ** ")
     (if (startapp "C:/copyNET2LOCALtest.bat")
       (progn
	 (prompt "\n** Local file updated ** ")
       )
     )
  )
  (princ)
)

 The hiccup:

The code above runs the batch file but seems to skip comparing the two text files and just run the batch file whether text files are equal or not.


What are the vl-File-SysTime values for each file?

 

Also, no need for the PROGN statement when there's only a single expression to evaluate (i.e., your PROMPT call).



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

Message 13 of 15
JCprog
in reply to: BlackBox_

When the local is up to date (meaning both folders are identical) and run the routine......it still runs the batch and skips this part:

(prompt "\n** No update required ** ")

 Part of your original code is:

     (prompt "\n** No update required ** ")
     (if (vl-file-delete local)
       (progn
	 (vl-file-copy network local)
	 (prompt "\n** Local file updated ** ")
       )
       (prompt "\n** Unable to delete local file ** ")
     )
  )

 somewhere along the code needs:

(startapp "C:/copyNET2LOCALtest.bat")

 In place of:

vl-file-delete
and
vl-file-copy

 

Message 14 of 15
JCprog
in reply to: BlackBox_

I got it!!!!!!!!!! I thinkSmiley Happy

 

(vl-load-com)

(defun c:UPDATE (/ _FilesAreUpToDate local network)

  (defun _FilesAreUpToDate (local network)
    (equal (vl-file-systime local) (vl-file-systime network))
  )

  (if
    (_FilesAreUpToDate
      (setq local "C:/folder1/update.txt")
      (setq network "N:/folder1/update.txt")
    )
     (prompt "\n** No update required ** ")
     (if (vl-file-delete local)
       (progn
	 (startapp "C:/copyNET2LOCALtest.bat")
	 (prompt "\n** Local file updated ** ")
       )
       (prompt "\n** Unable to delete local file ** ")
     )
  )
  (princ)
)

 Your original code worked from the very start. I just changed the vl-file-copy line to execute the batch file instead. Not sure if its the right way to go but it performed the way I need it to beSmiley Happy

 

Thanks a million BlackBox!!!!!!!!!!!!

Message 15 of 15
BlackBox_
in reply to: JCprog


@JCprog wrote:

 

Thanks a million BlackBox!!!!!!!!!!!!


You're welcome, JCprog; I'm happy to help. :beer:

 

Cheers



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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost