Help with coustomization flat pattern iLogic rule

Help with coustomization flat pattern iLogic rule

appN65UD
Participant Participant
289 Views
4 Replies
Message 1 of 5

Help with coustomization flat pattern iLogic rule

appN65UD
Participant
Participant

Hi everyone, i found on this site: http://hjalte.nl/81-dxf-export-made-easy great rule for me, I customizated and edit it for my preferecies, but i cant do two things: delete one layer (IV_ARC_CENTERS), and changed line type from continous to dashed during exporting to dwg file. I attached schreenshot for better understanding what i want to do and pasted edited rule. Can anybody help me?

 

Public Class ThisRule
	Sub Main()
		Dim doc As PartDocument = ThisDoc.Document

		Dim newFileName As String = ThisDoc.PathAndFileName(False) & ".dwg"

		Dim white = ThisApplication.TransientObjects.CreateColor(255, 255, 255)
		Dim red = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
		Dim blue = ThisApplication.TransientObjects.CreateColor(0, 255, 255)
		
		Dim Exporter As New FlatPatternDxfExporterService()
		' Basic options
		Exporter.AcadVersion = "2004"
		Exporter.RebaseGeometry = True	
		' Layer options
		Exporter.Layers.OuterProfileLayer.Name = "Outer profile"
		Exporter.Layers.OuterProfileLayer.Color = white		
		Exporter.Layers.InteriorProfilesLayer.LineWeight = 0.01		
		Exporter.Layers.BendUpLayer.Name = "Bend up"
		Exporter.Layers.BendUpLayer.Color = red
		Exporter.Layers.BendUpLayer.LineWeight = 0.01		
		Exporter.Layers.BendDownLayer.Name = "Bend down"
		Exporter.Layers.BendDownLayer.Color = blue
		Exporter.Layers.BendDownLayer.LineWeight = 0.01		
		Exporter.Layers.TangentLayer.Hidden = True		
		Exporter.Export(doc, newFileName)
		
	End Sub
End Class

