VBA - Save DXF from Drawing View

I'm (unsuccessfully) trying to write a macro that'll automate saving a part profile (flat pattern or flat (unbent) part) to dxf for use at our waterjet.

Drawings typically contain one or more views, one of which will be the view I want. That view could be a flat pattern, or it could be a 'flat' part that we're simply cutting the profile of.

The manual steps I take now are:

  1. Open drawing
  2. Delete all views except the view I want to save out
  3. Window-select the entire sheet and delete all notes and annotations
  4. If view is a flat pattern, right click and hide bend lines
  5. Hide the sheet format
  6. Save the remaining part profile as DXF

None of this seems like it should be difficult to do in VBA, but with my limited knowledge I haven't been able to come close to making this work (the best I've done is gotten save as DXF to work). I used the macro recorder to try to hide the sheet format, but I can't get it to work, and running the recorded macro doesn't even work.

If anybody could help with some of this I'd really appreciate it. I'm willing to continue to try to make it work, but I'm getting nowhere on my own.


Thank you,

Brain

SolidworksApi macros
Answers 7
SF
SF 2011-04-20 Best Answer

Hi Brian,

Give the attached macro a try. It's probably not the fastest, but it works fine for me.

If your drawing has no flat pattern, click a view first that you wish to use for the DXF. Dont click a feature within the view...click the VIEW :-)

This macro also strips all the annotations and asks the user where to save the file.

If you have a folder called C:\DXF it uses that folder as a default save location. Just search the code to change this location to whatever you wish.

Have fun

Anthony

SF
SF 2011-04-20

That is EXACTLY what I needed--it works perfectly. This will save so much time. I really, really appreciate this--thank you!

RV
RV 2019-08-07

Its not working. I am getting a Compile Error. 

ZP
ZP 2019-09-07

I am also getting same error as Ravi Chandra Verma

ZP
ZP 2019-09-07

Did you get this figured out? I'm getting the same error as you. 

Thanks

RV
RV 2019-09-09

No Solution i have got till now.

ZP
ZP 2019-09-09

Here is a link to one that works. You choose a view and it saves a dxf of that view in 1:1 after removing all dimensions. 

 And don't forget to modify the macro where you want it to save the dxf files.