Combining iLogic rules (dxfs, sats, steps, pdfs/dwgs)

Combining iLogic rules (dxfs, sats, steps, pdfs/dwgs)

gary.creaney
Explorer Explorer
695 Views
6 Replies
Message 1 of 7

Combining iLogic rules (dxfs, sats, steps, pdfs/dwgs)

gary.creaney
Explorer
Explorer

I have 4 ilogic rules that all work well for my needs but I would really like to somehow combine them and get them to do slightly more but don't have the iLogic knowledge to see the task through:

 

The rules are:

1) create dxfs from within an assembly (the rule finds sheet metal and creates dxfs of the flat pattern - creates a folder in the same location of the assembly and populates with the dxfs it could create)

2) create SATs from within an assembly - creates a folder in same location

3) create STEPs from within an assembly - creates a folder in same location

4) create pdf and/or 2D dwg from one or multiple open drawings (idws)

 

It would be great if 1, 2 & 3 could be combined so that all 3 functions take place together simultaneously rather than separately. It would also be great if a folder was created in the same location as the assembly and to have EXACTLY the same name as the assembly (minus the ".iam") and populated with said dxfs, sats & steps.

Is this possible?

The last thing which is probably pushing it too far would be for the same rule to look for idws (which are already in place) of the parts in the assembly, open them and export a pdf and/or 2D dwg ...AND save them into the above mentioned folder with the exact same name as the assembly.

 

I can share the rules already in place for the 4 steps if need be.

 

Apologies if this is confusing but hopefully not. Happy to explain further.

 

Thanks in advance.

0 Likes
696 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Can you attach your rules? Much easier to work with your own rules that your comfortable looking at. 

A few options:

  • You could combine alot of them into there own sub routines I am guessing and see where the common objects are. One large rule processing all.
  • If you are still wanting to use the rules separately the other option could be to just launch the external rules from a main rule. The downside of this approach is ensuring the objects are sequenced and having to potentially pass information between the rules and also the extra coding needed and multiple storage locations.
  • Another option again is just to set up a dialogue box for processing all of the files or individually selecting what type of processing by category . A single winform with checkbox can be a nice way to achieve this without needing to have multiple basic dialogue boxes.
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 7

gary.creaney
Explorer
Explorer

Hi. Thanks for the response.
First 2 rules attached

0 Likes
Message 4 of 7

gary.creaney
Explorer
Explorer

Second 2 rules attached.

 

Thanks

0 Likes
Message 5 of 7

A.Acheson
Mentor
Mentor

Here is two approaches to doing the translation to DXF,SAT and DXF in one operation. Rule 1 just process everything in sequence. Rule 2 uses a form built within VB.NET environment by code so has more of a manual approach rather than using Visual studio to build out the form.

 

Rule 1 Process All

Option Explicit On
Sub Main
	ProcessRefDocuments(ThisDoc.Document)
End Sub
Sub ProcessRefDocuments(oDoc As Document)
	Dim oDXFDirectory As String
	Dim oStepDirectory As String
	Dim oStpFullFileName As String
	Dim oSatDirectory As String
	Dim oSatFullFileName As String 
	Dim oDxfFullFileName As String 
	
    Dim oAsmPN As String = oDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
	oDXFDirectory = CreateFolder(oDoc, " DXF Files")

	oStepDirectory = CreateFolder(oDoc, "STEP Files")
	oStpFullFileName = oStepDirectory & "\" & oAsmPN & ".stp"
	SaveAs(oDoc, oStpFullFileName)

	oSatDirectory = CreateFolder(oDoc, " SAT Files")
	oSatFullFileName = oSatDirectory & "\" & oAsmPN & ".sat"
	SaveAs(oDoc,oSatFullFileName)

	
	'Look at the files referenced by the assembly and work the referenced models.
	For Each oRefDoc As Document In oDoc.AllReferencedDocuments  
		If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
	    
		Dim oModelPN As String = oRefDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
	  	
		oStpFullFileName = oStepDirectory & "\" & oModelPN & ".stp"
		oStpFullFileName = Nothing
		SaveAs(oRefDoc, oStpFullFileName)

		oSatFullFileName = Nothing
		oSatFullFileName = oSatDirectory & "\" & oModelPN & ".sat"
		SaveAs(oRefDoc, oSatFullFileName)

		'FilterSheetmetal Parts.
		If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
			oDxfFullFileName = Nothing
			oDxfFullFileName  = oDXFDirectory & "\" & oModelPN & ".dxf"
			CreateDXF(oRefDoc ,oDxfFullFileName)
		End If
	Next
	MessageBox.Show("Batch Processing Rule Finished!","iLogic")