Public Class FlatPatternDxfExporterService

	''' <summary>Only use one of the following values: 2018, 2013, 2010, 2007, 2004, 2000, or R12</summary>
	Public Property AcadVersion As String = "2018"

	''' <summary>Enable spline replacement(by linear segments or arcs).</summary>
	Public Property SimplifySplines As Boolean = False

	''' <summary>Chord tolerance for spline replacement.</summary>
	Public Property SplineTolerance As Double = 0.01

	Public Property AdvancedLegacyExport As Boolean = True

	''' <summary>Build a polyline Of the exterior profiles</summary>
	Public Property MergeProfilesIntoPolyline As Boolean = True

	''' <summary>Trim the centerlines at contour.</summary>
	Public Property TrimCenterlinesAtContour As Boolean = False

	''' <summary>Move geometry to 1st quadrant.</summary>
	Public Property RebaseGeometry As Boolean = False

	''' <summary>
	''' True: Replace splines by tangent arcs. 
	''' False: Replace splines by line segments. 
	''' The SimplifySplines should be specified To True otherwise this Option Is ignored.
	''' </summary>
	Public Property SimplifyAsTangentArcs As Boolean = False

	Public Property Layers As OverallLayerSettings = New OverallLayerSettings()

	Public Sub Export(doc As Inventor.PartDocument, newFileName As String)
		If doc Is Nothing Then Return

		If (String.IsNullOrWhiteSpace(newFileName)) Then
			Throw New Exception("No DXF FullFileName specified.")
		End If

		If (doc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
			Throw New Exception("Document is not a Sheet Metal Part.")
		End If

		Dim def As SheetMetalComponentDefinition = doc.ComponentDefinition

		If (System.IO.File.Exists(newFileName)) Then
			Dim nl = System.Environment.NewLine
			Dim msg = String.Format("The following DWG file already exists.{1}{0}{1}Do you want to overwrite it?", newFileName, nl)
			Dim result As MsgBoxResult = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2, "Dwg already exists")
			If result = MsgBoxResult.No Then Return
		End If

		If (Not def.HasFlatPattern) Then
			Try
				def.Unfold()
				def.FlatPattern.ExitEdit()
			Catch
				Throw New Exception("Error unfolding " & doc.FullDocumentName)
			End Try

		End If
		Dim flatpattern As FlatPattern = def.FlatPattern

		If flatpattern Is Nothing Then
			Throw New Exception("Sheet Metal FlatPattern was not attainable.")
		End If

		Try
			flatpattern.DataIO.WriteDataToFile(ToString(), newFileName)
		Catch ex As Exception
			Throw New Exception("Failed to export to dxf.")
		End Try
	End Sub

	Public Overrides Function ToString() As String
		Dim settingsString As String = "FLAT PATTERN DXF?"

		Dim settings As New List(Of String)
		settings.Add("AcadVersion=" & AcadVersion)
		settings.Add("SimplifySplines=" & SimplifySplines)
		settings.Add("SplineTolerance=" & SplineTolerance)
		settings.Add("AdvancedLegacyExport=" & AdvancedLegacyExport)
		settings.Add("MergeProfilesIntoPolyline=" & MergeProfilesIntoPolyline)
		settings.Add("TrimCenterlinesAtContour=" & TrimCenterlinesAtContour)
		settings.Add("RebaseGeometry=" & RebaseGeometry)
		settings.Add("SimplifyAsTangentArcs=" & SimplifyAsTangentArcs)
		settings.Add(Layers.ToString())
		Return "FLAT PATTERN DXF?" & String.Join("&", settings)
	End Function
End Class

Public Class OverallLayerSettings
	Public Property TangentLayer() As LayerSettings = New LayerSettings("TangentLayer", "IV_TANGENT")
	Public Property OuterProfileLayer() As LayerSettings = New LayerSettings("OuterProfileLayer", "IV_OUTER_PROFILE")
	Public Property ArcCentersLayer() As LayerSettings = New LayerSettings("ArcCentersLayer", "IV_ARC_CENTERS")
	Public Property InteriorProfilesLayer() As LayerSettings = New LayerSettings("InteriorProfilesLayer", "IV_INTERIOR_PROFILES")
	Public Property BendUpLayer() As LayerSettings = New LayerSettings("BendUpLayer", "IV_BEND")
	Public Property BendDownLayer() As LayerSettings = New LayerSettings("BendDownLayer", "IV_BEND_DOWN")
	Public Property ToolCenterUpLayer() As LayerSettings = New LayerSettings("ToolCenterUpLayer", "IV_TOOL_CENTER")
	Public Property ToolCenterDownLayer() As LayerSettings = New LayerSettings("ToolCenterDownLayer", "IV_TOOL_CENTER_DOWN")
	Public Property FeatureProfilesUpLayer() As LayerSettings = New LayerSettings("FeatureProfilesUpLayer", "IV_FEATURE_PROFILES")
	Public Property FeatureProfilesDownLayer() As LayerSettings = New LayerSettings("FeatureProfilesDownLayer", "IV_FEATURE_PROFILES_DOWN")
	Public Property AltRepFrontLayer() As LayerSettings = New LayerSettings("AltRepFrontLayer", "IV_ALTREP_FRONT")
	Public Property AltRepBackLayer() As LayerSettings = New LayerSettings("AltRepBackLayer", "IV_ALTREP_BACK")
	Public Property UnconsumedSketchesLayer() As LayerSettings = New LayerSettings("UnconsumedSketchesLayer", "IV_UNCONSUMED_SKETCHES")
	Public Property TangentRollLinesLayer() As LayerSettings = New LayerSettings("TangentRollLinesLayer", "IV_ROLL_TANGENT")
	Public Property RollLinesLayer() As LayerSettings = New LayerSettings("RollLinesLayer", "IV_ROLL")

	Public Overrides Function ToString() As String
		Dim settings As New List(Of String)
		Dim hiddenLayers As New List(Of String)
		AddSettingOrDefault(settings, hiddenLayers, TangentLayer)
		AddSettingOrDefault(settings, hiddenLayers, OuterProfileLayer)
		AddSettingOrDefault(settings, hiddenLayers, ArcCentersLayer)
		AddSettingOrDefault(settings, hiddenLayers, InteriorProfilesLayer)
		AddSettingOrDefault(settings, hiddenLayers, BendUpLayer)
		AddSettingOrDefault(settings, hiddenLayers, BendDownLayer)
		AddSettingOrDefault(settings, hiddenLayers, ToolCenterUpLayer)
		AddSettingOrDefault(settings, hiddenLayers, ToolCenterDownLayer)
		AddSettingOrDefault(settings, hiddenLayers, FeatureProfilesUpLayer)
		AddSettingOrDefault(settings, hiddenLayers, FeatureProfilesDownLayer)
		AddSettingOrDefault(settings, hiddenLayers, AltRepFrontLayer)
		AddSettingOrDefault(settings, hiddenLayers, AltRepBackLayer)
		AddSettingOrDefault(settings, hiddenLayers, UnconsumedSketchesLayer)
		AddSettingOrDefault(settings, hiddenLayers, TangentRollLinesLayer)
		AddSettingOrDefault(settings, hiddenLayers, RollLinesLayer)
		Dim settingsString = ""
		If (settings.Count > 0) Then
			settingsString = String.Join("&", settings)
		End If
		If (hiddenLayers.Count > 0) Then
			If (settings.Count > 0) Then settingsString += "&"

			settingsString += "InvisibleLayers=" + String.Join(";", hiddenLayers)
		End If
		Return settingsString
	End Function

	Private Sub AddSettingOrDefault(settings As List(Of String), hiddenLayers As List(Of String), value As LayerSettings)
		If (Not String.IsNullOrWhiteSpace(value.ToString())) Then
			settings.Add(value.ToString())
		End If
		If (value.Hidden) Then
			hiddenLayers.Add(value.Name)
		End If
	End Sub
End Class

Public Class LayerSettings
	Public Sub New(InventorName As String, defaultLayerName As String)

		Me.InventorName = inventorName
		Me.Name = defaultLayerName
		Me.NameOrg = defaultLayerName
	End Sub

	Private Property InventorName As String
	Public Property Name As String = String.Empty
	Private Property NameOrg As String = String.Empty

	Public Property Color As Color = Nothing
	Public Property LineType As LineTypeEnum = LineTypeEnum.kContinuousLineType
	Public Property LineWeight As Double = -1
	Public Property Hidden As Boolean = False

	Public Overrides Function ToString() As String
		Dim settings As New List(Of String)
		If (Name <> NameOrg) Then
			settings.Add(InventorName & "=" & Name)
		End If
		If (Color IsNot Nothing) Then
			settings.Add(String.Format("{0}Color={1};{2};{3}", InventorName, Color.Red, Color.Green, Color.Blue))
		End If
		If (LineType <> LineTypeEnum.kContinuousLineType) Then
			settings.Add(String.Format("{0}LineType={1}", InventorName, LineType.ToString()))
		End If
		If (LineWeight <> -1) Then
			settings.Add(String.Format("{0}LineWeight={1}", InventorName, LineWeight.ToString()))
		End If
		Return String.Join("&", settings)
	End Function
End Class

 

0 Likes
290 Views
4 Replies
Replies (4)
Message 2 of 5

C_Haines_ENG
Collaborator
Collaborator

When you export to DWG manually, there are a TON of settings that you can hardcode in and then save as a configuration file. You can then reference this file later for simpler code. 

0 Likes
Message 3 of 5

appN65UD
Participant
Participant

I have configuration .ini file for flat export, but i want to automatize it by ilogic rule (flat pattern saved in dwg 2004 version in the same file folder according .ini options):

 

[FP EXPORT SELECT OPTIONS]
AUTOCAD VERSION=AutoCAD 2004
USE CUSTOMIZE=Yes
CUSTOMIZE FILE=c:\progra~1\autodesk\invent~1\Design Data\DWG-DXF\FlatPattern.xml
[FLATPATTERN LAYER OPTIONS]
Linie styczne=IV_TANGENT:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Linie gięcia (przednie)=IV_BEND:Visibility=ON;LinePattern=28101;LineWeight=0,0130;Color=255,0,0;
Linie gięcia (tylne)=IV_BEND_DOWN:Visibility=ON;LinePattern=28101;LineWeight=0,0130;Color=0,255,255;
Środki narzędzi (przednie)=IV_TOOL_CENTER:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Środki narzędzi (tylne)=IV_TOOL_CENTER_DOWN:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Środki łuków=IV_ARC_CENTERS:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Profil zewnętrzny=IV_OUTER_PROFILE:Visibility=ON;LinePattern=28100;LineWeight=0,0200;Color=0,0,0;
Profil wewnętrzny=IV_INTERIOR_PROFILES:Visibility=ON;LinePattern=28100;LineWeight=0,0200;Color=0,0,0;
Profil elementu (przedni)=IV_FEATURE_PROFILES:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Profil elementu (tylny)=IV_FEATURE_PROFILES_DOWN:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Alternatywna reprezentacja (przednia)=IV_ALTREP_FRONT:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Alternatywna reprezentacja (tylna)=IV_ALTREP_BACK:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Szkice nieużywane=IV_UNCONSUMED_SKETCHES:Visibility=OFF;LinePattern=0;LineWeight=-1,0000;Color=-255,-255,-255;
Nieużywana konstrukcja szkicu=IV_UNCONSUMED_SKETCH_CONSTRUCTION:Visibility=ON;LinePattern=0;LineWeight=-1,0000;Color=-255,-255,-255;
Styczne linie zawijania=IV_ROLL_TANGENT:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Zwiń linie=IV_ROLL:Visibility=OFF;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
[FLATPATTERN GEOMETRY OPTIONS]
REBASE GEOMETRY=No
GROUP GEOMETRY=No
REPLACE SPLINE=No
SPLINE SIMPLIFICATION METHOD=Linear
CHORD_TOLERANCE=0,010000
TRIM CENTERLINES=Yes
0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

I can't test this now but if you add these lines, will that work for you?

Exporter.Layers.ArcCentersLayer.Hidden = True
Exporter.Layers.BendDownLayer.LineType = LineTypeEnum.kDashedLineType
Exporter.Layers.BendUpLayer.LineType = LineTypeEnum.kDashedLineType

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

0 Likes
Message 5 of 5

appN65UD
Participant
Participant
Exporter.Layers.ArcCentersLayer.Hidden = True

Work good

 

Exporter.Layers.BendDownLayer.LineType = LineTypeEnum.kDashedLineType
Exporter.Layers.BendUpLayer.LineType = LineTypeEnum.kDashedLineType

layer line types don`t work, i need try something else...., but i dont know what 😛 Can you help me. If i fix that the formula will be perfect for me after my own customization 🙂

0 Likes