Jump to content

Recommended Posts

Posted

Is there a way to return the current, open drawing file path??

Posted

Excellent! Thank you, kind sir.

Posted

You're welcome.

Also, the following will return the active drawing name: (getvar 'DWGNAME)

Posted

Perfect. I was messing around with that and figured out that i can use (STRCAT

) to combine the two, but i am having a hard time opening the file. I am using:

 

 
(setq CD (getvar 'dwgprefix)
       CN (getvar 'dwgname)
       CF (strcat CD CN))
(open CF "w")

 

I did a save as before this routine and i tested that "CF" is still active, however, i can not get it to open. Is there an error in my code?

Posted
Perfect. I was messing around with that and figured out that i can use (STRCAT ) to combine the two, but i am having a hard time opening the file. I am using:

 

 
(setq CD (getvar 'dwgprefix)
       CN (getvar 'dwgname)
       CF (strcat CD CN))
(open CF "w")

 

I did a save as before this routine and i tested that "CF" is still active, however, i can not get it to open. Is there an error in my code?

OPEN doesn't work like that. It's for reading the contents of text files (read through the developer's HELP).

Plus, why would you open a drawing you already have open?

Posted

Hmmm.. Ok.. I am running a routine that saves the current drawing to an archive folder, renames it and does some "stuff" to it. At the end of the routine I want to open the original file back up.

Posted
Hmmm.. Ok.. I am running a routine that saves the current drawing to an archive folder, renames it and does some "stuff" to it. At the end of the routine I want to open the original file back up.

You'll need a bit of VLISP:

 

(vla-activate (vla-open (vla-get-activedocument (vlax-get-acad-object)) <FileName&Path> <Readonly>))
;; For readonly argument, feed it :vlax-false or :vlax-true (true for readonly)

Posted
You'll need a bit of VLISP:

 

(vla-activate (vla-open (vla-get-activedocument (vlax-get-acad-object)) <FileName&Path> <Readonly>))
;; For readonly argument, feed it :vlax-false or :vlax-true (true for readonly)

 

Can be my created list "CF"?

Posted
Can be my created list "CF"?

Yes. As long as it find a valid file path, it'll open it.

 

This subroutine should give you what you want...

(defun _open (file&path)
 (if (setq file&path (findfile file&path))
   (not (vl-catch-all-error-p
          (vl-catch-all-apply
            '(lambda (/)
               (vla-activate
                 (vla-open (vla-get-activedocument (vlax-get-acad-object)) file&path :vlax-false)
               )
             )
          )
        )
   )
 )
)

 

(_open cf)

Posted

Thanks a lot. Ill give it a go and let you know if I have a problem! Geez, something as simple as opening a file can be so involved..

Posted
Thanks a lot. Ill give it a go and let you know if I have a problem! Geez, something as simple as opening a file can be so involved..

Give a shout if you need more help.

Posted
Give a shout if you need more help.

 

Ok, I tried to add your routine to my existing program without the sub-routine. Maybe there is another way to go about this, but the result of this LISP is to SAVE the current drawing to another folder, bind all xrefs, and reopen the original drawing but i want the "ARCHIVED" drawing to be the current, active document in order to verify the bound xrefs as per the 'alert' in the lisp... It is not working. Take a look and see what can be improved/modified... I appreciate your help.

 

 
(DEFUN C:ARCHIVER (/ FN CD CN CF AD AN AF)
 (setq FN (getfiled "Save Archive As" "" "dwg" 1))
 (if (= FN nil )
   (progn
    (princ)(princ "...ARCHIVER ABORTED...")(princ))
   (progn
    (setvar "cmdecho" 0)
    (setq CD (getvar 'DWGPREFIX)
   CN (getvar 'DWGNAME)
   CF (strcat CD CN))
    (command "-xref" "r" "*" ""
             "qsave"
             "saveas" "" FN "y"
             "-xref" "b" "*" ""
             "zoom" "e"
             "-purge" "all" "*" "N"
             "QSAVE")
   (setq AD (getvar 'DWGPREFIX)
  AN (getvar 'DWGNAME)
  AF (strcat AD AN))
(vl-load-com)
(if (setq CF (findfile CF))
   (not (vl-catch-all-error-p
          (vl-catch-all-apply
            '(lambda (/)
               (vla-activate
                 (vla-open (vla-get-activedocument (vlax-get-acad-object)) CF :vlax-false)
               )
             )
          )
        )
   )
 )
(if (setq AF (findfile AF))
   (not (vl-catch-all-error-p
          (vl-catch-all-apply
            '(lambda (/)
               (vla-activate
                 (vla-open (vla-get-activedocument (vlax-get-acad-object)) AF :vlax-false)
               )
             )
          )
        )
   )
 )
    (setvar "cmdecho" 1)
    (alert "MAKE SURE ALL XREFS HAVE BEEN BOUND.\nTYPE XREF AT THE COMMAND LINE.")
    (princ)
    )))

 

Let it be known that I am teaching myself how to code, so forgive me if it is done "the hard way"... :-)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...