Ilogic - Batch dxf from Assembly

Ilogic - Batch dxf from Assembly

Anonymous
Not applicable
4,453 Views
32 Replies
Message 1 of 33

Ilogic - Batch dxf from Assembly

Anonymous
Not applicable

Hi All,

I am having problems with a code.

I am trying to make a dxf from each sheet metal part in an assembly with ilogic: (I have cut and and paste diffrent codes from this forum in an poor atempt...)

 

Sub Main
Dim oApp As Inventor.Application = ThisApplication
Dim oAssy As Inventor.AssemblyDocument = oApp.ActiveDocument

For Each oSubDoc as Inventor.Document In oAssy.AllReferencedDocuments
If oSubDoc.DocumentType = kPartDocumentObject Then
Dim oPartPropset As Inventor.PropertySet = oSubDoc.PropertySets("Design Tracking Properties")
Dim oPartParam As Inventor.PropertySet = oSubDoc.PropertySets("Inventor User Defined Properties")

Dim oParameter As Parameter
For Each oParameter In oSubDoc.ComponentDefinition.Parameters
oParameter.ExposedAsProperty = True
Next oParameter

If oSubDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
DefaultChoice = True
CADline()


Else
' here is code for normal parts
' .................

End If
End If

Next

oAssy = Nothing
oApp = Nothing


End Sub
Public Sub CADline()
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=R12&OuterProfileLayer=IV_INTERIOR_PROFILES"
Dim sFname As String
sFname = oDoc.FullFileName
sFname = Left$(sFname, Len(sFname) - 3) & "dxf"
oCompDef.DataIO.WriteDataToFile( sOut, sFname)
oDoc = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit
End Sub
Accepted solutions (1)
4,454 Views
32 Replies
Replies (32)
Message 21 of 33

Anonymous
Not applicable

When I try using your code it pops up with an error saying that I need to add a job# to iproperties.  I tried adding a custom one in the BOM but that didn't work.  When I go to the Iproperties I don't see anything labeled as the job # could you clarify what I need to do here to make it work.

0 Likes
Message 22 of 33

kevinv
Enthusiast
Enthusiast

Good catch.  We use the iProperties “Project” for job number.  That number is used to sort the DXFs into job folders on our production server.  Feel free to modify the code to remove the need for Job # and locate the DXFs wherever you want them.

 

edit: based on your question I am guessing that you are new to iLogic?  Let me know if you need help modifying the code to place the DXF files where you want them.

 

BTW - we still use this code all the time. I have written over 40 iLogic rules for the company now, all of them are helpful but none as helpful as this one!

 

0 Likes
Message 23 of 33

Anonymous
Not applicable

You're right I am new to this. Is there any way you could make it create a new folder in the same location as the dxf? I appreciate your offer to help.

0 Likes
Message 24 of 33

kevinv
Enthusiast
Enthusiast

No Problem, happy to help.  I am not sure I am following your question though.  The code will create a new folder for your DXFs to land in based on how you define New_Folder_Path.  The code example from reply 17 in this thread places the DXFs on my G: drive in a folder that might not exist yet (based on possible new job #).  That folder is created before the DXFs are made.

 

So I think it is doing what you want but I am guessing you will need the path fixed?  

 

Please explain a little further what you are looking for.

 

0 Likes
Message 25 of 33

Anonymous
Not applicable

Sorry I didn't understand that the code already made a folder.  I would just like to have it put the folder in the same place as the assembly if that's possible. As well as no longer needing the job#.  Thanks again for your help.

0 Likes
Message 26 of 33

kevinv
Enthusiast
Enthusiast

Sorry for the confusion, I think I understand what you want now.  This will add the DXF Files to gauge folders right where the assembly is saved.  Hope this helps:

 

edit: just make sure you don't have any characters in the names of your Sheet Metal Rules that can't be in file or folder names.  I did, so this code will do a replace for "/" or inch marks (").  Any others will cause errors and you will have to do a Replace on those as well to get rid of the errors.

 

Sub Main()
    
    Dim New_Folder_Path As String = ThisDoc.Path
        
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument  
    
'    Dim Job_confirm As String
'    Job_confirm = MsgBox ("Sending Files to DXF Folder " & iProperties.Value("Project", "Project"),vbOKCancel, "Confirm Job #")
'    If Job_confirm = "2" Then Exit Sub
    
    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
    
    For Each doc In oAsmDoc.AllReferencedDocuments 

        If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
            Dim oSheetMetalCompDef As SheetMetalComponentDefinition
            oSheetMetalCompDef = doc.ComponentDefinition
            Ga = oSheetMetalCompDef.ActiveSheetMetalStyle.Name

            Ga = Replace(Ga, "/", "_")
            Ga = Replace(Ga, Chr(34), "")
                    
            If UBound(Filter(Gauge_Folders, Ga)) > -1 Then
            Else    
                Gauge_Folders(Count_up) = Ga
                Gauge_Path = New_Folder_Path & "\" & Ga
                My.Computer.FileSystem.CreateDirectory(Gauge_Path)
            End If
        End If
    
    Next 
    ReDim Preserve Gauge_Folders(Count_up)
    For i = LBound(Gauge_Folders) To UBound(Gauge_Folders) 
        msg = msg & Gauge_Folders(i) & vbNewLine 
    Next i 
    
    MsgBox ("Adding DXF files to Folders:" & vbNewLine & vbNewLine & msg, ,"Gauges Found")
    
    Count_up = 0
    
    For Each doc In oAsmDoc.AllReferencedDocuments 
        If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
            Call Make_DXF(doc, Rev_Level, New_Folder_Path)
        End If
        Count_up = Count_up + 1
    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 GA_Adder As String = oSheetMetalCompDef.ActiveSheetMetalStyle.Name
    
    GA_Adder = Replace(GA_Adder, "/", "_")
    GA_Adder = Replace(GA_Adder, Chr(34), "")
                
    Dim Part_Name As String = doc.DisplayName
    Dim TestPos As Integer = 0
    
    'checking for parts that don't have flat pattern and telling user what parts are skipped for lack of flat pattern        
    part = doc.ComponentDefinition.Document.FullDocumentName
    
    ' Create flat pattern if none
    If Not oSheetMetalCompDef.HasFlatPattern() Then
        ' Open document
        openDoc = ThisApplication.Documents.Open(part,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
'        '*******************remove line below to remove gauge from file name***********
        New_Name = GA_Adder & " " & New_Name
'        '*******************/remove line above to remove gauge from file name**********       
    
        Dim nameandpath As String = File_Location & "\" & GA_Adder & "\" & 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

 

Message 27 of 33

Anonymous
Not applicable

This sounds like it's exactly like what I need. I'll try it when I get to work. Thanks for all your help.

Message 28 of 33

kevinv
Enthusiast
Enthusiast

New code that works a bit different. 

 

This creates all DXFs within an assembly that have the Vendor iProperties set to "Laser"

 

The DXF Files are located in subfolders at the location of the saved assembly file sorted by a Parameter named "Thickness" and Material type for each part.

 

Sub Main()
    
    Dim New_Folder_Path As String = ThisDoc.Path
	
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = 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 
			
			R_Part = doc.DisplayName
			
			oMaterial = doc.ComponentDefinition.Material
			
			Gauge_Path = New_Folder_Path & "\" & Parameter(R_Part, "Thickness") & " " & oMaterial.Name			
				
			If iProperties.Value(R_Part, "Project", "Vendor") = "Laser" Then	
				Try
					My.Computer.FileSystem.CreateDirectory(Gauge_Path)						
				Catch
				End Try
				
            	Call Make_DXF(doc, Rev_Level, Gauge_Path)
			End If				

        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
        
    part = doc.ComponentDefinition.Document.FullDocumentName
    
    ' Create flat pattern if none
    If Not oSheetMetalCompDef.HasFlatPattern() Then
        ' Open document
        openDoc = ThisApplication.Documents.Open(part,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
0 Likes
Message 29 of 33

Anonymous
Not applicable

When I tried to run this it popped up with an error window saying

"Error in rule: Create DXF Sort Thickness Material, in document: "Assembly Name"

Parameter: The component named "File Name of a Sheet Metal Part" was not found."

0 Likes
Message 30 of 33

Anonymous
Not applicable

Sorry for asking, is it possible to save all the Dxf file in 2010 version?

0 Likes
Message 31 of 33

kevinv
Enthusiast
Enthusiast

Yes, you sure can look for this line near the bottom:

 

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)

 

change AcadVersion=R12 to AcadVersion=2010

 

I just tested it, that is all you need to do.

0 Likes
Message 32 of 33

ktsaleej
Enthusiast
Enthusiast
 

 

Plate and sheet development  

 

In here you can generate AutoLISP(.lsp) program to draw the development of geometric shapes in AutoCAD. This drawing you can directly transfer to your cnc plate cutting machines to cut the plate. Just select shape which you want to draw and fill the form, You can generate your AutoLISP(.lsp) program.

Development

 

 

 

0 Likes
Message 33 of 33

ktsaleej
Enthusiast
Enthusiast

Plate and sheet development 

 

In here you can generate AutoLISP(.lsp) program to draw the development of geometric shapes in AutoCAD. This drawing you can directly transfer to your cnc plate cutting machines to cut the plate. Just select shape which you want to draw and fill the form, You can generate your AutoLISP(.lsp) program.

 

Development

0 Likes