ilogic to export only certain named sketches from all parts in an assembly

ilogic to export only certain named sketches from all parts in an assembly

busturazz
Explorer Explorer
663 Views
2 Replies
Message 1 of 3

ilogic to export only certain named sketches from all parts in an assembly

busturazz
Explorer
Explorer

trying to export all sketches from an assembly with the name "cut DXF sketch". this is not the same as flat pattern as the sketch  has been altered from flat pattern. here is what I have been able to find and piece together. just need to figure out how to have it only export the sketches named "cut DXF Sketch"

 

'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
Try
CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
Catch
CustomName ="XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert
End Try

oDataMedium.FileName = oFolder & "\" & CustomName  & " " & 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=2010&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"
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
Accepted solutions (2)
664 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

does this work for you?

[ilogic code]

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmName As String = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) - 4)
'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If
'get user input
Dim RUsure As DialogResult = 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 = DialogResult.No Then
    Return
Else
End If
Dim oPath As String = ThisDoc.Path
Dim oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'get DXF target folder path
Dim 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 = oAsmDoc.AllReferencedDocuments
'work the the drawing files for the referenced models
'this expects that the model has been saved
For Each oRefDoc As Document In oRefDocs
    Dim 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)
        Dim oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
        Try
            'Set the DXF target file name
            Dim CustomName As String
            Try
                CustomName = iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
            Catch
                CustomName = "XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert
            End Try

            oDataMedium.FileName = oFolder & "\" & CustomName & " " & oFileName & ".dxf"

            Dim oCompDef As SheetMetalComponentDefinition = oDrawDoc.ComponentDefinition
            If oCompDef.HasFlatPattern = False Then
                oCompDef.Unfold()
            Else
                oCompDef.FlatPattern.Edit()
            End If

            Dim sOut As String
            ' sOut = "FLAT PATTERN DXF?AcadVersion=2010&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"
            sOut = "DXF"
            For Each sketch As PlanarSketch In oCompDef.FlatPattern.Sketches
                If Sketch.Name.Equals("cut DXF Sketch") Then
                    Sketch.DataIO.WriteDataToFile(sOut, oDataMedium.FileName)
                End If
            Next

            ' 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 ex As Exception
        End Try
        oDrawDoc.Close()
    Else
    End If
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

busturazz
Explorer
Explorer
Accepted solution

yes as far as i can tell ran a quick test and worked at pulling 1 file will have to try it on an assembly with multiple files

0 Likes