Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

dxf export macro 1

Status
Not open for further replies.

jbohrer

Industrial
Aug 22, 2012
11
Hi all,
I've been struggling with this project all week, so hopefully I can figure this out and be done with it.

I'm trying to export dxf files from a sheet metal part. each part has 2-4 flat patterns and a bunch of configurations. Frankly, the dxf export utility in solidworks is awful, it names them so that they are all out of order when I look at them in windows and ProNest. I found a macro that is close to what I need on the solidworks forums, but it only exports one flat pattern from the drawing. Is there any way to make this macro output all the flats on seperate dxf files? Thanks in advance!


Option Explicit

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim nStart As Single
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean


Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc

vConfNameArr = swModel.GetConfigurationNames

For i = 0 To UBound(vConfNameArr)

sConfigName = vConfNameArr(i)


bShowConfig = swModel.ShowConfiguration2(sConfigName)

bRebuild = swModel.ForceRebuild3(False)

Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String

FilePath = swModel.GetPathName
PathSize = Strings.Len(FilePath)
PathNoExtension = Strings.Left(FilePath, PathSize - 6)

NewFilePath = PathNoExtension + sConfigName & ".DXF"

'Export Flat Pattern
bRet = swModel.ExportFlatPatternView(NewFilePath, 1)

Next i

End Sub
 
Replies continue below

Recommended for you

Are you running this macro from the drawing file (.SLDDRW) or the part file (.SLDPRT)? I see code in there that is grabbing all of the config names and ehtn looping through it... so it appears it is intended to do multiple DXF flats from a single file. Try running it in the part file if you previously ran it in a drawing.

-Dustin
Professional Engineer
Pretty good with SolidWorks
 
I looked at your file.

I don't understand your statement of "only one flat per configuration". How can you have more than one flat pattern for a given configuration? The exported DXF... is it actually the flat pattern? One thing to try. Create a derived configuration for each parent configuration... call it for example #47_FLAT_PATTERN. Then go into that derived config and unsupress the flat pattern feature... resulting in the part being flattened. Re-Run your macro.

-Dustin
Professional Engineer
Pretty good with SolidWorks
 
Limey got what I was trying to say. I'll try unsupressing the flat pattern and see what happens.
 
well it's a no-go unsupressing it. Trying to learn to macro on the fly and there doesn't seem to be a whole lot of documentation that I can find. Anyone know of a good resource for learning to make a macro for SW?
 
I still don't understand your statement of "only one flat per configuration". How can you have more than one flat pattern for a given configuration?

You don't have a multibody sheetmetal part. I just ran that macro on the sample file you uploaded... it worked like a champ. I got one DXF for each of the 3 configurations in your model... 3 DXF's. The macro automatically added in the SM-FLAT-PATTERN derived config.

I am not clear on what your intended output is...

-Dustin
Professional Engineer
Pretty good with SolidWorks
 
Ahhh... that part is multibody. You will have to manually create two derived configurations. In each of the derived configs, unsupress ONE of the flat pattern features. Then run the macro.

Alternatively, create a drawing and insert flatpattern views... select the body etc. That will create the derived configs for you. I just did and it got two DXF files for the one config.

-Dustin
Professional Engineer
Pretty good with SolidWorks
 
Thank you Shaggy, that's a huge time saver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor