Change dxf export options in macro

Change dxf export options in macro

Anonymous
Not applicable
1,334 Views
8 Replies
Message 1 of 9

Change dxf export options in macro

Anonymous
Not applicable

I have a macro that looks through an assembly and creates drawings based off of the flat patterns for sheet metal parts and then exports them as dxf's.  I was wondering if there was a way to change the dxf export settings so that it puts all the interior and outer profiles on one layer and puts up and down bends on the same layer.  I also want it to omit tangent lines and arc centers.  I don't know if this is possible but any help would be greatly appreciated. 

0 Likes
Accepted solutions (2)
1,335 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

Someone corrected me on a different post so I just want to clarify that this is actually a Ilogic rule not a macro.

Here is the rule.

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument

oAsmDoc = ThisApplication.ActiveDocument

oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)



'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then

	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	
	Exit Sub
	
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then

	Return
	
	Else
	
End If

oPath = ThisDoc.Path

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

oContext = ThisApplication.TransientObjects.CreateTranslationContext

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'get DXF target folder path
oFolder = oPath & "\" & oAsmName & " DXF Files"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then

    System.IO.Directory.CreateDirectory(oFolder)
	
End If
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator

oRefDocs = oAsmDoc.AllReferencedDocuments

Dim oRefDoc As Document


'work the the drawing files for the referenced models
'this expects that the model has been saved
		For Each oRefDoc In oRefDocs
			
			iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"

    		'check that model is saved
			If(System.IO.File.Exists(iptPathName)) Then
			
                Dim oDrawDoc As PartDocument
				
                oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)
				
            	oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
				
				Try
				
                	'Set the DXF target file name
                	oDataMedium.FileName = oFolder & "\" & oFileName & ".dxf"
				
					Dim oCompDef As SheetMetalComponentDefinition
				
					oCompDef = oDrawDoc.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_OUTER_PROFILE"

					
					oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
				
					'just for check its works coretcly
					'i=MessageBox.Show(oDataMedium.FileName, "Title",MessageBoxButtons.OKCancel)
					
					'MessageBox.Show(i,"title",MessageBoxButtons.OK)
				
					'If i=2 Then
				
						'Exit Sub
				
					'End If

					oCompDef.FlatPattern.ExitEdit
				
				Catch
				
				End Try
                
				oDrawDoc.Close
				
			Else
					
			End If
			
		Next
0 Likes
Message 3 of 9

Anonymous
Not applicable

I did some more reading and realized that what I want is a macro and not an Ilogic rule so if anyone could help modify this to work as a macro that would be extra helpful.

0 Likes
Message 4 of 9

Anonymous
Not applicable
Accepted solution

Anyone else looking for an answer to this, if you manually export as dxf you can then change the layers and other settings and save it so it does it on all future exports.  

0 Likes
Message 5 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Anonymous,

 

Hoping that below VBA macro may be helpful.

Sub Export_Sheetmetal()
    'define the active document as an assembly file
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    
    Dim oAsmName As String
    oAsmName = Left(oAsmDoc.displayname, Len(oAsmDoc.displayname) - 4)
    
    
    
    'check that the active document is an assembly file
    If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
        
        MsgBox ("Please run this rule from the assembly file.")
        Exit Sub
        
    End If
    
    'get user input
    Result = MsgBox("This will create a DXF file for all of the asembly components that are sheet metal." _
    & vbLf & "This rule expects that the part file is saved." _
    & vbLf & " " _
    & vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
    & vbLf & "This could take a while.", vbYesNo, "iLogic  - Batch Output DXFs ")
    
    If Result = vbNo Then
    
        Exit Sub
        
    End If
    
    Dim oPath As String
    Dim iSplit As Integer
    
    iSplit = InStrRev(oAsmDoc.FullDocumentName, "\")
    
    oPath = Left(oAsmDoc.FullDocumentName, iSplit - 1)
     
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    
    'get DXF target folder path
    Dim oFolder As String
    oFolder = oPath & "\" & oAsmName & " DXF Files"
    
    'Check for the DXF folder and create it if it does not exist
    If Not System.IO.Directory.Exists(oFolder) Then
    
        System.IO.Directory.CreateDirectory (oFolder)
        
    End If
    '- - - - - - - - - - - - -
    
    '- - - - - - - - - - - - -Component  - - - - - - - - - - - -
    'look at the files referenced by the assembly
    Dim oRefDocs As DocumentsEnumerator
    
    Set oRefDocs = oAsmDoc.AllReferencedDocuments
    
    Dim oRefDoc As Document
    Dim iptPathName As String
    
    'work the the drawing files for the referenced models
    'this expects that the model has been saved
    For Each oRefDoc In oRefDocs
    
        If oRefDoc.DocumentSubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
    
            Dim oDrawDoc As PartDocument
            
            Set oDrawDoc = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, True)
            
            oFileName = Left(oRefDoc.displayname, Len(oRefDoc.displayname) - 4)
            
            'Set the DXF target file name
            oDataMedium.FileName = oFolder & "\" & oFileName & ".dxf"
        
            Dim oCompDef As SheetMetalComponentDefinition
        
            Set oCompDef = oDrawDoc.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_OUTER_PROFILE"
    
            
            Call oCompDef.DataIO.WriteDataToFile(sOut, oFolder & "\" & oFileName & ".dxf")
        
            'just for check its works coretcly
            'i=MessageBox.Show(oDataMedium.FileName, "Title",MessageBoxButtons.OKCancel)
            
            'MessageBox.Show(i,"title",MessageBoxButtons.OK)
        
            'If i=2 Then
        
                'Exit Sub
        
            'End If
    
            oCompDef.FlatPattern.ExitEdit
            
            oDrawDoc.Close
            
        End If
    Next
End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 9

wCorreiaHBYAR
Explorer
Explorer
Hi Chandra, It shows error on this a line: "If Not System.IO.Directory.Exists(oFolder) Then"

Please let know if there is a quick fix for this one.
0 Likes
Message 7 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@wCorreiaHBYAR,

 

Code should be fine. Please make sure that "oFolder" does not contain any special character in it.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 9

wCorreiaHBYAR
Explorer
Explorer

wCorreiaHBYAR_0-1646839976064.png

Thank you Chandra, there are no special letters. 

0 Likes
Message 9 of 9

kelvincosta
Participant
Participant

could you please share the original macro that looks throuhg the assembly and create the dxf file. I need those dxf file with the flat pattern face to send to my supplier to cut the plates

0 Likes