End Sub

Function CreateFolder(oDoc As Document, oFolderName As String ) As String
	Dim oPath As String = IO.Path.GetDirectoryName(oDoc.FullFileName)
	Dim oAsmName As String = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
	'Get Target folder path.
	Dim oFolder As String = oPath & "\" & oAsmName & " " & oFolderName
	'Check For the Step folder And create it If it does Not exist.
	If Not System.IO.Directory.Exists(oFolder) Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If

	Return oFolder
End Function

Sub SaveAs(oDoc,oFullFileName)
	  Try  	
	       	oDoc.SaveAs(oFullFileName, True)
	  Catch ex As Exception
			'Logger.Info("Error Saving As " & oFullFileName)
	  End Try
End Sub

Sub CreateDXF(oDoc As PartDocument, oFullFileName As String)

	Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
	oDataMedium.FileName = oFullFileName
	
	oDoc = ThisApplication.Documents.Open(oDoc.FullFileName, False)
	Try
		Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
		If oCompDef.HasFlatPattern = False Then
			oCompDef.Unfold
		Else
			oCompDef.FlatPattern.Edit
		End If

		Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2010&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerColor=0;0;255"& _
				  "&TangentLayer=IV_TANGENT&TangentLayerColor=255;0;0&BendUpLayer=IV_BEND&BendUpLayerColor=255;255;0"& _
				  "&BendDownLayer=IV_BEND_DOWN&BendDownLayerColor=255;128;0&InteriorProfilesLayer=IV_INTERIOR_PROFILES"& _
				  "&InteriorProfilesLayerColor=255;0;0&MergeProfilesIntoPolyline=True"
				'MessageBox.Show("Message", "Title")
  
		oCompDef.DataIO.WriteDataToFile(sOut, oDataMedium.FileName)
		oCompDef.FlatPattern.ExitEdit
	Catch
	End Try
	oDoc.Close
End Sub

Rule 2 Give Form to user for Translation Options

Option Explicit On
AddReference "System.Drawing"
Imports System.Windows.Forms
Imports System.Drawing

