Save flat pattern drawing as DXF

I have a program that takes a selected drawing view and savesout a 1:1 drawing view as a dxf file that we send to the plasma. Ihaven't figured out how to get bend lines to save out so I can putthem on an etch layer.

If I manually save the drawing as a DXF, sometimes I have theoption to uncheck a box at the bottom of the SaveAs dialog to hidebend lines, so unchecking that box lets the bend lines comethrough. But that checkbox isn't always there - haven't figuredthat one out either. I even tried turning off the bend notes to seeif that made a difference - nope.

But anyway, I have instances where I can manually save out the maindrawing and the bend lines show up. And then if I run the programto create a new drawing with the selected flat pattern view, then Idon't get the bend lines.

Any thoughts?

SW2009 SP2
Macro is VB6

WTSolidworksApi macros
Answers 26
TC
TC 2009-01-26 Best Answer
I save my flat patterns directly from the sheet metal parts.Just do a save as DXF. You can check "remove bend lines" during thesave.
Tim
SF
SF 2009-01-26
Yes, while that does output the geometry and the bend lines,it doesn't do all the other stuff that our program does. We createa burn layer and an etch layer. The part number is etched onto thepart and the file is saved into the appropriate folder on thenetwork based on what job it's for. It's also named per the drawingand view that the shop sees it on.

So if the bend lines can show up with a direct save, why can't Iget them to show up with my program? I have searched for an APIcall that shows or hide sbend lines but i can't find one. Have Imissed it somewhere?

WT
BG
BG 2009-01-26
Hi Wayne,

I'm not sure that I understand you right but, are you saying thatwhen you do a dxf save through a drawing the bend lines don't showup ? and you want them to ?
SF
SF 2009-01-26
Not quite. When I have a drawing open that includes a flatpattern, and I have the box unchecked to "Remove bend lines" then Ido get the bend lines coming through to the dxf file. But when Isave that same drawing with the macro, then something is notletting the bend lines come through and I can't find anything inthe API help that talks about showing/saving bend lines. Bend linenotes - yes. Bend lines - no.

WT
BG
BG 2009-01-27
When I first wrote a macro to make dxf files, I did not neednothing to do with layers or anything so I never wanted to havebendlines showing and the only way I could do it so they would notshow was by going to view and clicking the sketches button then Isaved that as my template.

So when ever I ran my macro the bendlines were always hidden and inyour case you might want to do the opposite.

You can probably control that sketch button through the API aswell.

SF
SF 2009-01-27

Ben Guenther wrote:

 

...by going to view and clicking the sketches button...

Please elaborate - not sure what you mean. Do you mean thatyou would hide the sketch in the tree that is the bend line?

WT

BG
BG 2009-01-27
I was just snooping around and found that all you actuallyneed to do is select the a bend line and put in this line"swDrawDoc.UnblankSketch" to show the bend lines and"swDrawDoc.BlankSketch" to hide the bend lines see how that worksfor you.
SF
SF 2009-01-27
Great! So then the next question is how to select the bendlines. I suppose I could assume that people here are not supposedto change the name of that particular thing, and I could then knowthat it's always called Bend-Lines1. But, what if they do changethe name? Hmm. It should always be under the flat pattern featurewhatever that name is........

WT
BG
BG 2009-01-27
I was haveing a little bit of trouble with that too. When Ido that with a part I just loop through all the features of thepart and in the loop I do the magic.


 


Set swFeat = swDoc.FirstFeature
Do While Not (swFeat Is Nothing)
If (swFeat.GetTypeName2 = "FlatPattern") Then
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not (swSubFeat Is Nothing)
If swSubFeat.GetTypeName2 = "ProfileFeature" Then
swSubFeat.Select2 True, 1
****Here the bend sketch would be selected and then you would putyour line that I gave you before******
End If
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
End If
Set swFeat = swFeat.GetNextFeature
Loop

The above code works great for that in a part but I am justhaving a little bit of trouble looping through the features of thepart in a drawing I don't do much with drawing so I am not veryexperienced with that but I will try again tomorrow and get back toyou.
BG
BG 2009-01-27
Sorry Wayne,

I thought I could but I was wrong.

 


Dim swapp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swView As SldWorks.View
Dim swDraw As SldWorks.DrawingDoc
Dim swModel As SldWorks.ModelDoc2
Dim Retval As Boolean
Dim bendline As String

Sub main()

Set swapp = Application.SldWorks
Set swDoc = swapp.ActiveDoc
Set swDraw = swDoc
Set swView = swDraw.GetFirstView

