Create parts from excel data

Create parts from excel data

Anonymous
Not applicable
1,310 Views
4 Replies
Message 1 of 5

Create parts from excel data

Anonymous
Not applicable

Hello!

 

Is it possible to create part files with dat from an excel sheet?

 

I have a part file to use as template and an excel sheet containing different lengths of this part.

 

So I want to connect these (with iLogic?) to automate a batch creation of new part files according to the lengths in the excel sheet. Preferably with the original file name + the new length as the new file name.

 

Thanks,

/J

0 Likes
1,311 Views
4 Replies
Replies (4)
Message 2 of 5

HermJan.Otterman
Advisor
Advisor

In Inventor these part are called iParts....

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2016...

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 5

Anonymous
Not applicable

I´m not sure that iParts is what I am after, have had a look at this, but not got it to work as I want.

I am looking for the following:

 

I have an excel document already created.

This document has two important columns: one for the filename, one for the lenght

What I want to do now is to create a macro or similar function to:

Take an inventor file already created as a "template"

Get the length value in the first row

Put this value as the length dimension in parameters

Save the file as a STEP-file with the filename from the first row

Get the length value in the second row

Put this value as the length dimension in parameters

Save the file as a STEP-file with the filename from the second row

 

...and so on until it meets an empty row and then the macro or similar function finishes.

0 Likes
Message 4 of 5

philip1009
Advisor
Advisor

iLogic has a bunch of snippets for interacting with Excel files, and there's more in the Inventor API that you can look for:

Excel code_edited.jpg

0 Likes
Message 5 of 5

lmc.engineering
Advocate
Advocate

Hi @Anonymous

 

If you save your excel document as a CSV file, this rule will do what you need.

 

You can add further columns to each data row in the 'oAssignValues' Sub routine.

 

Version:1.0 StartHTML:00000145 EndHTML:00010451 StartFragment:00000294 EndFragment:00010419 StartSelection:00000294 EndSelection:00000294SyntaxEditor Code Snippet

Sub Main()
oReadCSV()
End Sub

Sub oReadCSV()
	'''This section reads the CSV file and stores the data as a new arraylist for assembly creation
Dim FileSource As String = "File path of where the CSV is stored"
Dim CSVFile As String = "Your CSV File name.csv"
Dim ReadCSV As New System.IO.StreamReader(FileSource & "\" & CSVFile)
Dim i As Integer = 0
Dim oFieldSets As New ArrayList()
	'''continues to read until it finds a blank line
	Do While ReadCSV.Peek <> -1
		oFieldSets.Add(ReadCSV.ReadLine.Split(","))
		i+=1
	Loop
CreateParts(i, oFieldSets)
End Sub

Sub CreateParts(i As Integer, oFieldSets As ArrayList)
	Dim x As Integer = 0
	'Define the amount of parts to produce(x)
	Do Until x = i
		''' Send the fields from the csv file to be exported to the corresponding parameters
		oAssignValues(x, oFieldSets)
			'''Force update each parameter
			RuleParametersOutput()
			InventorVb.DocumentUpdate()
		''' Now export each line as STEP File
		exportAsStep()
	x+=1
	Loop
End Sub

Sub oAssignValues(x As Integer, oFieldSets As ArrayList)
pLength = oFieldSets.Item(x) (0) '''THIS IS YOUR LENGTH PARAMETER
pFileName = oFieldSets.Item(x) (1) '''MAKE 'pFileName' A TEXT USER PARAMETER
'SomethingElse1 = oFieldSets.Item(x) (2)
'SomethingElse2 = oFieldSets.Item(x) (3)
'SomethingElse3 = oFieldSets.Item(x) (4)
'SomethingElse4 = oFieldSets.Item(x) (5)
End Sub

Sub exportAsStep()
StepfilePath = ThisDoc.Path
StepFolder = "STEP FILES"
StepFileName = pFileName & "_" & pLength & ".stp"
ExportFile = StepfilePath & "\" & StepFolder & "\" & StepFileName
 
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
	    oOptions.Value("ApplicationProtocolType") = 3
	    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	    Dim oData As DataMedium
	    oData = ThisApplication.TransientObjects.CreateDataMedium	    
	    ' Set export name of STEP file
	    oData.FileName = ExportFile
	oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
	End If
End Sub

 

0 Likes