Help with saving copy as iges or step of part within assembly

Help with saving copy as iges or step of part within assembly

dschulteHR4D5
Advocate Advocate
3,006 Views
47 Replies
Message 1 of 48

Help with saving copy as iges or step of part within assembly

dschulteHR4D5
Advocate
Advocate

Hello all, I am looking for some assistance with iLogic coding... Let me try to explain what i am looking for here, bear with me.

 

For my workflow, i am designing one-off tooling that trims plastic blow molded parts. We have an in house tool room where we design and build most of the tooling we use. With that being said, we build some of the parts, some times some of them get sent out to other companies to build then we assemble depending on the job. 

 

So i will design an entire project for say a trim station, and the parts we build i will save as an igs for our cnc department to use. Then some of the companies need the files as a stp and the drawings as a dxf. 

 

What i am trying to do essentially is take the entire assembly, and hide the parts i do not want to convert to say an iges. But when i use this code it saves everything in the assembly, and i believe it saves assemblies within the assembly as an iges as well, whereas i want each individual part saved as an iges, not the whole assembly. So it seems i need to add something to recognize only visible items, and to only select parts, not assemblies within the assembly. Is this possible? This is the current code i am using right now. 

 

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


'path from current file
oFolder = ThisDoc.WorkspacePath() & "\CNC 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

 This code also checks and makes a folder for CNC FILES if there isnt one there, as mentioned, i use this for our CNC department so it works, but it seems like it saves subassemblies as one igs file, and not the individual parts within a subassembly. 

 

Also i would like to map out how to reference if i translate to an step file, to find a reference drawing of that part and also save the drawing as a dxf if this would be possible. 

 

Thanks for any help!! Ill take anything i can get for knowledge of this, i am pretty new to ilogic but have made this code from cross referencing a number of posts and different codes and eventually got it to work. 

0 Likes
Accepted solutions (4)
3,007 Views
47 Replies
Replies (47)
Message 21 of 48

WCrihfield
Mentor
Mentor

Glad to hear that it is generating the files now.  To avoid the confusion over settings within the .ini file, you could always export a .idw to .dxf manually, through the File menu's SaveAs tool.  Then while the file browser screen is open, click the [Options...] button (next to the Save button) to open the 'DXF File Export Options' dialog, then carefully go through everything and set it the way you want (don't forget the [Next >] button at the bottom, which will advance to more options).  Then on that second page of options, click the [Save Configuration...] button and pay attention to the file location and name you give it, so you can put that into the code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 22 of 48

dschulteHR4D5
Advocate
Advocate
Yeah i am playing with that now. Seems to be working as it should, but just need to be at the shop to verify, i havent really opened dxf files with inventor so not sure if it is normal, but when i save as it is using the ini file for the settings, so that is good, but when i go to open, select dxf file, it pulls open the DWG/DXF file wizard every time, i try to select the options through there, map it to the import settings but still comes up. SO not sure if this is normal or not but i dont normally open them anyways
0 Likes
Message 23 of 48

dschulteHR4D5
Advocate
Advocate
Is there a quick way to add a code, after everything is all said and done, to open the workspace folder location... after exports are complete open WSpath folder location?
0 Likes
Message 24 of 48

dschulteHR4D5
Advocate
Advocate
this is the full working code right now

Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document

Dim oWSPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oSTEPFilesFolder = oWSPath & "\STEP FILES"
If Not System.IO.Directory.Exists(oSTEPFilesFolder) Then
System.IO.Directory.CreateDirectory(oSTEPFilesFolder)
End If
oDXFFilesFolder = oWSPath & "\DXF FILES"
If Not System.IO.Directory.Exists(oDXFFilesFolder) Then
System.IO.Directory.CreateDirectory(oDXFFilesFolder)
End If

oOccs = oADoc.ComponentDefinition.Occurrences
IterateComponentsRecursively(oOccs)
MsgBox("All Exports Complete.", vbInformation, "")
ThisApplication.Documents.CloseAll(True)
End Sub

Dim oSTEPFilesFolder As String
Dim oDXFFilesFolder As String
Dim oProcessedDocs As List(Of PartDocument)

Sub IterateComponentsRecursively(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
'only process Visible components
If oComp.Visible = False Then Continue For
'if it is Visible, and an Assembly, recursively process its components
If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
IterateComponentsRecursively(oComp.Definition.Occurrences)
End If
'make sure it is a Part
If oComp.DefinitionDocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
If Not TypeOf oComp.Definition Is PartComponentDefinition Then Continue For
Dim oPDoc As PartDocument = oComp.ReferencedDocumentDescriptor.ReferencedDocument
If IsNothing(oProcessedDocs) Then oProcessedDocs = New List(Of PartDocument)
'if we have already processed this referenced document, skip to next component
If oProcessedDocs.Contains(oPDoc) Then Continue For
Dim oFileName As String = System.IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)
Dim oSTEPFullFileName As String = oSTEPFilesFolder & "\" & oFileName & ".stp"
'run other custom Sub routine here that does main work of rule
ExportToSTEP(oPDoc, oSTEPFullFileName)
Dim oDrawDoc As DrawingDocument = GetDrawing(oPDoc)
If Not IsNothing(oDrawDoc) Then
Dim oDXFFullFileName As String = oDXFFilesFolder & "\" & oFileName & ".dxf"
ExportIDWtoDXF(oDrawDoc, oDXFFullFileName)
End If
Next
End Sub

Sub ExportToSTEP(oDoc As Document, oNewFileName As String)
Dim oSTEP As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
"{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
If IsNothing(oSTEP) Then
MsgBox("STEP Translator Add-in not found. Exiting.", vbCritical, "")
'Logger.Debug("STEP Translator Add-in not found.")
Exit Sub
End If

'create needed variables for translator
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium

If System.IO.File.Exists(oNewFileName) Then
oAns = MsgBox("A STEP file with this name already exists." & vbCrLf &
"Do you want to overwrite it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "STEP FILE EXISTS")
If oAns = vbNo Then Exit Sub
End If
oDataMedium.FileName = oNewFileName

If oSTEP.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
'oOptions.Value("ApplicationProtocolType") = 3
'oOptions.Value("IncludeSketches") = True
'oOptions.Value("export_fit_tolerance") = .000393701 'minimum
'oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = iProperties.Value("Summary", "Title")
'oOptions.Value("Organization") = iProperties.Value("Summary", "Company")
Try
oSTEP.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
Catch
MsgBox("Your attempt to export this document as a STEP file FAILED!", vbExclamation, "Export to STEP Error")
'Logger.Error("Export to STEP failed.")
End Try
End If
End Sub

Function GetDrawing(oModelDoc As Document) As DrawingDocument
oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim oDrawingsFolder As String = oWSPath & "\DRAWINGS"
oFileName = System.IO.Path.GetFileNameWithoutExtension(oModelDoc.FullFileName)
Dim oDrawingFile As String = oDrawingsFolder & "\" & oFileName & ".idw"
If System.IO.File.Exists(oDrawingFile) Then
Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(oDrawingFile, False)
Return oDrawingDoc
Else
' MsgBox("A Drawing File Named:" & vbCrLf & oDrawingFile & vbCrLf & _
' "Could not be found.", vbExclamation, "")
End If
Return Nothing
End Function

Sub ExportIDWtoDXF(oDrawing As DrawingDocument, oNewFullFileName As String)
Dim oDXF As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
If IsNothing(oDXF) Then
MsgBox("DXF Translator Add-in not found. Exiting.", vbCritical, "")
'Logger.Debug("DXF Translator Add-in not found.")
Exit Sub
End If

'create needed variables for translator
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium

If System.IO.File.Exists(oNewFullFileName) Then
oAns = MsgBox("A DXF file with this name already exists." & vbCrLf &
"Do you want to overwrite it with this new one?", vbYesNo + vbQuestion + vbDefaultButton2, "DXF FILE EXISTS")
If oAns = vbNo Then Exit Sub
End If
oDataMedium.FileName = oNewFullFileName
'<<<< CHANGE THIS IF NEEDED >>>>
Dim oINI_File As String = "C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\exportdxf.ini"
If Not System.IO.File.Exists(oINI_File) Then
MsgBox("Couldn't find this INI file: " & oINI_File & ". Exiting.", vbExclamation, "")
Exit Sub
End If
If oDXF.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = oINI_File
End If
Try
oDXF.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
Catch oEx As Exception
MsgBox("SaveCopyAs method of the ExportIDWtoDXF Sub routine failed." & vbCrLf & _
"While trying to export the following Drawing file: " & vbCrLf & _
oDrawing.FullFileName & vbCrLf & _
"as the following dxf file: " & vbCrLf & _
oNewFileName & vbCrLf & _
oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "")
'Logger.Error(oEx.Message & vbCrLf & oEx.StackTrace)
oDrawing.ReleaseReference
End Try
End Sub

0 Likes
Message 25 of 48

WCrihfield
Mentor
Mentor
Accepted solution

Sure.  This is the absolute simplest way to do that, but there are lots of other ways too.

ThisDoc.Launch(ThisDoc.WorkspacePath)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 26 of 48

sanil_heartbeats
Contributor
Contributor

This is not the full program, but includes major parts

 

 

Dim invBOM As BOM
invBOM = invAssy.ComponentDefinition.BOM

invBOM.PartsOnlyViewEnabled = True
Dim invPartOnlyView As BOMView
invPartOnlyView = invBOM.BOMViews.Item("Parts Only")
Dim invBomRow As BOMRow = Nothing
Dim invPart As PartDocument = Nothing

Dim FNamePos As Long
Dim docFName As String 

'path from current file
oFolder = ThisDoc.WorkspacePath() & "\CNC 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

Dim oIGESTranslator As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oData As DataMedium

	Try
		For Each invBomRow In invPartOnlyView.BOMRows
			' Her you get each individual part in the assembly
			invPart = invBomRow.ComponentDefinitions.Item(1).Document

			' Check for part visiblilty & skip if hidden
			If invPart.Visible = False Then Continue For

			'postion of last back slash
			FNamePos = InStrRev(invPart.FullFileName, "\", -1)                        
			'file name with extension
			docFName = Right(invPart.FullFileName, Len(invPart.FullFileName) - FNamePos) 
			'file name without extension
			shortname = Left(docFName, Len(docFName) -4)

			' Get the IGES translator Add-In.
			oIGESTranslator = ThisApplication.ApplicationAddIns.ItemById _ 
			("{90AF7F44-0C01-11D5-8E83-0010B541CD80}")
			
			oContext = ThisApplication.TransientObjects.CreateTranslationContext
			
			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
				oData = ThisApplication.TransientObjects.CreateDataMedium
				'set file path for IGS file
				oData.FileName =  oFolder & "\" & shortname & ".igs"
				oIGESTranslator.SaveCopyAs(invPart, oContext, oOptions, oData)
			End If
		Next
	Catch ex As Exception
		MsgBox(ex.Message)
	End Try

 

 

you can get individual parts in an assy from BOM. only catch is that the assembly should not have any resolved constraints or components. i havent tested it thought. try it out and please let me know too...

0 Likes
Message 27 of 48

sanil_heartbeats
Contributor
Contributor
One correction

oIGESTranslator.SaveCopyAs(invPart, oContext, oOptions, oData)
0 Likes
Message 28 of 48

dschulteHR4D5
Advocate
Advocate
ill have to look into this when i get extra time, working on getting this one final, getting close!
0 Likes
Message 29 of 48

dschulteHR4D5
Advocate
Advocate

So got it working, changed a few things around, i ended up adding a save as pdf after the save as dxf, i noticed while experimenting with the code, parts that didnt have a referenced document, still saved as a stp and didnt show that there wasn't a referenced idw, so i am trying to look into adding a message box,

 

if it checks a part that doesn't have a referenced idw, could it be possible to add a message box that would say, skip sub, or retry, basically, if it finds a part that i dont need to save as, skip the sub for that part to save as all together, and retry would be a part i need a idw for, so i could on the fly open the part and make an idw, and retry that sub to finish the save as process

0 Likes
Message 30 of 48

WCrihfield
Mentor
Mentor
Accepted solution

It looks like there is already a MsgBox within the 'GetDrawing' function for when it does not find a drawing, but it is currently commented out.  We could have something similar within the Sub Main part of the code, just after the line of code that calls that function to run:

 

Dim oDrawDoc As DrawingDocument = GetDrawing(oPDoc)

 

...most likely within an If...Then type block that checks if it returned a drawing, on the 'no it did not return one' side of it.  We could put a message there, but we could also record (one way or another) which source document (oPDoc) did not have a drawing.  Maybe put it in a list, or write its FullFileName out to a text file, or something similar, then we would know after the run which ones you may need to deal with all at once.  You could also just comment out the feedback questions about overwriting existing PDF or DXF files, and just have it not overwrite them.  That way, you could just run the whole process again, and it will only generate new files for the ones that don't already have those PDF, STEP, or DXF files where they are supposed to be, and not overwrite any of the existing ones.  Just a thought.  It kind of sounds like you want the main process to be paused for an unknown amount of time, when it encounters a missing drawing document, and allow you to create a drawing document, then let you un-pause the process, let it find that new drawing, then continue to generate the DXF and/or PDF from it.  I'm not sure that is possible, or a good idea.  That rule is using your Inventor application, and the documents involved.  All that you would have to do to open these specific model documents and create new drawing documents for them would surely disrupt any iLogic rule process that may have been started beforehand.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 31 of 48

dschulteHR4D5
Advocate
Advocate
Yeah i noticed the messagebox in the code but wasnt showing up so not sure what was going on with that. and yeah i like that idea actually, makes sense to just run it again, and if it finds a saved file already just end sub for each of the save as functions. wasn't sure if it would be a good idea to do that part, wait for a message box reply, or just what, but as long as the message box can show it didn't find one at least as some sort of fail safe that would be cool
0 Likes
Message 32 of 48

dschulteHR4D5
Advocate
Advocate

Okay so, as of now i accepted some of your comments as solutions, I made more adjustments, probably will continue to do so as workflow requests it. BUT, so far, what this code does, makes folders for each STP, DXF, and PDF files in the project workspace, loops through components in the active assembly, if it is a part and has a referenced IDW, save each component as a STP, then save the IDW as a DXF and PDF in the appropriate workspace folder.

 

I have it configured to skip the STP if it doesn't have a referenced IDW, will show a message showing the filename, so if that pops up i can write it down quick, the rule will skip the rest of the steps and move onto the next component, then can just rerun the code once i resolve the missing IDWs. When i get extra time to play with the code, i would like to maybe add a filename list that shows each filename that doesn't have a referenced idw like you mentioned but for now showing each one individually works for now. Eventually when i get more time, i might look into adding code to check each component, if the material is PURCHASED, to skip the code altogether. I use the material property of the compent to drive the IDW to send to the customer, so PURCHASED would be a bought component we buy for the project, so a customer wouldn't be building that to begin with, so that would save some time having to make parts visible to run the code.

 

I tried to pretty up the code a little, theres parts of it i dont quite understand yet, but this experience with you has helped me understand alot more of what is going on in the code., for example, IterateComponentsRecursively sub, i feel like the way its written it should, if it finds a component with the same name, skip, so it doesn't have to cycle through the rest of the code so it doesn't prompt to save a copy over the existing file, but i set those subs to skip as of now anyways, the only time i see this being an issue, is if i send out the final stp, dxf, and pdf, and end up making a change to a component, at that point i would need to manually save each as, but at the same time for this specific workflow, the STP and DXF is what the customer would receive to build, so it should be finalized anyways at this point to run the code. 

 

But all in all, this is the full working code. THANK YOU SO MUCH!

 

Sub Main
'Make sure ASM document is active'
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If

Dim oADoc As AssemblyDocument = ThisDoc.Document

'Create folders in project workspace folder if not already there'
Dim oWSPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oSTEPFilesFolder = oWSPath & "\STEP FILES"
If Not System.IO.Directory.Exists(oSTEPFilesFolder) Then
System.IO.Directory.CreateDirectory(oSTEPFilesFolder)
End If
oDXFFilesFolder = oWSPath & "\DXF FILES"
If Not System.IO.Directory.Exists(oDXFFilesFolder) Then
System.IO.Directory.CreateDirectory(oDXFFilesFolder)
End If
oPDFFilesFolder = oWSPath & "\PDF FILES"
If Not System.IO.Directory.Exists(oPDFFilesFolder) Then
System.IO.Directory.CreateDirectory(oPDFFilesFolder)
End If

'Loop through components and define the save as criteria'
oOccs = oADoc.ComponentDefinition.Occurrences
IterateComponentsRecursively(oOccs)

'After completion show exports complete'
MsgBox("All Exports Complete.", vbInformation, "")

'Close any referenced documents'
ThisApplication.Documents.CloseAll(True)

'Open workspace folder'
ThisDoc.Launch(ThisDoc.WorkspacePath)
End Sub

Dim oSTEPFilesFolder As String
Dim oDXFFilesFolder As String
Dim oPDFFilesFolder As String
Dim oProcessedDocs As List(Of PartDocument)

Sub IterateComponentsRecursively(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
	
'Only process Visible components'
If oComp.Visible = False Then Continue For
	
'If component is Visible, and an Assembly, recursively process its components'
If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
IterateComponentsRecursively(oComp.Definition.Occurrences)
End If

'Make sure it is a Part'
If oComp.DefinitionDocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
If Not TypeOf oComp.Definition Is PartComponentDefinition Then Continue For
Dim oPDoc As PartDocument = oComp.ReferencedDocumentDescriptor.ReferencedDocument
If IsNothing(oProcessedDocs) Then oProcessedDocs = New List(Of PartDocument)
	
'If we have already processed this referenced document, skip to next component'
If oProcessedDocs.Contains(oPDoc) Then Continue For
Dim oFileName As String = System.IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)
Dim oSTEPFullFileName As String = oSTEPFilesFolder & "\" & oFileName & ".stp"

'Find component referenced drawing file'
Dim oDrawDoc As DrawingDocument = GetDrawing(oPDoc)
If Not IsNothing(oDrawDoc) Then
	
'Start sub routines to loop through save copy of component as STP and referenced IDW to DXF and PDF'	
ExportToSTEP(oPDoc, oSTEPFullFileName)
Dim oDXFFullFileName As String = oDXFFilesFolder & "\" & oFileName & ".dxf"
ExportIDWtoDXF(oDrawDoc, oDXFFullFileName)
Dim oPDFFullFileName As String = oPDFFilesFolder & "\" & oFileName & ".pdf"
ExportIDWtoPDF(oDrawDoc, oPDFFullFileName)
End If
Next
End Sub

'Export to STP sub'
Sub ExportToSTEP(oDoc As Document, oNewFileName As String)
Dim oSTEP As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
"{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
If IsNothing(oSTEP) Then
MsgBox("STEP Translator Add-in not found. Exiting.", vbCritical, "")
'Logger.Debug("STEP Translator Add-in not found.")
Exit Sub
End If

'Create needed variables for translator'
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium

'Exit sub if file extension exists otherwise continue save as process"
If System.IO.File.Exists(oNewFileName) Then
Exit Sub
End If 

oDataMedium.FileName = oNewFileName
If oSTEP.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
'oOptions.Value("ApplicationProtocolType") = 3
'oOptions.Value("IncludeSketches") = True
'oOptions.Value("export_fit_tolerance") = .000393701 'minimum
'oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = iProperties.Value("Summary", "Title")
'oOptions.Value("Organization") = iProperties.Value("Summary", "Company")
Try
oSTEP.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
Catch
MsgBox("Your attempt to export this document as a STEP file FAILED!", vbExclamation, "Export to STEP Error")
'Logger.Error("Export to STEP failed.")
End Try
End If
End Sub

'Find referenced IDW and continue save as process'
Function GetDrawing(oModelDoc As Document) As DrawingDocument
	oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	Dim oDrawingsFolder As String = oWSPath & "\DRAWINGS"
	oFileName = System.IO.Path.GetFileNameWithoutExtension(oModelDoc.FullFileName)
	Dim oDrawingFile As String = oDrawingsFolder & "\" & oFileName & ".idw"
'Reference IDW but don't open'
	If System.IO.File.Exists(oDrawingFile) Then
		Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(oDrawingFile, False)
		Return oDrawingDoc
	Else
MsgBox("A Drawing File Named:" & vbCrLf & oFileName & vbCrLf & _
"Could not be found.", vbExclamation, "")
	End If
	Return Nothing
End Function

'Start IDW to DXF'
Sub ExportIDWtoDXF(oDrawing As DrawingDocument, oNewFullFileName As String)
Dim oDXF As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
If IsNothing(oDXF) Then
MsgBox("DXF Translator Add-in not found. Exiting.", vbCritical, "")
'Logger.Debug("DXF Translator Add-in not found.")
Exit Sub
End If

'Create needed variables for translator'
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium

'Exit sub if file extension exists otherwise continue save as process"
If System.IO.File.Exists(oNewFullFileName) Then
Exit Sub
End If

oDataMedium.FileName = oNewFullFileName
'<<<< CHANGE THIS IF NEEDED, INI FILE CONFIGURATION LOCATION >>>>'
Dim oINI_File As String = "C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\exportdxf.ini"
If Not System.IO.File.Exists(oINI_File) Then
MsgBox("Couldn't find this INI file: " & oINI_File & ". Exiting.", vbExclamation, "")
Exit Sub
End If

'Set save as options'
If oDXF.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = oINI_File
End If
Try
		oDXF.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
	Catch oEx As Exception
		MsgBox("SaveCopyAs method of the ExportIDWtoDXF Sub routine failed." & vbCrLf & _
		"While trying to export the following Drawing file:  " & vbCrLf & _
		oDrawing.FullFileName & vbCrLf & _
		"as the following dxf file:  " & vbCrLf & _
		oNewFileName & vbCrLf & _
		oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "")
		'Logger.Error(oEx.Message & vbCrLf & oEx.StackTrace)
		oDrawing.ReleaseReference
	End Try
End Sub

'Start IDW to PDF'
Sub ExportIDWtoPDF(oDrawing As DrawingDocument, oNewFullFileName As String)
	'get the PDF Translator Add-in
	Dim oPDFAddin As TranslatorAddIn
	For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAddin.DisplayName = "Translator: PDF" Then
			oPDFAddin = oAddin
		End If
	Next

	'Create the variables needed by the Translator Add-in
	oTO = ThisApplication.TransientObjects
	oContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = oTO.CreateNameValueMap
	oDataMedium = oTO.CreateDataMedium
	oDataMedium.FileName = oNewFullFileName

'Exit sub if file extension exists otherwise continue save as process"
	If System.IO.File.Exists(oNewFullFileName) = True Then
	Exit Sub
	End If
	
	oDataMedium.FileName = oNewFullFileName
	
	'The following If-Then statement defines the Options available, and their Values.
If oPDFAddin.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
		oOptions.Value("Publish_All_Sheets") = 1 ' 0 = False, 1 = True
		'oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintAllSheets
		'oOptions.Value("Custom_Begin_Sheet") = 1
		'oOptions.Value("Custom_End_Sheet") = 4
		oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
		oOptions.Value("Vector_Resolution") = 720 '150, 200, 400, 600, 720, 1200, 2400, 4800 ' DPI
		oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
		oOptions.Value("Launch_Viewer") = 1 ' 0 = False, 1 = True
	End If
	
	'Publish PDF
	oPDFAddin.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
End Sub

 

0 Likes
Message 33 of 48

dschulteHR4D5
Advocate
Advocate
Hey there, hate to bug again, but ive spent probably 4 hours or more trying to figure out how to do this and i just cant seem to get it quite right... Ive come close but always end up with an error. But im trying to use the parts that its finding, and if the part it finds has the material set to PURCHASED to skip the part. Similar to if it finds a part that doesn't have a referenced drawing, a messagebox shows the name, then it moves onto the next part. I'm trying to do that with the materials, if its PURCHASED it skips that part and goes to the next, thanks for any help
0 Likes
Message 34 of 48

dschulteHR4D5
Advocate
Advocate
Okay so i am getting closer to what i am trying to get.. i have some more testing to do, but so far from the couple trials i ran on sample assemblies, it seems to be working, i added this in the sub,
If oComp.Definition.Document.PropertySets.Item

Sub IterateComponentsRecursively(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps



'Only process Visible components'
If oComp.Visible = False Then Continue For

If oComp.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").value = "PURCHASED" Then Exit Sub

'If component is Visible, and an Assembly, recursively process its components'
If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
IterateComponentsRecursively(oComp.Definition.Occurrences)
End If
0 Likes
Message 35 of 48

WCrihfield
Mentor
Mentor

Hi @dschulteHR4D5.  I don't recall if I mentioned this before or not, but there is actually a Property of every model type document's ComponentDefinition called BOMStructure, which has a value from the BOMStructureEnum, that is just for specifying whether it is Purchased (or other similar status).  You could be using that property for that purpose, instead of setting the 'Material' of the model document to 'Purchased', then having to dig its value out of the iProperties.  It is also usable on assemblies, where Material is not used.  Just an idea or food for thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 36 of 48

dschulteHR4D5
Advocate
Advocate
That is good to know, ill have to look into that at some point, part of what i am running into with the codes is just that, knowing what is available and what isnt, took me hours of scrolling through forums just to find

oComp.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").value

and managed to make it work, at least it seems to work for now, then it took awhile to work it into the code to make it work with everything else, still not sure if its proper or not, as far as placement, do you happen to know the code for that by chance? if theres a better way to manage it i would prefer to do it that way for sure.
0 Likes
Message 37 of 48

WCrihfield
Mentor
Mentor

Hi @dschulteHR4D5.  The line of code you have there is a fairly common way of accessing the iProperties of an assembly component, and it is using the Inventor API route which is usually more stable, instead of the iLogic shortcut route.  Even if using material name to designate and check if a component is Purchased or not may seem a bit odd to me, what is more important is whatever works for you.  If you were to use the BOMStructure route, an equivalent line of code for checking its status would look something like this:

If oComp.Definition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then Continue For

That line of code checks if the component is Purchased, and if so it will skip to the next component in your loop of components (instead of exiting the whole Sub routine or rule).  You can set its value manually when the model document is open/active by going to the Tools tab > Options panel > Document Settings > Bill Of Materials tab > then change the 'Default BOM Structure' setting.  Or it can be set by code similarly to how we are checking it above:

ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure

...or of course, you can set its value however you want.

And the assembly BOM can work with the BOMStructure to help control quantities.  For instance, if you set the BOMStructure to 'kReferenceBOMStructure', it will not count towards the 'net' count within the BOM.  Similar to when you have it suppressed in a LevelOfDetailRepresentation or ModelState.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 38 of 48

dschulteHR4D5
Advocate
Advocate
Okay i see what youre doing with that, youre using the BOM structure, i didnt think of that, i am using my own material library, and using PURCHASED as a material, to specify an item we buy for a build, cylinder, bolts, etc etc. I am using the BOM but not the different structures, havent quite ventured into that yet but plan on getting there some time soon
0 Likes
Message 39 of 48

dschulteHR4D5
Advocate
Advocate
Hey there, so i have been trying to do what you mentioned previously, add the names of all the components with missing prints into a list. i have been doing some research and trying to get it to work, i have got it to make a list on notepad, and got it to do some things, but i cannot for the life of me get it to work properly, i had it set in the function getdrawing, and when doing this, it works but it makes a text document for every one that it finds, whereas i want to get them onto one list. I cant figure out how to get it to do this... part of it i think is the way the code is laid out, where i have it it makes sense to do one per, because where it is in the function. If you had a moment, i think i just need to know where to put the stuff to get it properly, as i said it is doing one for each, now i am trying to use an array list, but i cant seem to get it to work right. i tried setting it in different parts of the code, in the main, out of the main, in the getdrawing function.
i was able to get the names in an inputlistbox, using a test assembly, i was able to pull the names i needed in this list, but using this list isn't something i would like permanent, a text with a list would be best i think, the input list i cant minimize and go back to, has to close before i can do anything else in inventor, would like a list i can go back n forth to as needed to make the missing prints. but for some reason i cant get the names in the array list of the inputlistbox to work the same in a text document. im thinking array list is for the input list box? Basically as of now this is the code i am using, working great, would just like to get the missing prints onto a text list.



Sub Main
'Make sure ASM document is active'
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If

Dim oADoc As AssemblyDocument = ThisDoc.Document

'Create folders in project workspace folder if not already there'
Dim oWSPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oSTEPFilesFolder = oWSPath & "\STEP FILES"
If Not System.IO.Directory.Exists(oSTEPFilesFolder) Then
System.IO.Directory.CreateDirectory(oSTEPFilesFolder)
End If
oDXFFilesFolder = oWSPath & "\DXF FILES"
If Not System.IO.Directory.Exists(oDXFFilesFolder) Then
System.IO.Directory.CreateDirectory(oDXFFilesFolder)
End If
oPDFFilesFolder = oWSPath & "\PDF FILES"
If Not System.IO.Directory.Exists(oPDFFilesFolder) Then
System.IO.Directory.CreateDirectory(oPDFFilesFolder)
End If

'Loop through components and define the save as criteria'
oOccs = oADoc.ComponentDefinition.Occurrences
IterateComponentsRecursively(oOccs)


'After completion show exports complete'
MsgBox("All Exports Complete.", vbInformation, "")

'Close any referenced documents'
ThisApplication.Documents.CloseAll(True)

'Open workspace folder'
ThisDoc.Launch(ThisDoc.WorkspacePath)


'present the user with the list to choose from
myComponent = InputListBox("Select one.", myArrayList, myArrayList.Item(0), "iLogic", "List")

End Sub

Dim oSTEPFilesFolder As String
Dim oDXFFilesFolder As String
Dim oPDFFilesFolder As String
Dim oProcessedDocs As List(Of PartDocument)
Dim myArrayList As New ArrayList

Sub IterateComponentsRecursively(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps

'Only process Visible components'
If oComp.Visible = False Then Continue For

'If component is Visible, and an Assembly, recursively process its components'
If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
IterateComponentsRecursively(oComp.Definition.Occurrences)
End If

'Make sure it is a Part'
If oComp.DefinitionDocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
If Not TypeOf oComp.Definition Is PartComponentDefinition Then Continue For
Dim oPDoc As PartDocument = oComp.ReferencedDocumentDescriptor.ReferencedDocument
If IsNothing(oProcessedDocs) Then oProcessedDocs = New List(Of PartDocument)

'If we have already processed this referenced document, skip to next component'
If oProcessedDocs.Contains(oPDoc) Then Continue For
Dim oFileName As String = System.IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)
Dim oSTEPFullFileName As String = oSTEPFilesFolder & "\" & oFileName & ".stp"

'Find component referenced drawing file'
Dim oDrawDoc As DrawingDocument = GetDrawing(oPDoc)
If Not IsNothing(oDrawDoc) Then

'Start sub routines to loop through save copy of component as STP and referenced IDW to DXF and PDF'
ExportToSTEP(oPDoc, oSTEPFullFileName)
Dim oDXFFullFileName As String = oDXFFilesFolder & "\" & oFileName & ".dxf"
ExportIDWtoDXF(oDrawDoc, oDXFFullFileName)
Dim oPDFFullFileName As String = oPDFFilesFolder & "\" & oFileName & ".pdf"
ExportIDWtoPDF(oDrawDoc, oPDFFullFileName)
End If
Next
End Sub

'Export to STP sub'
Sub ExportToSTEP(oDoc As Document, oNewFileName As String)
Dim oSTEP As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
"{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
If IsNothing(oSTEP) Then
MsgBox("STEP Translator Add-in not found. Exiting.", vbCritical, "")
'Logger.Debug("STEP Translator Add-in not found.")
Exit Sub
End If

'Create needed variables for translator'
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium

'Exit sub if file extension exists otherwise continue save as process"
If System.IO.File.Exists(oNewFileName) Then
Exit Sub
End If

oDataMedium.FileName = oNewFileName
If oSTEP.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
'oOptions.Value("ApplicationProtocolType") = 3
'oOptions.Value("IncludeSketches") = True
'oOptions.Value("export_fit_tolerance") = .000393701 'minimum
'oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = iProperties.Value("Summary", "Title")
'oOptions.Value("Organization") = iProperties.Value("Summary", "Company")
Try
oSTEP.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
Catch
MsgBox("Your attempt to export this document as a STEP file FAILED!", vbExclamation, "Export to STEP Error")
'Logger.Error("Export to STEP failed.")
End Try
End If
End Sub

'Find referenced IDW and continue save as process'
Function GetDrawing(oModelDoc As Document) As DrawingDocument
oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim oDrawingsFolder As String = oWSPath & "\DRAWINGS"
oFileName = System.IO.Path.GetFileNameWithoutExtension(oModelDoc.FullFileName)
Dim oDrawingFile As String = oDrawingsFolder & "\" & oFileName & ".idw"
'Reference IDW but don't open'
If System.IO.File.Exists(oDrawingFile) Then
Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(oDrawingFile, False)
Return oDrawingDoc
Else

myArrayList.Add(oFileName)


End If
Return Nothing
End Function


'Start IDW to DXF'
Sub ExportIDWtoDXF(oDrawing As DrawingDocument, oNewFullFileName As String)
Dim oDXF As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
If IsNothing(oDXF) Then
MsgBox("DXF Translator Add-in not found. Exiting.", vbCritical, "")
'Logger.Debug("DXF Translator Add-in not found.")
Exit Sub
End If

'Create needed variables for translator'
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium

'Exit sub if file extension exists otherwise continue save as process"
If System.IO.File.Exists(oNewFullFileName) Then
Exit Sub
End If

oDataMedium.FileName = oNewFullFileName
'<<<< CHANGE THIS IF NEEDED, INI FILE CONFIGURATION LOCATION >>>>'
Dim oINI_File As String = "C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\exportdxf.ini"
If Not System.IO.File.Exists(oINI_File) Then
MsgBox("Couldn't find this INI file: " & oINI_File & ". Exiting.", vbExclamation, "")
Exit Sub
End If

'Set save as options'
If oDXF.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = oINI_File
End If
Try
oDXF.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
Catch oEx As Exception
MsgBox("SaveCopyAs method of the ExportIDWtoDXF Sub routine failed." & vbCrLf & _
"While trying to export the following Drawing file: " & vbCrLf & _
oDrawing.FullFileName & vbCrLf & _
"as the following dxf file: " & vbCrLf & _
oNewFileName & vbCrLf & _
oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "")
'Logger.Error(oEx.Message & vbCrLf & oEx.StackTrace)
oDrawing.ReleaseReference
End Try
End Sub

'Start IDW to PDF'
Sub ExportIDWtoPDF(oDrawing As DrawingDocument, oNewFullFileName As String)
'get the PDF Translator Add-in
Dim oPDFAddin As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
If oAddin.DisplayName = "Translator: PDF" Then
oPDFAddin = oAddin
End If
Next

'Create the variables needed by the Translator Add-in
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium
oDataMedium.FileName = oNewFullFileName

'Exit sub if file extension exists otherwise continue save as process"
If System.IO.File.Exists(oNewFullFileName) = True Then
Exit Sub
End If

oDataMedium.FileName = oNewFullFileName

'The following If-Then statement defines the Options available, and their Values.
If oPDFAddin.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
oOptions.Value("Publish_All_Sheets") = 1 ' 0 = False, 1 = True
'oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 4
oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
oOptions.Value("Vector_Resolution") = 720 '150, 200, 400, 600, 720, 1200, 2400, 4800 ' DPI
oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
oOptions.Value("Launch_Viewer") = 1 ' 0 = False, 1 = True
End If

'Publish PDF
oPDFAddin.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
End Sub
0 Likes
Message 40 of 48

WCrihfield
Mentor
Mentor

Hi @dschulteHR4D5.  When I just reviewed the code you posted, I saw a few things that may need to be addressed.

I see within your code where you create the variable 'oProcessedDocs' between the Subs, which makes it available to all other Subs/Functions, and I see where it is being used in 2 places within the 'IterateComponentsRecursively' Sub.  It is checking to make sure it has been given an initial value (a New List(Of PartDocument)).  And I see where it is checking if the current referenced document is already within the list.  But I do not see anywhere within your code where it is actually adding any referenced documents into that List.  This may be causing problems, or causing some documents to be processed multiple times, because it is 'never' already in the list.  I would suggest adding the referenced part document to the list just after you have attempted to run all your routines on it.

 

There is nothing wrong with using an ArrayList here, but I would recommend using a List(Of String) instead, because it too is simple, but is more specific to the type of objects we are putting into it, and therefore slightly helps us later due to not having to identify what Type of objects are in the collection when we iterate through it and use the items within.  The List object works about the same as the ArrayList in other ways though.  I see that you are likely collecting the needed data into the existing ArrayList now, but do not have any further code to output the data contained within it to a text file yet.  There is actually a 'snippet' of iLogic/vb.net code on the 'System' side of the iLogic 'snippets', under the 'My Snippets' folder, called "Text File Create" (and a couple other similar ones).  The code I'm posting below is an example using some of those same tools to help write a list of String data out to a new text file.  This should give you the idea you need for how to take that next step in your code, and write the contents of those part file names you collected in your list and output them to a text file, as you were wanting.

Sub Main
	Dim oNames As New List(Of String)
	oNames.Add("Part3")
	oNames.Add("Part7")
	oNames.Add("Part9")
	WriteListOfStringsToTextFile(oNames)
End Sub

Sub WriteListOfStringsToTextFile(oStrings As List(Of String))
	'write List contents (Strings) to a Text file
	Dim oTxtFile As String = "C:\Temp\List of String to Text File.txt"
	Dim oWriter As System.IO.StreamWriter = System.IO.File.CreateText(oTxtFile)
	For Each oString In oStrings
		oWriter.WriteLine(oString)
	Next
	oWriter.Close
	ThisDoc.Launch(oTxtFile)
End Sub

I hope this helps.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes