Author Topic: VLisp Question  (Read 13711 times)

0 Members and 1 Guest are viewing this topic.

Craig

  • Guest
VLisp Question
« on: November 17, 2003, 11:59:03 AM »
Is there a way in vlisp to save a dwg file. I know in Auotlisp you can't use something like (command ".save" filename). Is there something in vlisp that will allow this? Basically what I'm doing is wanting to select a button and it store the drawing I am working on into another location, not the folder I am working out of. What I've started with so far is:
Code: [Select]
(defun c:store ()
  (setq name (getvar "dwgname"))
  (setq project (substr name 1 5))
  (setq path (strcat "h:/" project "/" name))
  (command "_save" (strcat "h:/" project "/" name)) <---I know this won't work


I just wanted to show the last line of what I am wanting to get to with vlisp. If you input each line into our drawing here is the return:
Code: [Select]
(setq name (getvar "dwgname"))
"03033MP1.dwg"
(setq project (substr name 1 5))
"03033"
(setq path (strcat "h:/" project "/" name))
"h:/03033/03033MP1.dwg"


I can save the drawing taking a few extra lines of code creating a .bat file, but I really want to get away from batch filing. Any ideas?

Craig

  • Guest
VLisp Question
« Reply #1 on: November 17, 2003, 12:07:39 PM »
Will vl-file-copy let me do this? I can put in the dwg name variable and then the strcat path. Sumthin like

(vl-file-copy "filename" (strcat "h:/" project "/" name))

Think this would work?

daron

  • Guest
VLisp Question
« Reply #2 on: November 17, 2003, 12:18:37 PM »
vla-save should do the trick. Look it up under activex and vba reference.

Craig

  • Guest
VLisp Question
« Reply #3 on: November 17, 2003, 12:27:53 PM »
vla-save is not working and is not listed in the documentation. Not sure where I should be looking for this. I know little about Vlisp. The line of code (vla-save name (strcat "h:/" project "/" name)) does not work. Not sure on how to implement this

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
VLisp Question
« Reply #4 on: November 17, 2003, 12:31:36 PM »
needs more error checking
Code: [Select]
;;; path = string
;;; c:\\temp\\ <-- needs ending '\\'
(defun cpCurdwg (path / fn dn nn)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq fn (vlax-get-property doc 'FullName)
dn (vlax-get-property doc 'Name)
nn (strcat path dn)
)
  (if (vl-file-copy fn nn)
    (princ "\nFile copied...")
    (princ "\nNo file copied...")
    )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
VLisp Question
« Reply #5 on: November 17, 2003, 12:39:02 PM »
Thanks Mark, but something is going wrong. I get the follwing error

Quote
Error: cannot create file: h:\03033\03033MP1.dwg; error: An error has occurred
inside the *error* functionAutoCAD variable setting rejected: "orthomode" nil

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
VLisp Question
« Reply #6 on: November 17, 2003, 12:53:40 PM »
Code: [Select]
;;; path = string
;;; c:\\temp\\ <-- needs ending '\\'
(defun cpCurdwg (path / 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 (strcat path dn)
)
  (if (findfile nn)
    (alert "File exists.....")
    (if (vl-file-copy fn nn)
      (progn (princ "\nFile copied...")
    (princ "\nNo file copied...")
    )
      )
    )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
VLisp Question
« Reply #7 on: November 17, 2003, 12:58:07 PM »
Line by line, here's whats going on.

Code: [Select]
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
#<VLA-OBJECT IAcadDocument 0108c8bc>
(setq fn (vlax-get-property doc 'FullName))
"C:\\DWG\\03033\\03033MP1.dwg"
(setq dn (vlax-get-property doc 'Name))
"03033MP1.dwg"
(setq nn (strcat "h:\\" (substr dn 1 5)"\\" dn))
"h:\\03033\\03033MP1.dwg"
(vl-file-copy fn nn)
Error: cannot create file: h:\03033\03033MP1.dwg; error: An error has occurred
inside the *error* functionAutoCAD variable setting rejected: "orthomode" nil


Alright, tell me what the hell I am doing wrong.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
VLisp Question
« Reply #8 on: November 17, 2003, 01:17:47 PM »
What happens when you run the program like this.
(cpCurdwg "h:/03033/")

does the \03033\ already exist?
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
VLisp Question
« Reply #9 on: November 17, 2003, 01:19:14 PM »
When it does the findfile, it finds NIL but the file is there. I tried changing the path from h:\ to h:\\. I even did an strcase just to change them to all UPPERCASE since it extracts it that way, but to no avail.

Craig

  • Guest
VLisp Question
« Reply #10 on: November 17, 2003, 01:21:45 PM »
I tried (cpCurdwg "h:/03033/")  and still get the same error. Heres what I have.
Code: [Select]
(defun cpCurdwg   (path / 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 5)"\\" dn ))
   )
  (if (findfile nn)
    (alert "File exists.....")
    (if   (vl-file-copy fn nn)
      (progn (princ "\nFile copied...")
        (princ "\nNo file copied...")
        )
      )
    )
  (princ)
  )

Columbia

  • Guest
VLisp Question
« Reply #11 on: November 17, 2003, 01:23:12 PM »
Craig,

What you need to remember about using the VLISP Active-X controls is the first argument in almost every VL- function is a VLA-OBJECT.

Therefore when using vla-save, you need to provide the document object to this function.

However, that won't get you what you are looking for will it?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
VLisp Question
« Reply #12 on: November 17, 2003, 01:25:02 PM »
I'll get it right one of these days.........
Code: [Select]

;;; path = string
;;; c:\\temp\\ <-- needs ending '\\'
(defun cpCurdwg (path / 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 (strcat path dn)
)
  (if (findfile nn)
    (alert "File exists.....")
    (if (vl-file-copy fn nn)
      (princ "\nFile copied...")
      (princ "\nNo file copied...")
      )
    )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
VLisp Question
« Reply #13 on: November 17, 2003, 01:28:24 PM »
Alright,here is the code I just tried, and get nothing but errors.

Code: [Select]
(defun cpCurdwg   (path / 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 5)"\\" dn ))
   )
  (if (findfile nn)
    (alert "File exists.....")
    (if   (vla-save doc nn)
      (progn (princ "\nFile copied...")
        (princ "\nNo file copied...")
        )
      )
    )
  (princ)
  )


Bet you guys didn't know you would be tested like this on a Monday of all days. This is more like a Thursday problem.

The error I get with this one is: Error: too few arguments; error: An error has occurred inside the *error*
functionAutoCAD variable setting rejected: "orthomode" nil

Columbia

  • Guest
VLisp Question
« Reply #14 on: November 17, 2003, 01:35:37 PM »
You could try it this way...


Code: [Select]

(if (not (getvar "orthomode")) (setvar "orthomode" 0))
(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 5)"\\" dn ))
   )
  (if (findfile nn)
    (alert "File exists.....")
    (if   (vla-file-copy fn nn)
      (alert "File copied...")
      (alert "No file copied...")
    )
  )
  (princ)
  )


This might work...