TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: KewlToyZ on June 09, 2006, 12:12:39 PM

Title: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 12:12:39 PM
I'm trying to copy an image file to a project folder automatically within an autolisp routine.
I found a few references to vl-file-copy used but it seems to return "nil" when i try the static file and folder paths.
(defun c:logocopy()
(vl-file-copy "X:\\logo.jpg" "X:\\A\\A0001\\Logos")
)

playing around with it i also tried:

   (defun c:logocopy()
   (setq logo2logos (getfiled "Logo File Import" "X:\\logo.jpg" "jpg" 2))
   (vl-file-copy logo2logos "X:\\A\\A0001\\Logos\\" T)
   )

still got nil
I'm not finding the vl-file-copy in AutoCAD help very clear on its ability to handle image files over a network.
Any direction would be appreciated, Thank you :)
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Bob Wahr on June 09, 2006, 12:25:37 PM
Code: [Select]
(defun c:test()
  (command "sh")
  (command "copy x:\logo.jpg x:\a\0001\logos")
)
?
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Bob Wahr on June 09, 2006, 12:31:09 PM
As far as I can see,
Code: [Select]
(defun c:logocopy()
(vl-file-copy "X:\\logo.jpg" "X:\\A\\A0001\\Logos")
)
should work.  Are you sure that the file exists in that location and that the destination folder exists?
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Bob Wahr on June 09, 2006, 12:33:03 PM
wait, try
Code: [Select]
defun c:logocopy()
(vl-file-copy "X:\\logo.jpg" "X:\\A\\A0001\\Logos\\logo.jpg")
)
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 12:44:40 PM
Code: [Select]
(defun c:test()
  (command "sh")
  (command "copy x:\logo.jpg x:\a\0001\logos")
)
?

I was hoping for it to be this simple but it lists "copy x:\logo.jpg x:\a\0001\logos" as an unkown command
Of course adding "" to each component   (command "copy" "x:\logo.jpg" "x:\a\0001\logos") brings up autocad's copy command so this isn't the right course either.
Removing the quotes all together (command copy x:\logo.jpg x:\a\0001\logos)
Returns nil again so I am back to square one lol.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 12:48:58 PM
That was my first attempt and I keep getting a nil.
Which was wy I tried the getfiled to make sure i found the file.
I'm trying to use CAD to place the logo file since the web interface seems to fail arbitrarily on folders over the network.
All have the same permissions but for some reason it misses this image file periodically.
I was hoping a simple lisp routine would help but this is proving strange as well.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 12:52:26 PM
That was my first attempt and I keep getting a nil.
Which was wy I tried the getfiled to make sure i found the file.
I'm trying to use CAD to place the logo file since the web interface seems to fail arbitrarily on folders over the network.
All have the same permissions but for some reason it misses this image file periodically.
I was hoping a simple lisp routine would help but this is proving strange as well.

I forgot the command "sh" to bring up the OS command.
My bad and thank you for the help!
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Bob Wahr on June 09, 2006, 01:00:51 PM
Glad that fixed you up.  I'm sure that someone who can lisp will be along in the very near future to tell you how to get vl-file-copy to work or why you shouldn't use it and what you should use instead.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 01:08:07 PM
Yes it works well alone but when I try to make the paths defined by the session it doesnt activate within another routine.
I was trying to integrate it with the drawing setup routine the guys here helped me overwhelmingly with.
I'm going to keep playing with it, but I think that the OS command seems not to recognize a variable as a path.
Or I am hust completely failing to structure it properly which is more likely.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 01:16:24 PM
Yes it works well alone but when I try to make the paths defined by the session it doesnt activate within another routine.
I was trying to integrate it with the drawing setup routine the guys here helped me overwhelmingly with.
I'm going to keep playing with it, but I think that the OS command seems not to recognize a variable as a path.
Or I am hust completely failing to structure it properly which is more likely.

It tries to pass the variable path as a command instead of a path.

  (setq idx (vl-string-search "CADD" prefx))
  (setq baseprefix (strcat (substr prefx 1 (+ 5 idx)) "XREF\\"))
  (command "sh")
  (command "copy X:\\logo.jpg" baseprefix))
--------------------------------------------------------------------------------------------
Command: Unkown command "X:\A\A9999\CADD\XREF\" Press F1 for help.
nil

Command:|
-----------------------------------------------------------------------------------
Is where I end up
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: uncoolperson on June 09, 2006, 01:22:36 PM
wait, try
Code: [Select]
defun c:logocopy()
(vl-file-copy "X:\\logo.jpg" "X:\\A\\A0001\\Logos\\logo.jpg")
)


