Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Macro Button to save as DXF and close file without saving to DWG

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
B_Bevelander
1198 Views, 10 Replies

Macro Button to save as DXF and close file without saving to DWG

I usually extract DXF's from my Inventor Enviroment and edit them in AutoCAD 2016 to tidy them up. This happens quite often and when i wish to save the edit DXF, it prompts me with a save screen, I need to reselect DXF 2004 version and press enter and comfirm in wish to override the file.

 

To make my life a bit easier I created a button in the Customize User Interface called 'Save as DXF' with the following macro:

+Saveas (save the file as without prompting a pop-up screen)

F (save it as a DXF)

2004 (save it as a 2004 version)

 

thats as far as I've gotten, as it then prompts me with a screen anyway to the select the file name.

 

I wish to just keep the current filename and just press Enter basicly, then a last prompt comes to ask wether im sure I want to override the file, resulting with a Y for choosing Yes.

 

Is there a way to build these last 2 steps into the macro itself?

10 REPLIES 10
Message 2 of 11
ВeekeeCZ
in reply to: B_Bevelander

Edit: You're not using LT, right? If you do, stop reading here.

 

Try this.

If the is no dxf yet, no prompt for you.

If the dxf exists, you're prompted for a name. If you confirm the same one, it will override it. 

If you cancal the name dialog, or you give a new name that exists too... then you're sent to the dialog of the SaveAs.

 

Try and let know. 

btw the closing is a little bit issue - seems to work but it's a bit forced... 

(defun c:SaveAsDXF ( / *error* name-old name-new exist)

    (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (princ))

  (setq name-old (vl-filename-base (getvar 'dwgname))
	path (getvar 'dwgprefix))

  (if (setq exist (findfile (strcat path name-old ".dxf")))
    (setq name-new (lisped name-old)))

  (cond ((or (numberp name-new)
	     (and exist
		  (/= name-old name-new)
		  (findfile (strcat path name-new ".dxf"))))
	 (initdia)
	 (command-s "_.saveas"))

	((and exist (= name-old name-new))
	 (command "_.saveas" "dxf" "_version" "2004" 16 (strcat path name-new) "_Yes")
	 (command "_.close") (command))

	(T 
	 (command "_.saveas" "dxf" "_version" "2004" 16 (strcat path (cond (name-new) (name-old))))
	 (command "_.close") (command)
	 ))
  
  (princ)
  )

 

Message 3 of 11
B_Bevelander
in reply to: B_Bevelander

Doesn't seem to work, when I run the command, it stops at the 4th line (5th if you count the empty one)

Not sure if this is effected by the version im running? 2016.

Message 4 of 11
ВeekeeCZ
in reply to: B_Bevelander

Not sure... try this.

 

(defun c:SaveAsDXF ( / *error* name-old name-new exist)

    (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (princ))

  (setq name-old (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4))
	path (getvar 'dwgprefix))

  (if (setq exist (findfile (strcat path name-old ".dxf")))
    (setq name-new (lisped name-old)))

  (cond ((or (numberp name-new)
	     (and exist
		  (/= name-old name-new)
		  (findfile (strcat path name-new ".dxf"))))
	 (initdia)
	 (command-s "_.saveas"))

	((and exist (= name-old name-new))
	 (command "_.saveas" "dxf" "_version" "2004" 16 (strcat path name-new) "_Yes")
	 (command "_.close") (command))

	(T 
	 (command "_.saveas" "dxf" "_version" "2004" 16 (strcat path (cond (name-new) (name-old))))
	 (command "_.close") (command)
	 ))
  
  (princ)
  )

 

Message 5 of 11
B_Bevelander
in reply to: B_Bevelander

Still same problem occurs, see attached file.

Message 6 of 11
ВeekeeCZ
in reply to: B_Bevelander

Save the code as *.lsp file and drag-and-drop it into drawing.

Read THIS  

Message 7 of 11
B_Bevelander
in reply to: ВeekeeCZ

So there's no way to do this with a simple macro in a command like I initually tried?

Message 8 of 11
Moshe-A
in reply to: B_Bevelander

@B_Bevelander 

 

here check this cuix macro:

 

[Save to DXF 2004]^c^cDxfout;;y v 2004;;

 

enjoy

moshe

 

Message 9 of 11
B_Bevelander
in reply to: Moshe-A

That works only when I open a dwg to export it to DXF, yet when i open it as already being a DXF it gives me an error message:

 

EDIT: Ok with the help from previous post of @Moshe-A , changed my own code to: +Saveas F 2004 ;;; y

 

This seems to work for both DWG and DXF to save them as DXF in the same folder. If it already is a DXF, it overrides it, if its a DWG it creates a DXF.

 

Thanks for the help.

 

Message 10 of 11
Moshe-A
in reply to: B_Bevelander

your are welcome

 

Notice (for next time)  when closing a thread make sure you credit the right support guy 😀

 

 

Message 11 of 11
hansDPQMN
in reply to: ВeekeeCZ

 

(command "_.close") (command) you can use
(command "_.close" "n") instead for closing without saveing to dwg

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost