Turn Ilogic rule to macro and make it look at bom instead of file type.

Turn Ilogic rule to macro and make it look at bom instead of file type.

Anonymous
Not applicable
1,599 Views
16 Replies
Message 1 of 17

Turn Ilogic rule to macro and make it look at bom instead of file type.

Anonymous
Not applicable

I have an Ilogic rule that looks through an assembly and all the sub-assemblies for sheet metal parts and creates flat patterns and exports as dxf.  I would like to have it as a macro instead of an Ilogic but if that's not possible it's okay. I also want it to look at the bill of materials and do the export to all the files marked with laser as the vendor since we have two different types of sheet metal parts.  I don't really know anything about coding in inventor so if any of this is possible any help would be greatly appreciated.

0 Likes
Accepted solutions (1)
1,600 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable

I realized I'm an idiot and forgot to link the rule so here it is.

0 Likes
Message 3 of 17

Anonymous
Not applicable

I've been discussing these macros with my supervisors and they said that they would also like to have it sort the parts based on the thickness of the material and the material type.  If there was a way to create folders inside the folder created by this rule that would be great.  Anyone looking to help me out this is definitely the top priority for them right now so if you get it to do this but can't figure out the other stuff i requested before I would still be more than ecstatic.  

0 Likes
Message 4 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

@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



0 Likes
Message 5 of 17

Anonymous
Not applicable

When I try to run this an error pops up that says "Run-time error '424': Object Required"  

The line showing in the debug is:

If Not System.IO.Directory.Exists(oFolder) Then

0 Likes
Message 6 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Anonymous,

 

Try this modified code.

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 Len(Dir(oFolder, vbDirectory)) = 0 Then
        MkDir 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



0 Likes
Message 7 of 17

Anonymous
Not applicable

Now it says Run time error 438; Object doesn't support this property or method.  The line the debugger brings up is:

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

0 Likes
Message 8 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below changes

If oRefDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 17

Anonymous
Not applicable

This works as a translation to VBA from the original rule but like I said before I would like it to A) only run on parts with "Laser" as the Vendor and B) sort the parts into folders based on thickness and material.  I would really appreciate it if you could find a way to make it do both of those.  Thanks for all your help.

0 Likes
Message 10 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below code to export dxf only for "Laser" vendor.

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 Len(Dir(oFolder, vbDirectory)) = 0 Then
        MkDir 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.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
            If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value = "Laser" 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
        End If
    Next
End Sub

Thanks and regards


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 17

Anonymous
Not applicable

Thanks for that, it worked great.  Is there any way you could get it to sort them into folders based on thickness and material?

0 Likes
Message 12 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous ,

 

Hoping that below VBA code 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 Len(Dir(oFolder, vbDirectory)) = 0 Then
        MkDir 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.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
            If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value = "Laser" Then
                Dim oDrawDoc As PartDocument
                Set oDrawDoc = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, True)
                
                Dim oDef As SheetMetalComponentDefinition
                Set oDef = oDrawDoc.ComponentDefinition
                
                Dim oThick As String
                oThick = oDef.Thickness
                
                Dim oMaterial As String
                oMaterial = oDrawDoc.ActiveMaterial.DisplayName
                 
                oFolder = oPath & "\" & oAsmName & " DXF Files\" & oThick & "-" & 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) - 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
        End If
    Next
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 17

Anonymous
Not applicable

This worked almost perfectly except the folder names were weird. Instead of being .187 and .120 which were the two thicknesses I had in the assembly they had values of 50348544 and 50348800.  My manager also wants it to be by gauge instead of thickness in inches so is there a way to make it read the actual thickness in inches and then convert it to gauge or do I have to go through and figure out what the weird number is for each thickness?  If you have to right a bunch of statements like: if .187\50348544 then 7 Gauge I can do the most of that work if you show me what it needs to look like.  Thanks again for your help.

0 Likes
Message 14 of 17

Anonymous
Not applicable

This is almost perfect, except the thickness is doing weird things.  Instead of .187 and .12 it had 50348544 and 50348800.  It did the same numbers for the same thickness in some assemblies but not all of them is it maybe referencing the wrong thickness?  I was just going to make a case select to translate the numbers but since some of the assemblies don't give the same number for the same thickness I can't make that work.

0 Likes
Message 15 of 17

Anonymous
Not applicable

I replaced: 

oDef.Thickness

With:

oDef.ActiveSheetMetalStyle.Thickness

which gave me the actual Thickness in Inches but it gave the Thickness from the first part to the rest of them. So it still sorted by material but they all had a thickness of .12 in

0 Likes
Message 16 of 17

Anonymous
Not applicable

You can ignore my last 3 posts as I got that figured out on my own.  However,  some of our assemblies have the Laser marked as the category instead of the Vendor and I can't figure out how to get it to look at the category instead of Vendor.  If you could figure that out I would really appreciate it.

Message 17 of 17

Anonymous
Not applicable

I figured it out.  

If UCase(oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value) = "LASER" Or _
UCase(oRefDoc.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value) = "LASER" Then

 

The UCase makes it not matter if the LASER is all uppercase or whatnot.

0 Likes