this should be working, if it isn't take a look and make sure the file isn't already there (in the target directory), if it is delete it and try again
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Bob Wahr on June 09, 2006, 01:34:51 PM
What happens if
Code: [Select]
 (setq idx (vl-string-search "CADD" prefx))
  (setq baseprefix (strcat (substr prefx 1 (+ 5 idx)) "XREF\\"))
  (setq cmdline ( "sh copy x:\\logo.jpg" baseprefix)
;my lisp is weak and lacks leverage but I believe that the above line sets cmdline to
;"sh copy x:\\logo.jpg x:\\a\\a9999\cadd\xref\
  (command cmdline)

***starts looking around desperately for a lisper to step in***

woot!  UCP to the rescue.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 01:45:24 PM
wait, try
Code: [Select]
defun c:logocopy()
(vl-file-copy "X:\\logo.jpg" "X:\\A\\A0001\\Logos\\logo.jpg")
)


this should be working, if it isn't take a look and make sure the file isn't already there (in the target directory), if it is delete it and try again

No the file never made it there with this, I have no idea why.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 01:50:30 PM
What happens if
Code: [Select]
 (setq idx (vl-string-search "CADD" prefx))
  (setq baseprefix (strcat (substr prefx 1 (+ 5 idx)) "XREF\\"))
  (setq cmdline ( "sh copy x:\\logo.jpg" baseprefix)
;my lisp is weak and lacks leverage but I believe that the above line sets cmdline to
;"sh copy x:\\logo.jpg x:\\a\\a9999\cadd\xref\
  (command cmdline)

***starts looking around desperately for a lisper to step in***

woot!  UCP to the rescue.

Nice attempt, I played with this awhile but without command SH doesnt recognize.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 02:29:02 PM
Code: [Select]
  (setq idx (vl-string-search "CADD" prefx))
  (setq baseprefix (strcat (substr prefx 1 (+ 5 idx)) "XREF\\"))
  (command "sh")
  (command "copy X:\\logo.jpg baseprefix" ))

I went back with this above.
It opens the folder with windows explorer for the baseprefix but doesn't copy the file strangely enough.
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 02:40:24 PM
how would I remove the quotes from the path stored in baseprefix?
that is the reason it reads the path as a command from the shell when I run it under

Code: [Select]
  (setq idx (vl-string-search "CADD" prefx))
  (setq baseprefix (strcat (substr prefx 1 (+ 5 idx)) "XREF\\"))
  (command "sh")
  (command copy X:\\logo.jpg baseprefix ))
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: T.Willey on June 09, 2006, 02:56:06 PM
Try this.
Code: [Select]
(if (findfile "X:\\logo.jpg")
 (if (findfile "X:\\A\\A0001\\Logos\\logo.jpg")
  (prompt "\n File already exists, cannot copy.")
  (vl-file-copy "X:\\logo.jpg" "X:\\A\\A0001\\Logos\\logo.jpg")
 )
 (prompt "\n Original file does not exist, cannot copy.")
)
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: T.Willey on June 09, 2006, 02:57:41 PM
how would I remove the quotes from the path stored in baseprefix?
that is the reason it reads the path as a command from the shell when I run it under

Code: [Select]
  (setq idx (vl-string-search "CADD" prefx))
  (setq baseprefix (strcat (substr prefx 1 (+ 5 idx)) "XREF\\"))
  (command "sh")
  (command copy X:\\logo.jpg baseprefix ))
You would have to string all the string together with strcat.
Code: [Select]
(command (strcat "copy x:\\logo.jpg" baseprefix))

</guess about shell command>
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Andrea on June 09, 2006, 03:24:57 PM
I have wrote this...
maybe could help..

Code: [Select]
(defun c:pgpbackup (/ pgpfile loginname)
(setq pgpfile (findfile "acad.pgp"))
(setq loginname (getvar "loginname"))
(if (findfile (strcat "x:/acad/pgp/" loginname ".pgp"))
    (vl-file-delete (strcat "x:/acad/pgp/" loginname ".pgp"))
)
(vl-file-copy pgpfile (strcat "x:/acad/pgp/" loginname ".pgp") T)
)code]
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: Jeff_M on June 09, 2006, 04:26:42 PM
Here's my little contribution.....
Code: [Select]
(defun xcopy (source dest)
  (if (and (setq source (findfile source))
   (vl-file-directory-p (vl-filename-directory dest))
   )
    (progn
      (if (findfile dest)
(vl-file-delete dest)
)
      (vl-file-copy source dest)
      )
    )
  )

;;sample usage:
(xcopy "c:\\test.txt" "q:\\test.txt")
[\code]
Title: Re: Copy jpg to folder with vl-file-copy?
Post by: KewlToyZ on June 09, 2006, 04:41:46 PM
I was taking some time to tell myself how much of an idiot I was.... :lol:
Forgot to include the filename with the path with vl-file-copy :|

Code: [Select]
(if (findfile "J:\\logo.jpg")
  (if (findfile (strcat baseprefix"logo.jpg"))
  (prompt "\n File already exists, cannot copy.")
  (vl-file-copy "J:\\logo.jpg" (strcat baseprefix"logo.jpg"))
  )
  (prompt "\n Original file does not exist, cannot copy.")
  )

Worked perfectly TWiley.
Great addition Jeff M
Nice feature there Andrea!