Do While Not (swView Is Nothing)

Set swModel = swView.ReferencedDocument
If Not swModel Is Nothing Then
Set swFeat = swModel.FirstFeature
Do While Not (swFeat Is Nothing)
Debug.Print swFeat.Name
If (swFeat.GetTypeName2 = "FlatPattern") Then
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not (swSubFeat Is Nothing)
Debug.Print swSubFeat.Name
Debug.Print swSubFeat.GetTypeName2
If swSubFeat.GetTypeName2 = "ProfileFeature" Then
bendline = swSubFeat.Name
Retval = swDoc.Extension.SelectByID2(bendlines, "ProfileFeature",0#, 0#, 0#, True, 0, Nothing, swSelectOptionDefault)
swDoc.UnblankSketch
swDoc.BlankSketch

End If
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
End If
Set swFeat = swFeat.GetNextFeature
Loop

End If
Set swView = swView.GetNextView
Loop


End Sub

That is the code that I got so far I got right to the sektchbut I could not select the sketch to blank it hopefully somebodyelse can help you with selecting it.
SF
SF 2009-01-27
Thanks for the effort. As you say, maybe it will spark somethoughts. I have to get some stuff in the shop so I don't have timeto work on it right now, but I will take a look at it when I get achance. Tonight is our user group meeting so I can't even work onit later. Dang priorities anyway. :-)

WT
BG
BG 2009-01-29
Not sure if this is too cheesy but it works.

 


Option Explicit
Dim swapp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swView As SldWorks.View
Dim swDraw As SldWorks.DrawingDoc
Dim swModel As SldWorks.ModelDoc2
Dim Retval As Boolean
Dim bendline As String

Sub main()

Set swapp = Application.SldWorks
Set swDoc = swapp.ActiveDoc
Set swDraw = swDoc
Set swView = swDraw.GetFirstView

Do While Not (swView Is Nothing)

Set swModel = swView.ReferencedDocument
If Not swModel Is Nothing Then
Set swFeat = swModel.FirstFeature
Do While Not (swFeat Is Nothing)
Debug.Print swFeat.Name
If (swFeat.GetTypeName2 = "FlatPattern") Then
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not (swSubFeat Is Nothing)
If swSubFeat.GetTypeName2 = "ProfileFeature" Then
bendline = swSubFeat.Name & "@" &GetFileName(swModel.GetPathName, False) & "@" & swView.Name