Public Class WinForm
	Inherits System.Windows.Forms.Form
	Public ThisApplication As Inventor.Application = GetObject(,"Inventor.Application")
	Public oArial10 As System.Drawing.Font = New Font("Arial", 10)
	Public oArial12Bold As System.Drawing.Font = New Font("Arial", 10, FontStyle.Bold)
	Dim Operation As New List(Of String)
	Public Sub New()
		
		Dim oForm As System.Windows.Forms.Form = Me
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 300
			.Height = 300
			.TopMost = True
			.Font = oArial10
			.Text = "Assembly File Processing"
			.Name = "Form Title"
			.ShowInTaskbar = False
		End With
		Dim oMainLabel As New System.Windows.Forms.Label
		With oMainLabel
			.Text = "Pick As Required!"
			.Top = 10
			.Left = 25
			.Height = 20
			.Width = 300
		End With
		oForm.Controls.Add(oMainLabel)' Add to the form.
		
		'[Check Box1
		Dim CheckBox1 As New System.Windows.Forms.CheckBox'Create and initialize a CheckBox. 
			With CheckBox1 
			.Text = "STEP"
			.Top = oMainLabel.Bottom 
			.Left = 25
			.Width = 20
			.Height = 25
			.Name = "oCheckBox1"
			.Appearance = Appearance.Normal ' Make the check box control appear as a toggle button.
			.AutoCheck = True 'Turn off the update of the display on the click of the control.
		End With
		oForm.Controls.Add(CheckBox1)' Add the check box control to the form.
		AddHandler CheckBox1.Click, AddressOf checkBox1_Click
		
		Dim NameBox1 As New System.Windows.Forms.TextBox
		With NameBox1
			.Top = CheckBox1.Top
			.Left = CheckBox1.Right +25
			.Width = 200
			.Height = 25
			.Name = "oNameBox1"
			.Text = "STEP"
			.Enabled = False
		End With
		oForm.Controls.Add(NameBox1)
		']
		
		'[Check Box2
		Dim CheckBox2 As New System.Windows.Forms.CheckBox'Create and initialize a CheckBox. 
			With CheckBox2 
			.Text = "DXF"
			.Top = CheckBox1.Bottom 
			.Left = 25
			.Width = 20
			.Height = 25
			.Name = "oCheckBox2"
			.Appearance = Appearance.Normal ' Make the check box control appear as a toggle button.
			.AutoCheck = True 'Turn off the update of the display on the click of the control.
		End With
		oForm.Controls.Add(CheckBox2)' Add the check box control to the form.
		AddHandler CheckBox2.Click, AddressOf checkBox2_Click
		
		Dim NameBox2 As New System.Windows.Forms.TextBox
		With NameBox2
			.Top = CheckBox2.Top
			.Left = CheckBox2.Right +25
			.Width = 200
			.Height = 25
			.Name = "oNameBox2"
			.Text = "DXF"
			.Enabled = False
		End With
		oForm.Controls.Add(NameBox2)
		']
		
		'[Check Box3
		Dim CheckBox3 As New System.Windows.Forms.CheckBox'Create and initialize a CheckBox. 
			With CheckBox3 
			.Text = "SAT"
			.Top = CheckBox2.Bottom 
			.Left = 25
			.Width = 20
			.Height = 25
			.Name = "oCheckBox3"
			.Appearance = Appearance.Normal ' Make the check box control appear as a toggle button.
			.AutoCheck = True 'Turn off the update of the display on the click of the control.
		End With
		oForm.Controls.Add(CheckBox3)' Add the check box control to the form.
		AddHandler CheckBox3.Click, AddressOf checkBox3_Click
		
		Dim NameBox3 As New System.Windows.Forms.TextBox
		With NameBox3
			.Top = CheckBox3.Top
			.Left = CheckBox3.Right +25
			.Width = 200
			.Height = 25
			.Name = "oNameBox3"
			.Text = "SAT"
			.Enabled = False
		End With
		oForm.Controls.Add(NameBox3)
		']
		
		'[Check Box4
		Dim CheckBox4 As New System.Windows.Forms.CheckBox'Create and initialize a CheckBox. 
			With CheckBox4 
			.Text = "PROCESS ALL"
			.Top = CheckBox3.Bottom 
			.Left = 25
			.Width = 20
			.Height = 25
			.Name = "oCheckBox4"
			.Appearance = Appearance.Normal ' Make the check box control appear as a toggle button.
			.AutoCheck = True 'Turn off the update of the display on the click of the control.
		End With
		oForm.Controls.Add(CheckBox4)' Add the check box control to the form.
		AddHandler CheckBox4.Click, AddressOf checkBox4_Click
		
		Dim NameBox4 As New System.Windows.Forms.TextBox
		With NameBox4
			.Top = CheckBox4.Top
			.Left = CheckBox4.Right +25
			.Width = 200
			.Height = 25
			.Name = "oNameBox4"
			.Text = "PROCESS ALL"
			.Enabled = False
		End With
		oForm.Controls.Add(NameBox4)
		']
	
		Dim oStartButton As New System.Windows.Forms.Button
		With oStartButton
			.Text = "START"
			.Top = CheckBox4.Bottom + 10
			.Left = 25
			.Height = 25
			.Width = 75
			.Enabled = True
			.Name = "StartBox"
		End With
		oForm.AcceptButton = oStartButton
		oForm.Controls.Add(oStartButton)
		AddHandler oStartButton.Click, AddressOf oStartButton_Click	
		
		Dim oCancelButton As New System.Windows.Forms.Button
		With oCancelButton
			.Text = "CANCEL"
			.Top = oStartButton.Top
			.Left = oStartButton.Right + 10
			.Height = 25
			.Width = 75
			.Enabled = True
			.Name = "CancelBox"
		End With
		oForm.AcceptButton = oCancelButton
		oForm.Controls.Add(oCancelButton)
		AddHandler oCancelButton.Click, AddressOf oCancelButton_Click		
	End Sub
			
	Private Sub checkBox1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
	    Dim oBox1 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox1")
		If oBox1.Checked = True
			Operation.add(oBox1.Text)
	    Else
			Operation.Remove(oBox1.Text)
	    End If
	End Sub

	Private Sub checkBox2_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)		
	    Dim oBox2 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox2")
		If oBox2.Checked = True
			Operation.add(oBox2.Text)
	    Else
			Operation.Remove(oBox2.Text)
	    End If
	End Sub

	Private Sub checkBox3_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)		
	    Dim oBox3 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox3")
		If oBox3.Checked = True
			Operation.add(oBox3.Text)
	    Else
			Operation.Remove(oBox3.Text)
	    End If
	End Sub
	
	Private Sub checkBox4_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)		
	    Dim oBox1 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox1")
		Dim oBox2 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox2")
		Dim oBox3 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox3")
		Dim oBox4 As System.Windows.Forms.CheckBox = Me.Controls.Item("oCheckBox4")
		If oBox4.Checked = True
			oBox1.Checked = True
			oBox2.Checked = True
			oBox3.Checked = True
			Operation.add(oBox4.Text)
	    Else
			oBox1.Checked = False
			oBox2.Checked = False
			oBox3.Checked = False
			Operation.Remove(oBox3.Text)
	    End If
	End Sub

	Private Sub oStartButton_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		Me.Close
		ProcessRefDocuments(ThisApplication.ActiveDocument)
	End Sub

	Private Sub oCancelButton_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		Me.Close
	End Sub
		
		
	Sub ProcessRefDocuments(oDoc As Document)
		Dim oDXFDirectory As String
		Dim oStepDirectory As String
		Dim oStpFullFileName As String
		Dim oSatDirectory As String
		Dim oSatFullFileName As String 
		Dim oDxfFullFileName As String 
		Dim oAsmPN As String = oDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value

		If Operation.Contains("DXF")Or Operation.Contains("PROCESS ALL") Then
			oDXFDirectory = CreateFolder(oDoc, " DXF Files")
		End If
		If Operation.Contains ("STEP") Or Operation.Contains("PROCESS ALL") Then'Or Operation.Contains("PROCESS ALL")
			oStepDirectory = CreateFolder(oDoc, "STEP Files")
			oStpFullFileName = oStepDirectory & "\" & oAsmPN & ".stp"
			SaveAs(oDoc, oStpFullFileName)
		End If
		If Operation.Contains ("SAT") Or Operation.Contains("PROCESS ALL") Then 
			oSatDirectory = CreateFolder(oDoc, " SAT Files")
			oSatFullFileName = oSatDirectory & "\" & oAsmPN & ".sat"
			SaveAs(oDoc,oSatFullFileName)
		End If
		
		'Look at the files referenced by the assembly and work the referenced models.
		For Each oRefDoc As Document In oDoc.AllReferencedDocuments  
			If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
		    
			Dim oModelPN As String = oRefDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
		  	
			If Operation.Contains("STEP") Or Operation.Contains("PROCESS ALL")Then
				oStpFullFileName = oStepDirectory & "\" & oModelPN & ".stp"
				oStpFullFileName = Nothing
				SaveAs(oRefDoc, oStpFullFileName)
			End If
			If Operation.Contains ("SAT") Or Operation.Contains("PROCESS ALL") Then	
				oSatFullFileName = Nothing
				oSatFullFileName = oSatDirectory & "\" & oModelPN & ".sat"
				SaveAs(oRefDoc, oSatFullFileName)
			End If
			If Operation.Contains("DXF")  Or Operation.Contains("PROCESS ALL")Then
				'FilterSheetmetal Parts.
				If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
					oDxfFullFileName = Nothing
					oDxfFullFileName  = oDXFDirectory & "\" & oModelPN & ".dxf"
					CreateDXF(oRefDoc ,oDxfFullFileName)
				End If
			End If
		Next
		MessageBox.Show("Batch Processing Rule Finished!","iLogic")
	End Sub

	Function CreateFolder(oDoc As Document, oFolderName As String ) As String
		Dim oPath As String = IO.Path.GetDirectoryName(oDoc.FullFileName)
		Dim oAsmName As String = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
		'Get Target folder path.
		Dim oFolder As String = oPath & "\" & oAsmName & " " & oFolderName
		'Check For the Step folder And create it If it does Not exist.
		If Not System.IO.Directory.Exists(oFolder) Then
			System.IO.Directory.CreateDirectory(oFolder)
		End If

		Return oFolder
	End Function

	Sub SaveAs(oDoc,oFullFileName)
		  Try  	
		       	oDoc.SaveAs(oFullFileName, True)
		  Catch ex As Exception
				'Logger.Info("Error Saving As " & oFullFileName)
		  End Try
	End Sub

	Sub CreateDXF(oDoc As PartDocument, oFullFileName As String)
	
		Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
		Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
		oDataMedium.FileName = oFullFileName
		
		oDoc = ThisApplication.Documents.Open(oDoc.FullFileName, False)
		Try
			Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
			If oCompDef.HasFlatPattern = False Then
				oCompDef.Unfold
			Else
				oCompDef.FlatPattern.Edit
			End If

			Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2010&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerColor=0;0;255"& _
					  "&TangentLayer=IV_TANGENT&TangentLayerColor=255;0;0&BendUpLayer=IV_BEND&BendUpLayerColor=255;255;0"& _
					  "&BendDownLayer=IV_BEND_DOWN&BendDownLayerColor=255;128;0&InteriorProfilesLayer=IV_INTERIOR_PROFILES"& _
					  "&InteriorProfilesLayerColor=255;0;0&MergeProfilesIntoPolyline=True"
					'MessageBox.Show("Message", "Title")
	  
			oCompDef.DataIO.WriteDataToFile(sOut, oDataMedium.FileName)
			oCompDef.FlatPattern.ExitEdit
		Catch
		End Try
		oDoc.Close
	End Sub

