Flat pattern dxf export layer config

Flat pattern dxf export layer config

florescu.d95
Enthusiast Enthusiast
511 Views
2 Replies
Message 1 of 3

Flat pattern dxf export layer config

florescu.d95
Enthusiast
Enthusiast

Hi, 

 

Over time, by reading the forums and combining and modifying several ideas, I have created the following rule that exports the sheet metal flat pattern as a DXF and it works for assemblies and single parts.

 

I would like to add more customization options to it such as being able to choose which layers get exported, layer colour, line type without having to edit the code every time.

The way I would do it is by using a global form, problem is that I have no idea how to do it.   

Sub Main()      
        If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Assy
		If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Part

		End Sub

        Sub Assy()
         Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
         Dim oAsmName = oAsmDoc.DisplayName.Replace(".iam", "")

        Dim 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
        End If
	
		

        Dim oPath = ThisDoc.Path

        
        Dim oFolder = oPath & "\" & oAsmName & " DXF Files"
        If Not System.IO.Directory.Exists(oFolder) Then
            System.IO.Directory.CreateDirectory(oFolder)
        End If

        Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments

   
        For Each oRefDoc As Document In oRefDocs

           
            If (oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then
                Continue For
            End If
           
            If (oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
                Continue For 
            End If
            If (oRefDoc.Dirty = True) Then
               
                Continue For 
            End If

            Dim oDrawDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
            Dim oFileName = oRefDoc.DisplayName.Replace(".ipt", "")
            Dim oCompDef As SheetMetalComponentDefinition = oDrawDoc.ComponentDefinition
            Try
                Dim customPropertiesSet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
                Dim customName As String = "XXX"
                Try
                    customName = customPropertiesSet.Item("PF_PRT_ZNR").Value
                Catch
                    
                End Try

                Dim designTrackingPropertiesSet = oRefDoc.PropertySets.Item("Design Tracking Properties")
                Dim description As String = designTrackingPropertiesSet.Item("Description").Value
                Dim StockNumber As String = designTrackingPropertiesSet.Item("Stock Number").Value
				Dim PartNumber As String = oFileName

                Dim Material As String = oCompDef.ActiveSheetMetalStyle.Material.Name

              
                Dim newFileName As String =
                    oFolder & "\" & PartNumber & " " & Material & ".dxf"


                If oCompDef.HasFlatPattern = False Then
                    oCompDef.Unfold()
                Else
                    oCompDef.FlatPattern.Edit()
                End If
                Dim sOutA As String
                sOutA = "FLAT PATTERN DXF?AcadVersion=2000" & _
        "&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerLineType=37633&OuterProfileLayerLineWeight=0,0500&OuterProfileLayerColor=0;0;0" & _
        "&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InteriorProfilesLayerLineType=37633&InteriorProfilesLayerLineWeight=0,0500&InteriorProfilesLayerColor=0;0;0" & _
		"&BendUpLayer=IV_BEND&BendUpLayerLineType=37633&BendUpLayerColor=143;175;143" & _
		"&BendDownLayer=IV_BEND_DOWN&BendDownLayerLineType=37634&BendDownLayerColor=143;175;143" & _
		"&FeatureProfilesUpLayer=IV_FEATURE_PROFILES&FeatureProfilesUpLayerLineType=37633&FeatureProfilesUpLayerColor=0;0;255" & _
		"&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerLineType=37634&FeatureProfilesDownLayerColor=0;0;255" & _
		"&AltRepFrontLayer=IV_ALTREP_FRONT&AltRepFrontLayerLineType=37633&AltRepFrontLayerColor=0;0;255" & _
		"&AltRepBackLayerr=IV_ALTREP_BACK&AltRepBackLayerLineType=37634&AltRepBackLayerColor=0;0;255" & _
		"&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
					Dim sOutB As String
                sOutB = "FLAT PATTERN DXF?AcadVersion=2000" & _
        "&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerLineType=37633&OuterProfileLayerLineWeight=0,0500&OuterProfileLayerColor=0;0;0" & _
        "&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InteriorProfilesLayerLineType=37633&InteriorProfilesLayerLineWeight=0,0500&InteriorProfilesLayerColor=0;0;0" & _
		"&FeatureProfilesUpLayer=IV_FEATURE_PROFILES&FeatureProfilesUpLayerLineType=37633&FeatureProfilesUpLayerColor=0;0;255" & _
		"&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerLineType=37634&FeatureProfilesDownLayerColor=0;0;255" & _
		"&AltRepFrontLayer=IV_ALTREP_FRONT&AltRepFrontLayerLineType=37633&AltRepFrontLayerColor=175;175;143" & _
		"&AltRepBackLayerr=IV_ALTREP_BACK&AltRepBackLayerLineType=37634&AltRepBackLayerColor=175;175;143" & _
		"&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL;IV_BEND;IV_BEND_DOWN;"
				
		
	Dim ExpSettingQuestion = MessageBox.Show("Do you want to export Bend Lines?", "DXF Export Settings", MessageBoxButtons.YesNo)
If ExpSettingQuestion = vbNo Then oCompDef.DataIO.WriteDataToFile(sOutB, newFileName) 
If ExpSettingQuestion = vbYes Then oCompDef.DataIO.WriteDataToFile(sOutA, newFileName) 
				
                oCompDef.FlatPattern.ExitEdit()
            Catch
            End Try
            oDrawDoc.Close()
           
        Next
	End Sub
	
	Sub Part()
        Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
             Dim oPartName = oPartDoc.DisplayName.Replace(".ipt", "")

        Dim RUsure = MessageBox.Show(
"This will create a DXF file for the current part." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF file?" _
& vbLf & "This could take a while.", "iLogic - Batch Output DXFs ", MessageBoxButtons.YesNo)
        If RUsure = vbNo Then
            Return
        End If

        Dim oPath = ThisDoc.Path

        Dim oFolder = oPath

        Dim oRefDoc= oPartDoc

            If (oPartDoc .SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then  
				i = MessageBox.Show("Part is not a sheet metal part", "My iLogic Dialog", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
				Return 
			End If 
			If (oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
				
			End If 
				
            If (oPartDoc .Dirty = True) Then
              

            End If

            Dim oDrawDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
            Dim oFileName = oRefDoc.DisplayName.Replace(".ipt", "")
            Dim oCompDef As SheetMetalComponentDefinition = oDrawDoc.ComponentDefinition
            Try
                
                Dim customPropertiesSet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
                Dim customName As String = "XXX"
                Try
                    customName = customPropertiesSet.Item("PF_PRT_ZNR").Value
                Catch
                 
                End Try

                Dim designTrackingPropertiesSet = oRefDoc.PropertySets.Item("Design Tracking Properties")
                Dim description As String = designTrackingPropertiesSet.Item("Description").Value
                Dim StockNumber As String = designTrackingPropertiesSet.Item("Stock Number").Value
				Dim PartNumber As String = oFileName

                Dim Material As String = oCompDef.ActiveSheetMetalStyle.Material.Name

               
                Dim newFileName As String =
                    oFolder & "\" & PartNumber & " " & Material & ".dxf"


                If oCompDef.HasFlatPattern = False Then
                    oCompDef.Unfold()
                Else
                    oCompDef.FlatPattern.Edit()
                End If
                Dim sOutA As String
                sOutA = "FLAT PATTERN DXF?AcadVersion=2000" & _
        "&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerLineType=37633&OuterProfileLayerLineWeight=0,0500&OuterProfileLayerColor=0;0;0" & _
        "&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InteriorProfilesLayerLineType=37633&InteriorProfilesLayerLineWeight=0,0500&InteriorProfilesLayerColor=0;0;0" & _
		"&BendUpLayer=IV_BEND&BendUpLayerLineType=37633&BendUpLayerColor=143;175;143" & _
		"&BendDownLayer=IV_BEND_DOWN&BendDownLayerLineType=37634&BendDownLayerColor=143;175;143" & _
		"&FeatureProfilesUpLayer=IV_FEATURE_PROFILES&FeatureProfilesUpLayerLineType=37633&FeatureProfilesUpLayerColor=0;0;255" & _
		"&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerLineType=37634&FeatureProfilesDownLayerColor=0;0;255" & _
		"&AltRepFrontLayer=IV_ALTREP_FRONT&AltRepFrontLayerLineType=37633&AltRepFrontLayerColor=0;0;255" & _
		"&AltRepBackLayerr=IV_ALTREP_BACK&AltRepBackLayerLineType=37634&AltRepBackLayerColor=0;0;255" & _
		"&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
					Dim sOutB As String
                sOutB = "FLAT PATTERN DXF?AcadVersion=2000" & _
        "&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerLineType=37633&OuterProfileLayerLineWeight=0,0500&OuterProfileLayerColor=0;0;0" & _
        "&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InteriorProfilesLayerLineType=37633&InteriorProfilesLayerLineWeight=0,0500&InteriorProfilesLayerColor=0;0;0" & _
		"&FeatureProfilesUpLayer=IV_FEATURE_PROFILES&FeatureProfilesUpLayerLineType=37633&FeatureProfilesUpLayerColor=0;0;255" & _
		"&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerLineType=37634&FeatureProfilesDownLayerColor=0;0;255" & _
		"&AltRepFrontLayer=IV_ALTREP_FRONT&AltRepFrontLayerLineType=37633&AltRepFrontLayerColor=175;175;143" & _
		"&AltRepBackLayerr=IV_ALTREP_BACK&AltRepBackLayerLineType=37634&AltRepBackLayerColor=175;175;143" & _
		"&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL;IV_BEND;IV_BEND_DOWN;"
				
		
	Dim ExpSettingQuestion = MessageBox.Show("Do you want to export Bend Lines?", "DXF Export Settings", MessageBoxButtons.YesNo)
If ExpSettingQuestion = vbNo Then oCompDef.DataIO.WriteDataToFile(sOutB, newFileName) 
If ExpSettingQuestion = vbYes Then oCompDef.DataIO.WriteDataToFile(sOutA, newFileName) 
				
                oCompDef.FlatPattern.ExitEdit()
            Catch
            End Try
            oDrawDoc.Close()
           

	End Sub

 Any help is greatly appreciated. 

0 Likes
512 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor

Many years ago I made standalone application for creating the config string for DWG/DXF export of flat pattern. It contains all possible options. It was based on this help article

But it was a lot of code and I used WinForms PropertyGrid control to edit the values (not available in iLogic).

I don't know, if it is possible to do the similar (complex) solution using iLogic forms.

 

You need to implement your own object which describes the options and config string builder which converts that object to string form that you can use later in your code.

MichaelNavara_0-1661784447334.png

 

 

0 Likes
Message 3 of 3

florescu.d95
Enthusiast
Enthusiast

Hi @Michael.Navara ,

I have seen that standalone application here  but could never find it.

Maybe after expand my coding skills i will be able to do something similar.

0 Likes