Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Help, Revision export works sporadically.

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ibraunLEW5D
382 Views, 2 Replies

iLogic Help, Revision export works sporadically.

I have an iLogic code that I've pieced together from various snippets I've found on the forums.  It works fairly well except for the file name.  We use this code to pull all sheet metal parts from an assembly, create a dxf of the flat pattern, and place in a specific folder.  We then run a second rule to create an excel spread sheet that is a custom filtered BOM of just sheet metal components, revision level, material, etc.   For example, if I have a part number 1111-222 revision A, I want the file to export as 1111-222_RevA.dxf

 

On Occasion, the revision level will be missing.  It will be 1111-222Rev.dxf  It seems to happen very sporadically and I have not been able to nail down why that might be.   

 

Any suggestions I am an open book, thank you! 

 

Code:

 'EXPORT DXF TO FOLDER CHOSEN'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

        oFolder1 = "O:\Engineering\Print Request Files\Data Packet Folders\"
        Shell("explorer.exe " + oFolder1, vbNormalFocus)
        RFQEntry : Dim sRFQNumber As String = InputBox("DP Number:", "DATA PACKET NUMBER ENTRY",)
        If Len(sRFQNumber) <> 4 Then
            MessageBox.Show("DP Number must be 4 numbers i.e. 1234 to continue.")
            Goto RFQEntry
    
        End If

    oFolder = "O:\Engineering\Print Request Files\Data Packet Folders\" + sRFQNumber
    
'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"

    Dim Rev As String = iProperties.Value(FName, "Project", "Revision Number")
    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

    
    Try
    CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
    Catch
    CustomName ="" 
    End Try

    oDataMedium.FileName = oFolder & "\" & CustomName  & " " & oFileName & "_Rev" & Rev & ".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&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2;IV_BEND;IV_BEND_DOWN;IV_INNER_PROFILES;"
    oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
    


    oCompDef.FlatPattern.ExitEdit
    
    Catch
    End Try
    oDrawDoc.Close
    Else
    End If
    Next
2 REPLIES 2
Message 2 of 3
JhoelForshav
in reply to: ibraunLEW5D

Hi @ibraunLEW5D 

Looking through your code, I see that you're using a variable "FName" when getting the revision number. This variable is never declared before in the code so that is just Nothing.

The iLogic functionality you're using will return the assemblys revision number in the case of that agument being nothing. So when you get a revision number, it's because the assembly has one and it's the assemblys number you'll get.

 

Since you're already looping through the document objects I'd suggest using those to retrieve their revision numbers.

See my minor change to the code below. I think it's what you need 🙂

 

'EXPORT DXF TO FOLDER CHOSEN'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

        oFolder1 = "O:\Engineering\Print Request Files\Data Packet Folders\"
        Shell("explorer.exe " + oFolder1, vbNormalFocus)
        RFQEntry : Dim sRFQNumber As String = InputBox("DP Number:", "DATA PACKET NUMBER ENTRY",)
        If Len(sRFQNumber) <> 4 Then
            MessageBox.Show("DP Number must be 4 numbers i.e. 1234 to continue.")
            GoTo RFQEntry
    
        End If

    oFolder = "O:\Engineering\Print Request Files\Data Packet Folders\" + sRFQNumber
    
'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"

    'Dim Rev As String = iProperties.Value(FName, "Project", "Revision Number") 'FName doesn't exist
	Dim Rev As String = oRefDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
    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

    
    Try
    CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
    Catch
    CustomName ="" 
    End Try

    oDataMedium.FileName = oFolder & "\" & CustomName  & " " & oFileName & "_Rev" & Rev & ".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&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2;IV_BEND;IV_BEND_DOWN;IV_INNER_PROFILES;"
    oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
    


    oCompDef.FlatPattern.ExitEdit
    
    Catch
    End Try
    oDrawDoc.Close
    Else
    End If
    Next

 

Message 3 of 3
ibraunLEW5D
in reply to: JhoelForshav

Wow thank you! This works perfect now.  I knew it would be simple, I just didn't know it would be quite that simple.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report