Author Topic: VLisp Question  (Read 13570 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
VLisp Question
« Reply #15 on: November 17, 2003, 01:35:43 PM »
dont use this
(strcat "h:\\" (substr dn 1 5)"\\"
in the code, that's what 'path' is for.
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
VLisp Question
« Reply #16 on: November 17, 2003, 02:13:48 PM »
Alright guys. I am a f&*%!#g moron. :oops:   It's my damn fault why it wouldn't work. I left out one vital piece of info. The main folder it was in. So here is what it should look like. I'll have to add another line of code to add the extra folder, but thats on me.

Code: [Select]
(vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq fn (vlax-get-property doc 'FullName))
  (setq dn (vlax-get-property doc 'Name))
  (setq nn (strcase(strcat "h:\\03\\" (substr dn 1 5)"\\" dn )))<----Notice the extra \\03\\?
  (if (findfile nn)
    (alert "File exists.....")
    (if   (vl-file-copy fn nn)
      (progn (princ "\nFile copied...")
        (princ "\nNo file copied...")
        )
      )
    )
  (princ)
  )


Mark, when I did the findfile on THE RIGHT FOLDER of course it found it. Once I ran this I got a nil      :roll:

Craig

  • Guest
VLisp Question
« Reply #17 on: November 17, 2003, 02:17:56 PM »
Oh yea, when I do (cpCurdwg "h:/03033/") it does alert me that file exist. Is there a way to overwrite automatically with vl-file-copy?

Quote
dont use this
(strcat "h:\\" (substr dn 1 5)"\\"
in the code, that's what 'path' is for.


I know, I was trying to eliminate a few lines of code   :oops:

Craig

  • Guest
VLisp Question
« Reply #18 on: November 17, 2003, 02:31:54 PM »
To answer my own question I can do this (vl-file-copy fn nn T) but I get 263149 on the command line in response to the request. It acts like it does something but when I look at the other dwg there is no change. It says in the documentation that: If specified and not nil, source-file is appended to destination-file (that is, copied to the end of the destination file). Is it basically trying to append the file instead of overwrite it? That won't work if thats true

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
VLisp Question
« Reply #19 on: November 17, 2003, 02:56:39 PM »
Then use (vl-file-delete <filename>)
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
VLisp Question
« Reply #20 on: November 17, 2003, 02:58:00 PM »
Aiight guys, here seems to be what I'll be going with. Now all I need is the (vl-copy-file fn nn) to automatically overwrite, NOT APPEND. Any ideas on what I can use.

Code: [Select]
(defun cpCurdwg (/ doc fn dn nn)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq
    fn   (vlax-get-property doc 'FullName)
    dn   (vlax-get-property doc 'Name)
    nn   (strcase (strcat "h:\\" (substr dn 1 2) "\\" (substr dn 1 5) "\\" dn)
  )
  )
  (if (findfile nn)
    (alert "File exists.....")
    (if (vla-save fn nn)
      (alert "File copied...")
      (alert "No file copied...")
    )
  )
  (princ)
)

Craig

  • Guest
VLisp Question
« Reply #21 on: November 17, 2003, 02:59:07 PM »
Aiight Mark, I'll give it a try.

Craig

  • Guest
VLisp Question
« Reply #22 on: November 17, 2003, 03:07:16 PM »
Thanks Mark, Daron & Columbia for your help. Thanks again Mark. Here is the final
Code: [Select]
(defun c:filestore (/ doc fn dn nn)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq
    fn   (vlax-get-property doc 'FullName)
    dn   (vlax-get-property doc 'Name)
    nn   (strcase (strcat "h:\\" (substr dn 1 2) "\\" (substr dn 1 5) "\\" dn)
  )
  )
  (vl-file-delete nn)
  (vl-file-copy fn nn)
  (prompt "File Stored... ")
  (princ)
)


As simple as that

Columbia

  • Guest
VLisp Question
« Reply #23 on: November 17, 2003, 06:00:24 PM »
There's one other thing that you may have to watch out for, depending on the speed of your network and PC.

Sometimes, the interfacing with the Windows File System that vl-file-delete does takes longer to occur than VLISP allows for on its own.  Another way to put that is that your code is running too fast.  It goes onto the next step before the file deletion actually takes place.  Therefore you may get an error, or worse, unexpected results.

My suggestion is to wrap the vl-file-delete in a while loop that will keep testing for the deletion (non-existence) of the file before continuing on.  Much like the following:
Code: [Select]

(defun c:filestore (/ doc fn dn nn count)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq
    fn      (vlax-get-property doc 'FullName)
    dn      (vlax-get-property doc 'Name)
    nn      (strcase (strcat "h:\\" (substr dn 1 2) "\\" (substr dn 1 5) "\\" dn)
    count 0
      )
  )
  (if (findfile nn) ;; if the file already exists  <-- notice the if statement
    (progn
      (vl-file-delete nn)
      (while (and (findfile nn) (< count 100)) ;; <-- here's the loop
        ;; if the file is still to be found, hold on and try again...
        (setq count (1+ count))
      )
    )
  )
  (vl-file-copy fn nn)
  (prompt "File Stored... ")
  (princ)
)


But that's just my final 2 cents worth...