End Class

Public Class RunMyForm
	Private Sub Main
		Dim oMyForm As New WinForm
		oMyForm.Show
	End Sub
	End Class

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 7

gary.creaney
Explorer
Explorer

Thank you very much for taking the time to look at this which I fully appreciate you do not need to do.

 

Unfortunately there are a couple of things not working as hoped.
1) It's not picking up any DXFs - just creates a blank folder
2) It only creates a step file of the assembly not the individual parts

 

SAT files are good (creates a SAT file of the assembly + the individual parts) and this is how I would like the STEP files to be outputted as well.

 

One thing I mentioned in the original post was that the final output would be for all the DXFs, SATs & STEPs to go into one containing folder to EXACTLY match the name of the assembly from which they are being exported.

Perhaps you could afford me time for one more look at it? Understood if you can't but thanks again.

0 Likes
Message 7 of 7

A.Acheson
Mentor
Mentor

Hi @gary.creaney 

I noticed the step files were not being created for the individual files but your original code did not do this also. Did this work before? Dxf files were working for sheetmetal parts. Maybe you can change the open as visible(boolean option) to true to ensure it is creating a flatpattern. If it errors out for whatever reason no dxf is created. 

 

For the folder, you can copy the function into a different rule to test its output. 

Here is a sample of what The folder will look like. This will be the folder for all outputted files with no subfolder. Once the function works for you just swab it in the main code and it's calling line. 

 

Sub Main
  Dim oDoc AssemblyDocument = ThisDoc.Document 
 oDXFDirectory = CreateFolder(oDoc)
  Messagebox.show(oDXFDirectory)
End Sub
Function CreateFolder(oDoc As Document) As String
		Dim oPath As String = IO.Path.GetDirectoryName(oDoc.FullFileName)
		Dim oAsmName As String = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
		'Get Target folder path.
		Dim oFolder As String = oPath & "\" & oAsmName
		'Check for the folder And create it If it does Not exist.
		If Not System.IO.Directory.Exists(oFolder) Then
			System.IO.Directory.CreateDirectory(oFolder)
		End If

		Return oFolder
	End Function

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes