Excel to build article database and check if article exists

Excel to build article database and check if article exists

Koekepeerke
Advocate Advocate
334 Views
3 Replies
Message 1 of 4

Excel to build article database and check if article exists

Koekepeerke
Advocate
Advocate

Hello everyone,

 

I'm making an automation wich generates and positions configurations of a parametric model in an assembly.

I'm want to try and use an excel file to store all made configurations and have the program check if a configuration already exists. if the configuration exists it has to replace it with the existing one. 

At the moment i'm trying to do it with a for next loop but honestly i have no idea if this is the right approach.

 

Does anyone have an idea how i would go about doing this? Maybe excel is not the best way to do this? 

I'm not looking for someone to fix my code but a little push in the right direction would be a great help.

I want to try and avoid using iParts and the content center for now.

 

Dim count2 As Double

For count2 = oRowStart To oRowEnd
	
		If GoExcel.CellValue(ExcelFile, "Blad1", "B" & count2) = Parameter(bouwgoot.Name, "goot_soort") And GoExcel.CellValue(ExcelFile, "Blad1", "C" & count2) = Parameter(bouwgoot.Name, "goot_type") And GoExcel.CellValue(ExcelFile, "Blad1", "D" & count2) = Parameter(bouwgoot.Name, "goot_lengte") Then
			
			bouwreplace = GoExcel.CellValue("A" & count2) & ".iam"
			
			Component.Replace(bouwgoot.Name, bouwreplace, False)
			
			ThisApplication.FileManager.DeleteFile(bouwgootKopie)
			
			
		ElseIf GoExcel.CellValue(ExcelFile, "Blad1", "B" & count2) IsNot Parameter(bouwgoot.Name, "goot_soort") Or GoExcel.CellValue(ExcelFile, "Blad1", "C" & count2) IsNot Parameter(bouwgoot.Name, "goot_type") Or GoExcel.CellValue(ExcelFile, "Blad1", "D" & count2) IsNot Parameter(bouwgoot.Name, "goot_lengte") Then
			
			GoExcel.CellValue(ExcelFile, "Blad1", "A" & oEmptyRow) = System.IO.Path.GetFileNameWithoutExtension(bouwgootKopie)
			GoExcel.CellValue(ExcelFile, "Blad1", "B" & oEmptyRow) = Parameter(bouwgoot.Name, "goot_soort")
			GoExcel.CellValue(ExcelFile, "Blad1", "C" & oEmptyRow) = Parameter(bouwgoot.Name, "goot_type")
			GoExcel.CellValue(ExcelFile, "Blad1", "D" & oEmptyRow) = Parameter(bouwgoot.Name, "goot_lengte")
			
			GoExcel.Save
			
			Exit For
			
		End If
Next

 

JeKl_0-1656416206812.png

 

Note: i dont get any error messages but the program just writes new values in excel.

Sometimes the component will get replaced but not when all 3 parameters actually exist.

 

Regards,

Jeremy

0 Likes
Accepted solutions (1)
335 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator
Accepted solution

I would use the GoExcel.FindRows. It can search multiple columns and if it returns '-1' the row doesnt exist and you can create a new one.

i = GoExcel.FindRow("3rd Party:Embedding 1", "Sheet1", "goot soort", "=", Parameter(bouwgoot.Name, "goot_soort"), "goot type", "=", Parameter(bouwgoot.Name, "goot_type"))

 

Message 3 of 4

Koekepeerke
Advocate
Advocate
That looks very promising! i will try it out as soon as i can and i will let you know if i got it to work properly.
Thanks for the reply!
0 Likes
Message 4 of 4

Koekepeerke
Advocate
Advocate

Thanks a lot it works like a charm so far!

0 Likes