Export Current Part Flat Pattern to DXF with Custom name

Export Current Part Flat Pattern to DXF with Custom name

vkulikajevas
Advocate Advocate
497 Views
1 Reply
Message 1 of 2

Export Current Part Flat Pattern to DXF with Custom name

vkulikajevas
Advocate
Advocate

I need to create Flat Patern of one opened Sheet metal and save it in this pattern:

Stock Number " " Thickness " " Material

The code works to save DXF (It is a remake of code that saves all assembly parts to DXF), the problem is in the naming. I can't seem to change the sFName to name in needed pattern. 

Can you help me with this?

 

 


Sub Main()

Dim oDoc As PartDocument

oDoc = ThisApplication.ActiveDocument

 

Dim oCompDef As SheetMetalComponentDefinition

oCompDef = oDoc.ComponentDefinition

 

If oCompDef.HasFlatPattern = False Then

oCompDef.Unfold

Else

oCompDef.FlatPattern.Edit

End If

 

Dim sOut As String

 

sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_INTERIOR_PROFILES"

 

 

' Get document's full file name

Dim sFname As String

sFname = oDoc.FullFileName

 

' The file format will depend on the extension

' Set file name extension to ".DXF"

sFname = Left$(sFname, Len(sFname) - 3) & "dxf"

 

oCompDef.DataIO.WriteDataToFile( sOut, sFname)

 

End Sub

0 Likes
Accepted solutions (1)
498 Views
1 Reply
Reply (1)
Message 2 of 2

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, try the following code, I think it does what you need. Run it in a sheet metal file

	Dim oDoc As Document = ThisDoc.Document

	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
		
		If oCompDef.HasFlatPattern = False Then 
			oCompDef.Unfold
		Else
			oCompDef.FlatPattern.Edit
		End If
			
		Try
			oMaterial = oDoc.ComponentDefinition.Material.Name
			oThickness = Round(oDoc.ComponentDefinition.Thickness.value*10, 2)'Convert cm to inch
			oStockNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value

			Dim oFilename As String  = ThisDoc.Path & "\" &  oStockNumber  & "_" & oThickness  & "_" & oMaterial & ".dxf"
			
			MessageBox.Show(oFilename)
			
			Dim oDataIO As DataIO = oDoc.ComponentDefinition.DataIO
    		oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_INTERIOR_PROFILES", oFilename)
			oCompDef.FlatPattern.ExitEdit
		Catch
		End Try		
	End If	

 

I hope this helps with your problem. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn