Ilogic - Export sheetmetal parts in an assembly to IGES format

Ilogic - Export sheetmetal parts in an assembly to IGES format

Anonymous
Not applicable
974 Views
9 Replies
Message 1 of 10

Ilogic - Export sheetmetal parts in an assembly to IGES format

Anonymous
Not applicable

All of our bent parts need to be sent down to our CNC dept as IGES files. I've found an Ilogic rule to export every file in an assembly to IGES, but I only need it to do it to the sheetmetal parts. I'm learning how to deal with Ilogic, but this one is way over my head so far. 

0 Likes
Accepted solutions (1)
975 Views
9 Replies
Replies (9)
Message 2 of 10

MechMachineMan
Advisor
Advisor

So post your code here then?

 

All it requires is a simple tweak to add in "If part is sheet metal, export, otherwise, do nothing".


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 10

Anonymous
Not applicable

Sorry, here's the code that I found that exports everything.

 

SyntaxEditor Code Snippet

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'define folder to create files in
oFolder = "c:\temp\IGS Files"

 'Check for the destination folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments                
'format  file name                   
Dim FNamePos As Long
'postion of last back slash
FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
Dim docFName As String 
'file name with extension
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 
'file name without extension
shortname = Left(docFName, Len(docFName) -4) 

	' Get the IGES translator Add-In.
	Dim oIGESTranslator As TranslatorAddIn
	oIGESTranslator = ThisApplication.ApplicationAddIns.ItemById _ 
	("{90AF7F44-0C01-11D5-8E83-0010B541CD80}")
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	If oIGESTranslator.HasSaveCopyAsOptions(docFile, oContext, oOptions) Then
	   ' Set geometry type for wireframe.
	   ' 0 = Surfaces, 1 = Solids, 2 = Wireframe
	   'oOptions.Value("GeometryType") = 1
	   ' To set other translator values:
	   ' oOptions.Value("SolidFaceType") = n
	   ' 0 = NURBS, 1 = Analytic
	   ' oOptions.Value("SurfaceType") = n
	   ' 0 = 143(Bounded), 1 = 144(Trimmed)
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oData As DataMedium
	oData = ThisApplication.TransientObjects.CreateDataMedium
	'set file path for IGS file
	oData.FileName =  oFolder & "\" & shortname & ".igs"
	oIGESTranslator.SaveCopyAs(docFile, oContext, oOptions, oData)
	End If
Next
0 Likes
Message 4 of 10

Anonymous
Not applicable

Sorry, Here is the code I found that exports everything as an IGES

 

SyntaxEditor Code Snippet

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'define folder to create files in
oFolder = "c:\temp\IGS Files"

 'Check for the destination folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments                
'format  file name                   
Dim FNamePos As Long
'postion of last back slash
FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
Dim docFName As String 
'file name with extension
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 
'file name without extension
shortname = Left(docFName, Len(docFName) -4) 

	' Get the IGES translator Add-In.
	Dim oIGESTranslator As TranslatorAddIn
	oIGESTranslator = ThisApplication.ApplicationAddIns.ItemById _ 
	("{90AF7F44-0C01-11D5-8E83-0010B541CD80}")
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	If oIGESTranslator.HasSaveCopyAsOptions(docFile, oContext, oOptions) Then
	   ' Set geometry type for wireframe.
	   ' 0 = Surfaces, 1 = Solids, 2 = Wireframe
	   'oOptions.Value("GeometryType") = 1
	   ' To set other translator values:
	   ' oOptions.Value("SolidFaceType") = n
	   ' 0 = NURBS, 1 = Analytic
	   ' oOptions.Value("SurfaceType") = n
	   ' 0 = 143(Bounded), 1 = 144(Trimmed)
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oData As DataMedium
	oData = ThisApplication.TransientObjects.CreateDataMedium
	'set file path for IGS file
	oData.FileName =  oFolder & "\" & shortname & ".igs"
	oIGESTranslator.SaveCopyAs(docFile, oContext, oOptions, oData)
	End If
Next
0 Likes
Message 5 of 10

Anonymous
Not applicable

Sorry, Here is the code I found that exports all the parts in the assembly

 

SyntaxEditor Code Snippet

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'define folder to create files in
oFolder = "c:\temp\IGS Files"

 'Check for the destination folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments                
'format  file name                   
Dim FNamePos As Long
'postion of last back slash
FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
Dim docFName As String 
'file name with extension
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 
'file name without extension
shortname = Left(docFName, Len(docFName) -4) 

	' Get the IGES translator Add-In.
	Dim oIGESTranslator As TranslatorAddIn
	oIGESTranslator = ThisApplication.ApplicationAddIns.ItemById _ 
	("{90AF7F44-0C01-11D5-8E83-0010B541CD80}")
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	If oIGESTranslator.HasSaveCopyAsOptions(docFile, oContext, oOptions) Then
	   ' Set geometry type for wireframe.
	   ' 0 = Surfaces, 1 = Solids, 2 = Wireframe
	   'oOptions.Value("GeometryType") = 1
	   ' To set other translator values:
	   ' oOptions.Value("SolidFaceType") = n
	   ' 0 = NURBS, 1 = Analytic
	   ' oOptions.Value("SurfaceType") = n
	   ' 0 = 143(Bounded), 1 = 144(Trimmed)
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oData As DataMedium
	oData = ThisApplication.TransientObjects.CreateDataMedium
	'set file path for IGS file
	oData.FileName =  oFolder & "\" & shortname & ".igs"
	oIGESTranslator.SaveCopyAs(docFile, oContext, oOptions, oData)
	End If
Next
0 Likes
Message 6 of 10

Anonymous
Not applicable

I'm trying to reply to this and my replies aren't posting.

 

Okay, I was able to post without the code and then edit to include it. 

Here is the code I found that exported all of the parts as Iges

 

SyntaxEditor Code Snippet

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'define folder to create files in
oFolder = "c:\temp\IGS Files"

 'Check for the destination folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments                
'format  file name                   
Dim FNamePos As Long
'postion of last back slash
FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
Dim docFName As String 
'file name with extension
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 
'file name without extension
shortname = Left(docFName, Len(docFName) -4) 

	' Get the IGES translator Add-In.
	Dim oIGESTranslator As TranslatorAddIn
	oIGESTranslator = ThisApplication.ApplicationAddIns.ItemById _ 
	("{90AF7F44-0C01-11D5-8E83-0010B541CD80}")
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	If oIGESTranslator.HasSaveCopyAsOptions(docFile, oContext, oOptions) Then
	   ' Set geometry type for wireframe.
	   ' 0 = Surfaces, 1 = Solids, 2 = Wireframe
	   'oOptions.Value("GeometryType") = 1
	   ' To set other translator values:
	   ' oOptions.Value("SolidFaceType") = n
	   ' 0 = NURBS, 1 = Analytic
	   ' oOptions.Value("SurfaceType") = n
	   ' 0 = 143(Bounded), 1 = 144(Trimmed)
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oData As DataMedium
	oData = ThisApplication.TransientObjects.CreateDataMedium
	'set file path for IGS file
	oData.FileName =  oFolder & "\" & shortname & ".igs"
	oIGESTranslator.SaveCopyAs(docFile, oContext, oOptions, oData)
	End If
Next

 

0 Likes
Message 7 of 10

Anonymous
Not applicable

I've tried to post the code 4 or 5 times now, every time I do my post is deleted and I'm told it's because it's spam. I've messaged a moderator to tell me what's going on.

0 Likes
Message 8 of 10

BrianEkins
Mentor
Mentor
Accepted solution

I believe the rule below will do it.  However, you didn't say if you want the folded or flat pattern of the sheet metal part.  I don't believe Inventor supports exporting a flat pattern as IGES.  The rule below will export the folded model.  It would be possible to work around the limitation and still export the flat but it wouldn't contain any fold or bend lines.

 

Public Sub Main()
	ExportSheetMetalAsIGES("C:\Temp\")
End Sub

Public Sub ExportSheetMetalAsIGES(folder As String)
	If ThisDoc.Document.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("The active document must be an assembly.")
		Return
	End If

	Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document	
	
	' Iterate through each document in the assembly, looking for sheet metal parts.
	For Each doc As Inventor.Document In asmDoc.AllReferencedDocuments
		' Check for sheet metal document.
		If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			' Do a Save Copy As of the document to create the IGES file.
			doc.SaveAs(folder & System.IO.Path.GetFileNameWithoutExtension(doc.FullFileName) & ".igs", True)
		End If
	Next
End Sub
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 9 of 10

Anonymous
Not applicable

Perfect! This is exactly what I was looking for. 

Thanks for your help.

0 Likes
Message 10 of 10

gflessasP4B6Q
Explorer
Explorer

@BrianEkins , I'm not sure if you're still around 4 years later, but is it possible to tweak this code to save the .igs file as the Parts part number, instead of the Parts file name? 

The problem I'm running in to is that I can only get it to save as the Assemblies part number.

 

Thanks!

 

0 Likes