Retval = swDoc.Extension.SelectByID2(bendline, "SKETCH", 0#, 0#,0#, True, 0, Nothing, swSelectOptionDefault)
'swDoc.UnblankSketch
swDoc.BlankSketch

End If
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
End If
Set swFeat = swFeat.GetNextFeature
Loop

End If
Set swView = swView.GetNextView
Loop


End Sub

Public Function GetFileName(PathNameIn As String, IncludeExt AsBoolean) As String
If IncludeExt = False Then
PathNameIn = VBA.Left(PathNameIn, InStrRev(PathNameIn, ".", -1,vbTextCompare) - 1)
End If
PathNameIn = VBA.Right(PathNameIn, Len(PathNameIn) -InStrRev(PathNameIn, "\", -1, vbTextCompare))
GetFileName = PathNameIn
End Function

I have marked unblanksketch if you want to show the bendlinesjust use it instead of the blanksketch.

Let me know if it does not work or if you have any questions
SF
SF 2009-01-29
I do believe the API team are working on adding the option toshow/hide bendlines for the PartDoc::ExportFlatPatternViewfunction, as it has an unused Options parameter, so what else couldit be for.

Probably expect this to be in SP3-4 or 09, or at the latest in 2010SW.


Have you managed to get this request working yet or are you stillstruggling?
BG
BG 2009-01-29
Luke,

Yes, the code in my last post works to hide or show bendlines. It'skind of a lot of code to do a small little thing but that is theonly way I found it to work.

SF
SF 2009-01-29
I feel quite bad that I haven't had time to get back to this.I have been just buried here at work, as in 13 hour days. HopefullyI can survive until I get on the plane to SWW. Ahhhh, peace andquiet, a cup of coffee, work on this macro. Life is good. :-)

So, I'm not ignoring this, and very much appreciate the code, andam just itching to get back to it, but... you know how it is.Thanks.

WT
BG
BG 2009-02-02
The code that I last posted does that do what you wanted?
SF
SF 2009-02-03
Ben, my humblest apologies - I haven't had a chance to lookat it. I have been absolutely buried here at work. It's 9:30 pm andI am still here. Started at 7:00 this morning. Been like this for aweek and I'm afraid will be like this until the point I drive tothe airport.

Hopefully after SWW I'll get a chance to review it. Thanks for theinterest, though.

WT
SF
SF 2009-02-11
i was actually having this same problem as you wayne

some times i would want the bend lines and some times i wouldnt,depends if our bender had a parrallel edge to zero from

i actually had a macro set up and i believe its in the "tools,options" world dialogue box to "see" the bend lines, that way anyold flat pattern will have all of the bend lines that go with it,BUT if i didnt want them i would have to hide the layer, so i wrotea macro in autocad to select that layer and either hide it orchange its color so then i could import it with a set map into ourother program to code it for the the laser or waterjet or plasmacutter

90% of the time i didnt need the bend lines so i mostly just keptthem off

the last thing i needed to do for my code was make a form with alist box together so i could have solidworks open all of the partsfor me and run the macro, save and close and then do the same thingfor autocad

my macro also saves the file as a ".dxf" of the same name in thesame folder on the network so if you want i can find it and post iton here
JM
JM 2009-03-28

Ben Guenther wrote:

 

The code that I last posted does that do what you wanted ?

hello ben,

You seem the man to talk to about marcos.

what wayne is talking about is exactly what i required. could youpost it as a swp file. sorry i ant a code writer. .

will this marco. do (could)the following in one click?

save a pdf version of the drawing
save a profile drawing in 1:1 scale dxf format removing all linesand boarders.
save the profile (if it is a folded part)with etch lines where thefold lines are.
save the solidworks drawing.
can the location of each format dxf/pdf/solidwork drawing be saveda set location

i sorry it a long list. but life would be easiler if this waspossible.....


JOhn

SF
SF 2009-03-30
SF
SF 2009-04-07
In 09Sp3.0, saving a macro with remove bend lines selected,and yet another with this option unselected we see the same code:

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swPart = swApp.NewPart()
Part.SheetPrevious
Part.SheetNext
boolstatus = Part.ExportFlatPatternView("C:\Flat pattern -MCQUICA2S00A03.DXF", 1)
longstatus = Part.SaveAs3("C:\Flat pattern - MCQUICA2S00A03.DXF",0, 0)
End Sub


We can see that nothing is changed on the macro code, but the linesDO disappear. Also they are using an obsolete function, becausethey suggest replacing SaveAs3 with ImodelDocExtension.SaveAs...
When I try to use the SaveAs function, I always get Error 256(invalid extension) even though the file is created.

I've been trying to save a dxf from a flatten part for some timeago, and I don't see in a near future a way to do it...
SF
SF 2009-04-08
I was lead to believe that there was an enhancement in 2008to do this automatically?
SF
SF 2009-04-10

nigel bowen wrote:

 

I was lead to believe that there was an enhancement in 2008 todo this automatically?

The function is availabe in the API. However I can't seem tomake it work properly.
The DXF file always end up with the bend lines.


My mistake, the bend lines never appear. I've tried with thefollowing test running from a addin:

IModelDoc2 doc = (ModelDoc2)SwApp.ActiveDoc;
var finalName = @"c:\teste.dxf";
try
{
var Part = (PartDoc)doc;
Part.ExportFlatPatternView(@finalName, 0);
}
catch (Exception e)
{
Console.WriteLine(e);
}
SF
SF 2009-10-26
Not sure if this will help but you will need to use the "Torch Map File Profile" for the dxf export map file. Then you can use the macro that I have. If you rename your machined features in your tree to start with Machined it will suppress them so they are not part of your flat pattern. The object lines will come out green and the bend lines will be cyan. Also I commented out my code for Enterprise PDM actions. I hope this helps.
SF
SF 2009-10-27
Haven't read all the replys just the original question. Take a look at my forum in the repository for a macro to automatically create a flat patterned drawing sheet, remove (or if you modify it toggle) the bend lines, save out 1:1 DXF, then delete the sheet afterwards (or optional again).
DC
DC 2010-12-22

my macro

  • slddrw may conent more than 2 sheet, but name of sheet with  flat-pattern view must have "DXF" or "dxf" first letters.
  • flat-pattern view must have an attached note, note is a "PartNo_Description"

I've wrote code BatchProcess for generate dxf-files, but i've one problem. The macro  not scanning sub-folders for selected folder.