iLogic rule to export files of an assembly to dxf and stp

iLogic rule to export files of an assembly to dxf and stp

cedric.pollet
Explorer Explorer
3,875 Views
4 Replies
Message 1 of 5

iLogic rule to export files of an assembly to dxf and stp

cedric.pollet
Explorer
Explorer

Hello all,

 

We make and design machinery and use subcontractors to do the laser and/or bending of our designs. I'm looking for a quicker way to prepare the files to send to our subcontractors (step files for laser + bending and dxf files for laser and engraving).

 

We have a system in which we use the iproperties as follows:

Vendor: if value = "L" then the file needs to be lasered only, if value= "LP" then the file needs to be lasered and bent

 

If an assembly is ready, I would like to press a button so all the files that need to be sent to the subcontractor are being saved as an step or dxf file in a folder. They are saved by their name in the iProperty 'description'.

 

To do this I have created a rule. The part to save the ipt as a step file works, however the dxf's don't get created.

I have put in tracers via debugview and the code stops after "Tracer05". It is caught by the try

 

Here is the code:

 

 
Sub Main()
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument  
	'Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1)
	
	trace.Writeline("Debug started ExtRule_DXF_STP_ExportLaser")
	MsgBox("Beta versie" + vbLf + "CEP 12/9/2017" +vbLf + "Opgepast ! DXF export nog niet in orde voor L stukken !")
	
	Dim oDescription As String
	Dim oVendor As String
	Dim Teller As Integer
	
	Dim oDoc As Document
	For Each oDoc In oAsmDoc.AllReferencedDocuments
		'Check if oDoc is an ipt file..
		If oDoc.DocumentType= kPartDocumentObject Then	
			Dim oPartDoc As PartDocument
			oPartDoc = oDoc
			Dim model As String = oPartDoc.DisplayName
			model = model & ".ipt"
			
			Try
				oDescription = iProperties.Value(model,"Project", "Description")
				oVendor = iProperties.Value(model, "Project", "Vendor")
				
				teller = teller + 1
				
				'Path dir and create if needed
				Dim sPath As String
				sPath = "C:\Temp\ExportLaser"
				
				If Not System.IO.Directory.Exists(sPath) Then
					System.IO.Directory.CreateDirectory(sPath)
				End If
				
				Dim sFileName As String
				Dim bStepFile As Boolean = False
				
				'If first letter of iprop Vendor = "L" then continue
				If Left(oVendor,1) = "L" Then
					
					
					trace.WriteLine("Laserstuk gedetecteerd !")
					
					'If oVendor = "LP", file needs to be lasered and bent by subcontractor => create stepfile
					If Left(oVendor,2) = "LP" Then
					trace.WriteLine("LPlooistuk gedetecteerd !")
					'doe export naar STP
					sFileName = oDescription.ToString()+".stp"
					oPartDoc.SaveAs(sPath+"\"+sFileName, True)
					trace.WriteLine("Result SaveAs:" + sFileName + " " + teller.ToString())
					bStepFile = True
					
					End If
									
					'If oVendor = "L", file needs only be lasered and engraved => create unfold and save this as DXF file
					If bStepFile = False Then
						sFileName = oDescription.ToString()+".dxf"
						'oPartDoc = ThisApplication.ActiveDocument
						Trace.WriteLine(sFileName)
						
						Dim oCompDef As SheetMetalComponentDefinition
						
						oCompDef = oPartDoc.ComponentDefinition
						'oCompDef = oDoc.ComponentDefinition
						
						Trace.WriteLine("Tracer05")
						If oCompDef.HasFlatPattern = False Then
							Trace.WriteLine("Creëer ontvouwing..")
							oCompDef.Unfold
						
						Else
							Trace.WriteLine("Ontvouwing bestaat al...")
							oCompDef.FlatPattern.Edit
							Trace.Writeline("Tracer07")
						
						End If
						Trace.Writeline("Tracer10")
						
						Dim sOut As String
						'RGB Geel= 255;255;0
						'RGB Rood= 255;0;0
						sOut = "FLAT PATTERN DXF?AcadVersion=2013&OuterProfileLayerColor=255;0;0&InteriorProfilesLayerColor=255;0;0&BendUpLayerColor=255;255;0&BendDownLayerColor=255;255;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"
						
						oCompDef.DataIO.WriteDataToFile( sOut, sFilename)
			
						trace.Writeline("DXF opgeslagen als: " & sFilename ,"DXF Saved")
						Dim oSMDef As SheetMetalComponentDefinition
						oSMDef = oDoc.ComponentDefinition
						oSMDef.FlatPattern.ExitEdit
			
						trace.WriteLine("Result SaveAs:" + sFileName + " " + teller.ToString())
					End If
	
				End If
				
				Catch
				trace.WriteLine("Error bij Try: " + model.ToString() )
				
				
			End Try
		End If
	Next

	MsgBox("Export geëindigd.")
End Sub 

Can anyone help me with the code ?

 

Thanks in advance !

 

Greetings

Cedric

 

0 Likes
Accepted solutions (1)
3,876 Views
4 Replies
Replies (4)
Message 2 of 5

cedric.pollet
Explorer
Explorer

Does anyone have an iLogic sample to run through an assembly and export the sheetmetal files to dxf ? I have found code to do this for a single ipt file, but this doesn't work when you execute the code in an assembly.

 

Thanks in advance

 

 

0 Likes
Message 3 of 5

Rob67ert
Collaborator
Collaborator
Accepted solution

Hi,

I have found this, but still need some time to adjust it to our needs: 

 

SyntaxEditor Code Snippet

'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=2004&OuterProfileLayer=IV_OUTER_PR?OFILE"
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

 

Robert

If you find this reply helpful ? It would be nice if you use the Accept as Solution or Kudos button below.
Message 4 of 5

cedric.pollet
Explorer
Explorer

Allright, your code seems to work Robert, thank you very much

 

I will analyze your rule and try to integrate it to work with my rule above

 

Thank you for your reply !

0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi Robert, 

 

This code seems to work quite well, but I'm wondering what for U need this part: 

oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

Thanks in advance for an explanation. 

0 Likes