Macro for Part to Flat Pattern DXF?

Hi,

I have a few questions please... hope this makes sense:

I need a Macro (or whatever) that can take a SolidWorks Sheetmetal Part file and generate a DXF Flat Pattern. It can work in two parts, i.e. generate a SW Drawing file first then a macro for DXF...

I have no idea if this is hard or easy, but if it can be done it will save me from having to do a boring job of converting 100 or so part files to 1:1 flat DXF's - yuk!

I have searched and not found an answer to this...

Any Macros or third party software out there? but preferably free or low priced.

If not is there software to automate generate flat patterns or better yet punch files (assign the tools etc) directly from a SW part file. Currently we take the part file, create a drawing file. save it and a DXF copy, import it to the sheetmetal software, then use it to assign tools, prints punch lists...

Thanks for your input,

Aron

Reply to
Aron (bacsdesign.com)
Loading thread data ...

Yes, this can be done with a macro. If you were to attempt writing it yourself, you might start by recording a macro, running through the process and then modifying the macro to suit your needs.

I have such a macro, but it is configured for our file structure and uses a database for file references. I can be reached at 541.482.9555 x 319 if you need some help or would like to contract me to write a macro.

Dave

Reply to
Dave

Set up a blank drawing sheet, set view to hide all types, and in tools/ options document properties under sheet metal, uncheck display sheet metal bend notes. Save this as a drawing template - maybe call it flat pattern - in your normal template folder.

Open the sheet metal part file, then, File/make drawing from part, drag the flat pattern onto the sheet, hit esc. Then with that view highlighted, edit/copy to dwgeditor. Put you cursor in the dwgeditor window, ctrl-v, then save the dxf. At least the first couple times do a reality check to make sure your dxf is scaled correctly.

You should be able to either macro most or all of this, or set keyboard shortcuts for each command. It can go really fast.

Most punch and nesting software can auto-tool your parts.

Good luck, Diego

Reply to
Diego

Here is what I use. Let me know if it needs explaining. Brian

' ****************************************************************************** ' Written by Brian Putnam on 12/30/2004 ' This code creates a DXF file of a part that has a flat pattern. ' It should be added to in the future to create a DXF of a flat ' part that does not have a flat pattern. ' ****************************************************************************** Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Dim swModel As SldWorks.ModelDoc2 Dim docName As String Dim docType As String Dim ThreeDigit As String

Sub main()

Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc

'Check that the current model is a part ' Constant enumerators Const swDocPART = 1 Const swDocASSEMBLY = 2 Const swDocDRAWING = 3 If (swModel.GetType swDocPART) Then If (swModel.GetType swDocDRAWING) Then swApp.SendMsgToUser ("This is not a part") Exit Sub Else Call OpenModel(docName, docNameShort1) End If Else 'Get the name of the currently active model docName = swModel.GetPathName Let docNameShort1 = swModel.GetTitle End If Let docNameShort1 = swModel.GetTitle 'Determine if the part is a sheet metal part. nBendState = swModel.GetBendState

'This is from the macro I originally recored. 'Create a new drawing with sheet 2 meters x 1 meter 'Rugby DXF 3 was picked because it does not display tangent lines or dimensions automatically. Set Part = swApp.NewDocument("S:\SolidWorks Files\Solidworks Data\Templates\Rugby DXF 3.drwdot", 12, 2, 1) Dim DrawView As Object 'Put flat pattern at center of new sheet If nBendState swSMBendStateNone Then 'Part is sheetmetal Part.CreateFlatPatternViewFromModelView docName, "Default", 1, 0.5, 0 Part.DrawingViewRotate -1.5708 Else 'Part is not sheetmetal Set DrawView = Part.CreateDrawViewFromModelView2(docName, "*Front",

1, 0.5, 0) End If

Part.ViewZoomtofit2 'Get the name of the drawing file that was just created. This is so you can close the file later. Call ModelInfo(DrawName)

'Now export the dxf file Set Part = swApp.ActiveDoc swApp.SetUserPreferenceToggle 26, 1 'This sets the options for how the file is saved.

'Need to save it in acaddwg\dxf\23456.dxf 'Try to figure out a default name ThreeDigit = Mid(docNameShort1, 3, 1) If (ThreeDigit = " ") Then 'Check for a space between after the 2nd digit ex.12 3456 docNameShort3 = Mid(docNameShort1, 2, 1) + Mid(docNameShort1, 4, 4) Else docNameShort3 = Mid(docNameShort1, 2, 5) End If

docNameShort2 = InputBox("Enter name for DXF file. Use the 23456 format.", "DXF Name", docNameShort3) Part.SaveAs2 "S:\acaddwg\dxf\" & docNameShort2 & ".DXF", 0, True, False Set Part = Nothing 'Need to close drawing that was just created swApp.CloseDoc DrawName 'swApp.ActiveDoc.ActiveView.FrameLeft = 0 'swApp.ActiveDoc.ActiveView.FrameTop = 0 'swApp.ActiveDoc.ActiveView.FrameState = 1 'swApp.ActiveDoc.ActiveView.FrameState = 1 'Set Part = swApp.ActivateDoc("03 1676.SLDPRT")

End Sub

*************************************************************** Sub OpenModel(docName, docNameShort1)

'This is copied from "Get Document Referenced by Drawing View (VB)" example. 'Edited by Brian Putnam 2005 'Dim swModel As SldWorks.ModelDoc2 Dim swSelMgr As SldWorks.SelectionMgr Dim swView As SldWorks.View Dim swDrawModel As SldWorks.ModelDoc2 Dim sModelName As String

Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swSelMgr = swModel.SelectionManager Set swView = swSelMgr.GetSelectedObject5(1) Set swDrawModel = swView.ReferencedDocument

sModelName = swView.GetReferencedModelName docName = swView.GetReferencedModelName Let docNameShort1 = swModel.GetTitle

'Now open this part model. Set Part = swApp.ActivateDoc(sModelName) 'Set Part = swApp.IActivateDoc3(sModelName, True, nRetval): Debug.Assert

0 = nRetval 'Let docNameShort1 = swModel.GetTitle

'Close the drawing swApp.CloseDoc swModel.GetTitle 'can I get part title now? 'Let docNameShort1 = swModel.GetTitle

End Sub

Ar> Hi,

Reply to
Brian Putnam

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.