Can anybody help?????
(I know that this subject has been asked about several times before)
I have the following macro that flatterns a sheet metal component, then exports it as a DXF file.
However,
it is the SaveAs2 that is not working. I DO NOT KNOW WHY!!!
Sub main()
Set swApp = Application.SldWorks
Dim Doc As PartDoc
Set oDoc = swApp.ActiveDoc
swApp.ActiveDoc.ActiveView.FrameState = 1
boolstatus = oDoc.Extension.SelectByID2("Flat-Pattern2", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
oDoc.ClearSelection2 True
oDoc.SetBendState 2
oDoc.EditRebuild
TempFileName = "C:\\Temp.dxf"
oDoc.SaveAs2 TempFileName, 0, True, True
oDoc.SetBendState 3
oDoc.EditRebuild
End Sub
Has anybody any idea what I am doing wrong?
Many thanks in advance!!!
Darren
SolidworksApi macros
Well, SaveAs2 was replaced about 10 years ago. ModelDocExtension.SaveAs has been available since SolidWorks 2007 SP1
I should try that first.
Try Changing
Dim Doc As PartDoc
to
Dim oDoc As PartDoc
But for a better macro use the latest decelerations and syntaxs
I tried changing Doc to oDoc without success!
Therefore, using the code below, can you please modify it for me to show the correct code?
Sub main()
Set swApp = Application.SldWorks
Dim Doc As PartDoc
Set oDoc = swApp.ActiveDoc
oDoc.ClearSelection2 True
oDoc.SetBendState 2
oDoc.EditRebuild
TempFileName = "C:\Temp.dxf"
ModelDocExtension.SaveAs ?????
oDoc.SetBendState 3
oDoc.EditRebuild
End Sub
Many thanks for your help!!!!
Regards
Darren
Option Explicit
Option Compare Text
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim myDoc As ModelDoc2
Dim myPart As PartDoc
Dim TempFileName As String
Dim errors As Long
Dim warnings As Long
Dim myExportData As ExportPdfData
Dim varAlignment As Variant
Dim dataAlignment(11) As Double
dataAlignment(0) = 0#
dataAlignment(1) = 0#
dataAlignment(2) = 0#
dataAlignment(3) = 1#
dataAlignment(4) = 0#
dataAlignment(5) = 0#
dataAlignment(6) = 0#
dataAlignment(7) = 1#
dataAlignment(8) = 0#
dataAlignment(9) = 0#
dataAlignment(10) = 0#
dataAlignment(11) = 1#
varAlignment = dataAlignment
Set myDoc = swApp.ActiveDoc
Set myPart = myDoc
myDoc.ClearSelection2 True
myPart.SetBendState 2
myDoc.EditRebuild
TempFileName = Replace(myDoc.GetPathName, ".sldprt", ".dxf")
myPart.ExportToDWG TempFileName, myDoc.GetPathName, 1, True, varAlignment, False, False, 13, Null
myDoc.SetBendState 3
myDoc.EditRebuild
End Sub
Hi Darren,
You should be using ExportToDWG Method (IPartDoc) for this, sample code is available at the following link,
http://help.solidworks.com/2012/English/api/sldworksapi/Export_Part_To_DWG_Example_VB.htm
In the code just change file extension "dwg" to "dxf"
add macro