Help make Ilogic for dxf export work.

Help make Ilogic for dxf export work.

Anonymous
Not applicable
7,094 Views
37 Replies
Message 1 of 38

Help make Ilogic for dxf export work.

Anonymous
Not applicable

I have been working on making an Ilogic rule to create dxf's of all sheet metal parts with the Vendor "LASER" in an assembly and then export and sort them based on thickness and material.  @kevinv has done most of the work on the rule and it runs on his end using Inventor 2020 but for me using Inventor Pro 2018 there is no error code but it doesn't create the files.  If anyone using Inventor 2018 could try to help make it work that would be greatly appreciated.  

0 Likes
7,095 Views
37 Replies
Replies (37)
Message 2 of 38

Sergio.D.Suárez
Mentor
Mentor

Hi, I think the error is in the equality where it is detailed in red. I have Inv 2018 and it has worked for me.

 

Sub Main()
    
    Dim New_Folder_Path As String = ThisDoc.Path
	
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument  
    
    My.Computer.FileSystem.CreateDirectory(New_Folder_Path)
    
    'Ask user for REV level
    Dim Rev_Level As String = ""
    Rev_Level = InputBox ("Enter Rev Level","Creating DXF files For Entire Assembly")
    
    Dim Count_up As Integer = 0
    
    Dim Gauge_Folders(12) As String
    
    Dim Ga As String
    
    Dim doc As Document
	
	Dim R_Part As String
	
	Dim oMaterial As Material
    
    For Each doc In oAsmDoc.AllReferencedDocuments 

        If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
			
			Try
		
				R_Part = doc.DisplayName
					
				oMaterial = doc.ComponentDefinition.Material
					
				Gauge_Path = New_Folder_Path & "\" & Parameter(R_Part, "Thickness") & " " & oMaterial.Name			
						
						
					If UCase(iProperties.Value(R_Part, "Project", "Vendor")) = "LASER" Then	' If doc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value= "LASER" Then


						Try
							My.Computer.FileSystem.CreateDirectory(Gauge_Path)						
						Catch
						End Try
						
		            	Call Make_DXF(doc, Rev_Level, Gauge_Path)
					End If				
		
			Catch
			End Try		
		
		End If

    Next 
	
MsgBox("DXF Export Complete",,"All Done")		
    
End Sub
    
Sub Make_DXF(doc As Document, Rev_L As String, File_Location As String)
    				
    Dim oSheetMetalCompDef As SheetMetalComponentDefinition
    oSheetMetalCompDef = doc.ComponentDefinition
                
    Dim Part_Name As String = doc.DisplayName
    Dim TestPos As Integer = 0
    
    ' Create flat pattern if none
    If Not oSheetMetalCompDef.HasFlatPattern = False Then
        ' Open document
        openDoc = ThisApplication.Documents.Open(doc, False)
        ' Unfold part
        oSheetMetalCompDef.Unfold()
        ' Exit flat pattern
        oSheetMetalCompDef.FlatPattern.ExitEdit()
        ' Close document
        openDoc.Close()
    End If

        Dim Rev_Adder As String = ""
        If Rev_L <> "" Then Rev_Adder = " REV " & Rev_L
        
        TestPos = InStr(1, Part_Name, ".")
        
        If TestPos <> 0 Then 
            Part_Name = Left(Part_Name, InStr(Part_Name, ".")-1)
        End If

        Dim New_Name As String = Part_Name 
    
        Dim nameandpath As String = File_Location & "\" & New_Name & Rev_Adder & ".dxf"

        Dim oDataIO As DataIO = doc.ComponentDefinition.DataIO
        oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=R12&RebaseGeometry=True&SimplifySpline=True&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL&SplineToleranceDouble=0.01",nameandpath)

End Sub

 I have removed some lines of code that were unnecessary.
I hope it helps to solve 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

0 Likes
Message 3 of 38

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide sample input assembly and expected output dxf files with folder structure (Sorted thickness and material) ? Which are exported through manual tasks.

 

Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 38

kevinv
Enthusiast
Enthusiast

If you change that to [= False] the you should probably remove the [Not] at the beginning of that line

0 Likes
Message 5 of 38

Sergio.D.Suárez
Mentor
Mentor

You're right, but I do not know why, but it works like that. Here you have another code that should work

 

Sub Main()
    
    Dim New_Folder_Path As String = ThisDoc.Path
	
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument  
    
    My.Computer.FileSystem.CreateDirectory(New_Folder_Path)
    
    'Ask user for REV level
    Dim Rev_Level As String = ""
    Rev_Level = InputBox ("Enter Rev Level","Creating DXF files For Entire Assembly")
    
    Dim Count_up As Integer = 0
    
    Dim Gauge_Folders(12) As String
    
    Dim Ga As String
    
    Dim doc As Document
	
	Dim R_Part As String
	
	Dim oMaterial As Material
    
    For Each doc In oAsmDoc.AllReferencedDocuments 

        If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
			
			Try
		
				R_Part = doc.DisplayName
					
				oMaterial = doc.ComponentDefinition.Material
					
				Gauge_Path = New_Folder_Path & "\" & Parameter(R_Part, "Thickness") & " " & oMaterial.Name			
						
						
					If UCase(iProperties.Value(R_Part, "Project", "Vendor")) = "LASER" Then	' If doc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value= "LASER" Then


						Try
							My.Computer.FileSystem.CreateDirectory(Gauge_Path)						
						Catch
						End Try
						
		            	Call Make_DXF(doc, Rev_Level, Gauge_Path)
					End If				
		
			Catch
			End Try		
		
		End If

    Next 
	
MsgBox("DXF Export Complete",,"All Done")		
    
End Sub
    
Sub Make_DXF(doc As Document, Rev_L As String, File_Location As String)
    				
    Dim oSheetMetalCompDef As SheetMetalComponentDefinition
    oSheetMetalCompDef = doc.ComponentDefinition
                
    Dim Part_Name As String = doc.DisplayName
    Dim TestPos As Integer = 0
    
    ' Create flat pattern if none
		If oSheetMetalCompDef.HasFlatPattern = False Then 
			oSheetMetalCompDef.Unfold
			oSheetMetalCompDef.FlatPattern.ExitEdit
			oSheetMetalCompDef.Close
		End If

        Dim Rev_Adder As String = ""
        If Rev_L <> "" Then Rev_Adder = " REV " & Rev_L
        
        TestPos = InStr(1, Part_Name, ".")
        
        If TestPos <> 0 Then 
            Part_Name = Left(Part_Name, InStr(Part_Name, ".")-1)
        End If

        Dim New_Name As String = Part_Name 
    
        Dim nameandpath As String = File_Location & "\" & New_Name & Rev_Adder & ".dxf"

        Dim oDataIO As DataIO = doc.ComponentDefinition.DataIO
        oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=R12&RebaseGeometry=True&SimplifySpline=True&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL&SplineToleranceDouble=0.01",nameandpath)

End Sub

 


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

0 Likes
Message 6 of 38

kevinv
Enthusiast
Enthusiast

I agree with that edit, thanks for stepping up and helping out!

0 Likes
Message 7 of 38

Anonymous
Not applicable

I don't know why but it still doesn't create any files for me.  I have a VBA macro that works though.  I'll attach it in case anyone wants that instead.

0 Likes
Message 8 of 38

bradeneuropeArthur
Mentor
Mentor

….

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 38

Anonymous
Not applicable

It only creates them for sheet metal parts with the Vendor "LASER" if you're talking about the macro.  If you meant the Ilogic Rule it doesn't create any for me either.

0 Likes
Message 10 of 38

GICain
Contributor
Contributor

You may want to try this DXF Exporter app. I've had this implemented in the department I work in and have been mostly happy with it. 

 

Takes a little getting used to but you can export sheet metal dxf's of an entire assembly in a matter of seconds once set up is complete. 

 

You can also write your own filename extension however you want it to read. The only downside is it only pulls from a select default Inventor parameters and currently custom iProperties can't be used. 

 

Screenshot of final result attached. 

 

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=7498862835390395853&appLang=en&os=Win32_64

Gabe Cain
Structural Designer/Engineering Checker
0 Likes
Message 11 of 38

bsnyderACLUW
Enthusiast
Enthusiast

used the VBA macros to make this work for Ilogic.

just hade to get rid of a few things and add some ()'s and voila it works!!!!


 

