Jump to content

Dxf to file location


bradb

Recommended Posts

Trying to get this lisp to save a dxf to a specific folder ex. C:\My Documents\DXF\. I tryed putting that in the code but I'm not writing it right or something. Could someone point me in the right direction.

 

(defun c:dxf ()
(vl-load-com)
(vlax-for LAYOUT (vla-get-layouts(vla-get-activedocument(vlax-get-acad-object)))
(vl-catch-all-apply 'vla-delete (list LAYOUT))
)
(command "CHANGE" "ALL" "" "P" "LA" "0" "")
(command "-PURGE" "ALL" "" "N")
(nowdxf)
)
(defun nowdxf () 
(command "saveas" "dxf" "")
)

Link to comment
Share on other sites

I'd look into the DXFOUT command in lieu of saveas

 

Also you will need \\ or use / for directory locations in lieu of the single \

 

-David

Link to comment
Share on other sites

Tryed this. Its still not working. By usings just the saveas or dxfout, it works but I want to force it to this folder with out have to select it.

 

(defun c:dxf ()
(vl-load-com)
(vlax-for LAYOUT (vla-get-layouts(vla-get-activedocument(vlax-get-acad-object)))
(vl-catch-all-apply 'vla-delete (list LAYOUT))
)
(setvar "CLAYER" "0")
(command "change" "all" "" "p" "la" "0" "")
(command "-purge" "all" "" "n")
(nowdxf)
)
(defun nowdxf (/ dxfname)
(setq dxfname (getstring "n\DXF Name:  "))
(command "_SAVEAS"  "DXF" "" (strcat "C:\\Users\\My Documents\\DXF\\" DXFNAME))
(princ)
)

Link to comment
Share on other sites

If you're trying to avoid the SaveAs dialog, then consider this example:

 

(defun c:FOO ( / fileName)
 (vl-load-com)
 (if (setq fileName (getstring T "\nEnter a file name: "))
   (vla-saveas
     (vla-get-activedocument (vlax-get-acad-object))
     (strcat "C:\\Users\\My Documents\\DXF\\" fileName ".dxf")
     ac2010_dxf)
   )
 (princ)
 )

Link to comment
Share on other sites

Pseudo code:

 

(defun c:FOO  ()
 (vl-load-com)
 (vlax-for oLayout  (vla-get-layouts
                      (vla-get-activedocument
                        (vlax-get-acad-object)))
   (vl-catch-all-apply 'vla-delete (list oLayout)))

 (setvar 'clayer "0")

 (command "._change" "all" "" "properties" "layer" "0" "")
 (command "._-purge" "all" "" "no")
 (command "._dxfout"
          (vl-string-subst
            ".dxf"
            ".dwg"
            (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
          16)

 (princ))

Link to comment
Share on other sites

Cool. Still trying to learn this visiual lisp. Thanks

 

No worries; we all start somewhere... Here's a thread where I learned one of my first lessons from Mr. Bell himself (he like most of 'us' geeks have an appreciation for SW humor). :geek: :thumbsup:

Link to comment
Share on other sites

For those who prefer Visual LISP...

 

(defun LM:dxfout ( doc fname / err sel )
   (setq err
       (vl-catch-all-apply 'vla-export
           (list
               doc
               (strcat
                   (vl-filename-directory (vl-string-translate "/" "\\" fname))
                   "\\"
                   (vl-filename-base fname)
               )
               "dxf"
               (setq sel (vla-add (vla-get-selectionsets doc) (rtos (getvar 'date) 2 8)))
           )
       )
   )
   (vla-delete sel)
   (if (vl-catch-all-error-p err)
       (prompt (vl-catch-all-error-message err))
       t
   )
)
(vl-load-com) (princ)
 

 

(LM:dxfout (vla-get-activedocument (vlax-get-acad-object)) <DXF Filename>)
 
Edited by Lee Mac
Link to comment
Share on other sites

For those who prefer Visual LISP...

 

This is _so_ me (one who prefers vla- code). :rofl:

 

Separately, and also interesting is the fact that the DXF extension is conveniently missing from the (albeit non-Autodesk) online ActiveX Developer Documentation:

 

Export Method

 

I'm also surprised that the extension is a string, rather than an ac####_dxf Enum, as is the case with the SaveAs Method. Nice find, thanks Lee. :beer:

Link to comment
Share on other sites

I'm guessing the .dsf should be .dxf (since also 's' is close to 'x' on a qwerty), but yes, one must read between the lines with the ActiveX Documentation...

 

You're welcome Renderman :)

Link to comment
Share on other sites

  • 10 years later...
On 6/29/2012 at 3:45 PM, Lee Mac said:

For those who prefer Visual LISP...

 

 

(defun LM:dxfout ( doc fname / err sel )
   (setq err
       (vl-catch-all-apply 'vla-export
           (list
               doc
               (strcat
                   (vl-filename-directory (vl-string-translate "/" "\\" fname))
                   "\\"
                   (vl-filename-base fname)
               )
               "dxf"
               (setq sel (vla-add (vla-get-selectionsets doc) (rtos (getvar 'date) 2 ))
           )
       )
   )
   (vla-delete sel)
   (if (vl-catch-all-error-p err)
       (prompt (vl-catch-all-error-message err))
       t
   )
)
(vl-load-com) (princ)
 

 

 

 

(LM:dxfout (vla-get-activedocument (vlax-get-acad-object)) <DXF Filename>)
 

 

 

There is a missing closing parentesis:

(setq sel (vla-add (vla-get-selectionsets doc) (rtos (getvar 'date) 2 )))

 

How do I export only selection if anything is selected or entire document if nothing is selected?

Link to comment
Share on other sites

7 hours ago, vanowm said:

There is a missing closing parentesis:

(setq sel (vla-add (vla-get-selectionsets doc) (rtos (getvar 'date) 2 )))

 

This caused by the change to the forum software which removed all instances of "8)" from code... I've now updated my earlier post.

  • Like 1
Link to comment
Share on other sites

12 hours ago, vanowm said:

So is there a way export only selected entites?

 

Yes, but not using the ActiveX Export method - per the documentation:

Quote

When exporting to EPS or DXF formats, the selection set is ignored and the entire drawing is exported.

 

Instead, you'll need to use the DXFOUT command with the Objects option.

Link to comment
Share on other sites

Working with selection sets I think you could do.

 

(setvar 'saveformat #) ;verson of your dxf you want o save

Wblock command feed selection set.

rest saveformat to default settings.

 

 

 

 

Link to comment
Share on other sites

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...