Sub main (Export_Sheetmetal())
    'define the active document as an assembly file
    Dim oAsmDoc As AssemblyDocument
     oAsmDoc = ThisApplication.ActiveDocument
    
    Dim oAsmName As String
    oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName))
    
    
    
    '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
     oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    Dim oContext As TranslationContext
     oContext = ThisApplication.TransientObjects.CreateTranslationContext
    
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    
    Dim oOptions As NameValueMap
     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 Len(Dir(oFolder, vbDirectory)) = 0 Then
        MkDir (oFolder)
    End If
    '- - - - - - - - - - - - -
    
    '- - - - - - - - - - - - -Component  - - - - - - - - - - - -
    'look at the files referenced by the assembly
    Dim oRefDocs As DocumentsEnumerator
    
     oRefDocs = oAsmDoc.AllReferencedDocuments
    
    Dim oRefDoc As Document
    Dim iptPathName As String
    
    'work the drawing files for the referenced models
    'this expects that the model has been saved
    For Each oRefDoc In oRefDocs
    
        If oRefDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
            If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value = "" Then
                Dim oDrawDoc As PartDocument
                 oDrawDoc = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
                
                Dim oDef As SheetMetalComponentDefinition
                 oDef = oDrawDoc.ComponentDefinition
                
                Dim oThick As String
                oThick = oDef.Thickness.Value
           
           
           
                 Select Case oThick
                    Case 0.635
                         Gauge_Name = "0.25"
                    Case 0.1524
                        Gauge_Name = "16 Gauge"
                    Case 0.1905
                        Gauge_Name = "14 Gauge"
                    Case 0.3048
                        Gauge_Name = "11 Gauge"
                    Case 0.9525
                        Gauge_Name = "0.375"
                    Case 0.475996
                        Gauge_Name = "7 Gauge"
                    Case Else
                        Gauge_Name = "Other"
                End Select
                
                Dim oMaterial As String
                oMaterial = oDrawDoc.ActiveMaterial.DisplayName
                 
                oFolder = oPath & "\" & oAsmName & " DXF Files\" & Gauge_Name & "-" & oMaterial
                
                'Check for the DXF folder and create it if it does not exist
                If Len(Dir(oFolder, vbDirectory)) = 0 Then
                    MkDir (oFolder)
                End If
                
                oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
                
                '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"
        
                
                Call oCompDef.DataIO.WriteDataToFile(sOut, oFolder & "\" & oFileName & ".dxf")
            
                oCompDef.FlatPattern.ExitEdit
                
                oDrawDoc.Close
            End If
        End If
    Next
End Sub



​

 

0 Likes
Message 12 of 38

reine_den_andra
Contributor
Contributor

Hi

I'm not good at ilogic rules. Is it just to copy and paste this code into "Add rule"? I got an error message ....

0 Likes
Message 13 of 38

kevinv
Enthusiast
Enthusiast

What post are you grabbing the code from? There are a number of them above with different tweaks. The first code I see when I scroll up has some folder names in it that would need to be changed in order to match your file structure. Some of the other code above places the dxf files in the same place as the assembly. You might want to try one of those. Otherwise you will have to be more specific with what errors you are getting. 

0 Likes
Message 14 of 38

kevinv
Enthusiast
Enthusiast

I think the best code to grab is found here:

Solved: Re: Ilogic - Batch dxf from Assembly - Autodesk Community - Inventor

The code is in message 17. The only change you should have to make is the folder path at the beginning. change 

"G:\DXF\Production\"

to whatever location you want the DXFs to go. Good luck!

0 Likes
Message 15 of 38

reine_den_andra
Contributor
Contributor

Hi

I have inventor 2019.
Is it possible to make a rule so that you can get a DXF from a part to a specific folder?
This is just about sheet metal.
Option 1: If I only have one part open.
Option 2: From an assembly.
Or if it is possible to have these at the same time?
I saw your link. Is it just to copy and paste into the add rule? I get an error message that I do not understand.
 
"Error in rule: Rule4, in document: part5.ipt

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: Gränssnittet stöds inte (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

0 Likes
Message 16 of 38

kevinv
Enthusiast
Enthusiast

Thank you for the error message. The code you are using is only for an assembly file. I think the error is happening because you are running it on a part file. There may also be issues with file locations. Let me know what path you want the DXFs to land in and I will try to send you some code that will work for you, for both parts and assembles.

0 Likes
Message 17 of 38

reine_den_andra
Contributor
Contributor

Thanks for all the help with this.

We can take "C: \ DXF" only as an example in this case.

I know of course that it's just "Export Face As ..." on a flat pattern, but it would be quick and easy if there was a rule to do this.

I want to be able to export dxf if I may only have one part open or maybe one assembly open.

 

Another thing I do not understand. If you have made a rule, then it does not remain if you open something else?

How do I get it to always be in the program no matter what I open? I have another rule that is the same.

0 Likes
Message 18 of 38

kevinv
Enthusiast
Enthusiast

Over time I added features to this code that are not mentioned here in this thread. What I am posting below is a version of the code that I just simplified for you. This will work for both part files and assemblies. First thing it does is save what you are working on. Then it will ask if you want to run the rule, then ask for a revision level(you can leave that blank-just hit OK), then confirm the path for you before creating the dxf files. It will delete any previous DXFs for each file and add the material gauge to the start of the file name for sorting purposes.

 

Before I post the code let me answer your second question. In order to have the rules available to all of your files you need to set up external rules. To do that open iLogic Configuration:

kevinv_0-1616761789563.png

and then add a new External Rule Directory:

kevinv_1-1616761896765.png

Once you have done that you will see the folder show up under external rules. Any rules you create in there will be available from all of your files. If you have other users you can put that folder on a server drive and map the external directory to the same folder on the other computers. Mine looks like this:

kevinv_2-1616762093428.png

Here is the code, note the one place you will need to update the path if you want to change it is right after Gauge_Path  =

Sub Main()

	 ThisApplication.[_LibraryDocumentModifiable] = True
	
	Dim oDoc As Document
	Dim Job_confirm As String
	Dim oAsmDoc As AssemblyDocument 
	Dim Rev_Level As String = ""
	Dim New_Folder_Path As String		
	Dim Ga As String
	Dim JobNum As String = iProperties.Value("Project", "Project")
	Dim DXFPath As String
	Dim Purchased As Boolean = False
	Dim Gauge_Path As String
	

'AutoSave before rule changes anything
Try
	SaveMe = ThisDoc.Document
	SaveMe.Save
Catch
	SaveQ=MsgBox("Save did NOT happen. Do you want to run the rule anyway?",vbYesNo,"Something Went Wrong")
	If SaveQ=7 Then Exit Sub
End Try

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'^^^^EDIT PATH BELOW^^^^^^^^^^^^^^
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Gauge_Path = "C:\DXF\"

		oDoc = ThisDoc.Document
	If oDoc.DocumentType = kPartDocumentObject Then
		
		

		
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CODE FOR PART DXF - NOT ASSEMBLY%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		
		If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
			
			Job_confirm = MsgBox ("Sending File to DXF Folder " & Gauge_Path, vbOKCancel, "Confirm Path")
			If Job_confirm = "2" Then Exit Sub

			Rev_Level = InputBox("Enter Rev Level", "Creating DXF file for Single Part")
			

				'ThisApplication.ActiveDocument.BOMSTRUCTURE
				Dim oPrtCompDef As PartComponentDefinition

				oPrtCompDef = ThisApplication.ActiveDocument.ComponentDefinition
				'MsgBox(oPrtCompDef.BOMStructure)
				'Exit Sub
				Dim oSheetMetalCompDef As SheetMetalComponentDefinition
	            'set it to the current document
	            oSheetMetalCompDef = oDoc.ComponentDefinition
	            'Dim oStyle As SheetMetalStyle
				
	            Ga = oSheetMetalCompDef.ActiveSheetMetalStyle.Name
				
					'remove quotes and replace / in fractions with _
				Ga = Replace(Ga, "/", "_")
				Ga = Replace(Ga, Chr(34), "")
			
				Job_confirm = MsgBox ("Sending File to DXF Folder " & Gauge_Path ,vbOKCancel, "Confirm Path")
'MsgBox(Len(Gauge_Path))
				If Job_confirm = "2" Then Exit Sub
				
				
				
				Try					
					My.Computer.FileSystem.CreateDirectory(Gauge_Path)

					Call Make_DXF(oDoc, Rev_Level, Gauge_Path)
				Catch
					MsgBox(Gauge_Path,,"Can't create folder:")
				End Try
		
		End If
		MsgBox("DXF Export Complete",,"All Done")	
		Exit Sub	'stop code after part level export
		
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END CODE FOR PART DXF - NOT ASSEMBLY%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
		
	ElseIf oDoc.DocumentType = kAssemblyDocumentObject Then
		'Correct doc type - now move on
	
	ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
		MsgBox("This is Not the Correct Rule",,"Ending Run")
		Exit Sub
	End If

'Dim oAsmDoc As AssemblyDocument 

oAsmDoc = ThisApplication.ActiveDocument  
	
Dim doc As Document 

Job_confirm = MsgBox ("Sending Files to DXF Folder " & Gauge_Path, vbOKCancel, "Confirm Path")
'MsgBox(Job_confirm,,"job_confirm")
If Job_confirm = "2" Then Exit Sub

'Ask user for REV level
Rev_Level = InputBox ("Enter Rev Level","Creating DXF files For Entire Assembly")

Dim Count_up As Integer = 0

Dim Gauge_Folders(40) As String

Count_up = 0


'Now we loop through all of the parts checking for sheetmetal parts and creating DXF files
'oAsmDoc = ThisApplication.ActiveDocument 
	For Each doc In oAsmDoc.AllReferencedDocuments 

	Try
		If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
		
			Call Make_DXF(doc, Rev_Level, Gauge_Path)

		End If
		
		Count_up = Count_up + 1
		
	Catch
		MsgBox(doc.FullDocumentName)
	End Try
	
	Next 

MsgBox("DXF Export Complete",,"All Done")	
 
End Sub


Sub Make_DXF(doc As Document, Rev_L As String, File_Location As String)
'''-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF
'''-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF
'''-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF-----MAKE DXF


			Dim oSheetMetalCompDef As SheetMetalComponentDefinition
            'set it to the current document
            oSheetMetalCompDef = doc.ComponentDefinition
            'Dim oStyle As SheetMetalStyle
			Dim GA_Adder As String = oSheetMetalCompDef.ActiveSheetMetalStyle.Name



'Dim GA_Adder As String = iProperties.Value(doc.DisplayName, "Custom", "GAUGE")
			GA_Adder = Replace(GA_Adder, "/", "_")
			GA_Adder = Replace(GA_Adder, Chr(34), "")
			GA_Adder = Replace(GA_Adder, "%", "")
			GA_Adder = Replace(GA_Adder, ".", "")
			
Dim Part_Name As String = doc.DisplayName
Dim TestPos As Integer = 0


Dim oCompDef As SheetMetalComponentDefinition
oCompDef = doc.ComponentDefinition

	'checking for parts that don't have flat pattern and telling user what parts are skipped for lack of flat pattern
	If oCompDef.HasFlatPattern = False Then 
		MsgBox ("Skipping DXF file for:" & vbNewLine & vbNewLine & Part_Name, ,"Flat Pattern Missing")
	Else

		'Checking to be sure the name passed to sub has a . in it
		TestPos = InStr(1, Part_Name, ".")
		'trimming everything before the .
		If TestPos <> 0 Then Part_Name = Left(Part_Name, InStr(Part_Name, ".")-1)

		Dim New_Name As String = Part_Name
''		'*******************remove line below to remove gauge from file name***********
		Part_Name = GA_Adder & " " & Part_Name
''		'*******************remove line above to remove gauge from file name***********		

		'Creating Rev add-on for file name if needed
		Dim Rev_Adder As String = ""
		If Rev_L <> "" Then Rev_Adder = " REV " & Rev_L
		
		'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^CHECKING FOR AND DELETING OLD DXF FILES^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		Dim Old_Files As String = ""
		'Dim Delete_List(5) As String
		'Dim q As Integer = 0
		
		Old_Files = Dir(File_Location & "\" & Part_Name & "*")
		Do Until Old_Files = ""
			Try
				Kill(File_Location & "\" & Old_Files)
			Catch
				MsgBox("Could Not Delete:"  & vbNewLine & vbNewLine & File_Location & "\" & Old_Files,,"Delete Error")
			End Try
			Old_Files = Dir()
		Loop
		


		'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^END CHECKING FOR AND DELETING OLD DXF FILES^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
			
			
		
		Dim nameandpath As String = File_Location & "\" & Part_Name & Rev_Adder & ".dxf"
		

		nameandpath = File_Location & "\" & Part_Name & Rev_Adder & ".dxf"

		
		
		'MsgBox(nameandpath)
		Dim oDataIO As DataIO = doc.ComponentDefinition.DataIO

		'Create the DXF file now!
		Try
		oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=R12&RebaseGeometry=True&SimplifySpline=True&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL&SplineToleranceDouble=0.01",nameandpath)
		Catch
			MsgBox (nameandpath,,"Error on this file")
		End Try
	End If
End Sub

 

Message 19 of 38

kevinv
Enthusiast
Enthusiast

Looks like I replied to the wrong message, see my answer in reply to Eric

0 Likes
Message 20 of 38

reine_den_andra
Contributor
Contributor

Hi

"Once you have done that you will see the folder show up under external rules"

Where do I find this?

EDIT: I found. I understand. I've never done this before.

0 Likes