iLogic - Get file names from directory, and post them all to Excel problem

iLogic - Get file names from directory, and post them all to Excel problem

mhoE3YPJ
Participant Participant
1,646 Views
6 Replies
Message 1 of 7

iLogic - Get file names from directory, and post them all to Excel problem

mhoE3YPJ
Participant
Participant

Good day,

 

I've been working a long time on a work around for some heavy manual drawing labor.

The last thing I really need from iLogic, is to post all filenames from a specified directory,

to excel cells.

 

Right now I can make my code post the first name in the directory, and change to the next empty row,

but I cant get it to post all names.

 

Dim di As New IO.DirectoryInfo("P:\KUNDER\" & pathMappe & "\" & sOrdreNr & "\")
Dim diar1 As IO.FileInfo() = di.GetFiles("*.dxf")
Dim files As List(Of String) = New List(Of String)

Worksheet = ("C:\Users\mho\Desktop\test123.xlsx")
Sheetno = ("Ark1")

GoExcel.Open(Worksheet, Sheetno)
RowStart = 2
RowEnd = 100
For count = RowStart To RowEnd
	If String.IsNullOrEmpty(GoExcel.CellValue("A" & count)) Then 
		i = i + 1
	End If
Next
row = RowEnd - i + 1

For Each fi As IO.FileInfo In diar1  
GoExcel.CellValue("A" & row) = fi.Name
Next
GoExcel.Save

This is my code. I use my Userparameters from my asm file, to find my directory, and I want to specify I only need .dxf files to be posted to excel.

 

I will use this with Lantek Expert, to run a processes which takes the files, and nest them for our fiber laser cutter, hence why all the file names specified is a must.

 

Any help would be greatly appriciated!

0 Likes
Accepted solutions (2)
1,647 Views
6 Replies
Replies (6)
Message 2 of 7

TomaszDąbrowski
Enthusiast
Enthusiast
Accepted solution

In my opinion you need two changes.

You should close excel file at the end of rule.

You should increase "row" variable after each managed file.

Dim di As New IO.DirectoryInfo("P:\KUNDER\" & pathMappe & "\" & sOrdreNr & "\")
Dim diar1 As IO.FileInfo() = di.GetFiles("*.dxf")
Dim files As List(Of String) = New List(Of String)

Worksheet = ("C:\Users\mho\Desktop\test123.xlsx")
Sheetno = ("Ark1")

GoExcel.Open(Worksheet, Sheetno)
RowStart = 2
RowEnd = 100
For count = RowStart To RowEnd
	If String.IsNullOrEmpty(GoExcel.CellValue("A" & count)) Then 
		i = i + 1
	End If
Next
row = RowEnd - i + 1

For Each fi As IO.FileInfo In diar1  
GoExcel.CellValue("A" & row) = fi.Name
row=row+1
Next
GoExcel.Save
GoExcel.Close
0 Likes
Message 3 of 7

Michael.Navara
Advisor
Advisor
Accepted solution

You don't increment the "row" variable in this loop. Writes only the last file to the Excel.

        For Each fi As IO.FileInfo In diar1  
            GoExcel.CellValue("A" & row) = fi.Name
        Next

 Solves this your issue?

For Each fi As IO.FileInfo In diar1  
   GoExcel.CellValue("A" & row) = fi.Name
   row = row + 1
Next

 

0 Likes
Message 4 of 7

mhoE3YPJ
Participant
Participant

Thanks for the help guys! It works perfectly now!
One step closer to full automatisation!

 

Thanks @Michael.Navara and @TomaszDąbrowski 

Have a great day you two!

0 Likes
Message 5 of 7

王承之pmhker
Advisor
Advisor

is this full code ? i creat a excel file and rename the sheet to “Ark1“,then i run the rule but nothing is happen

 


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

0 Likes
Message 6 of 7

mhoE3YPJ
Participant
Participant

This code will need some adjustment for it to work with your assembly files.

 

Dim di As New IO.DirectoryInfo("P:\KUNDER\" & pathMappe & "\" & sOrdreNr & "\")
Dim diar1 As IO.FileInfo() = di.GetFiles("*.dxf")
Dim files As List(Of String) = New List(Of String)

Dim aColumn As String = "A"
Dim cColumn As String = "C"
Dim Row As Integer = 2

Worksheet = ("C:\Users\mho\Desktop\test123.xlsx")
Sheetno = ("Ark1")

GoExcel.Open(Worksheet, Sheetno)

While Row < 99
GoExcel.CellValue(aColumn & Row) = "" 'Value
GoExcel.CellValue(cColumn & Row) = "" 'Value
Row = Row+1
End While

RowStart = 2
RowEnd = 100
For count = RowStart To RowEnd
	If String.IsNullOrEmpty(GoExcel.CellValue("A" & count)) Then 
		i = i + 1
	End If
Next
row = RowEnd - i + 1

For Each fi As IO.FileInfo In diar1  
GoExcel.CellValue("A" & row) = fi.Name
GoExcel.CellValue("C" & row) = fi.DirectoryName + "\" + fi.Name
row=row+1
Next
GoExcel.Save
GoExcel.Close

 

The text marked in read, need to match your userparameters and excel name.

I'm using my userparameters to find my folder for my dxf files:

Dim di As New IO.DirectoryInfo("P:\KUNDER\" & pathMappe & "\" & sOrdreNr & "\")

"P:\KUNDER\" is our server destination for customers, "pathMappe" is a list of folders I can change, and sOrdreNr is the Order folder. I always save my files with the order number. 

 

If you have a specific directory you want to use everytime for this rule, you should do this instead:

Dim di As New IO.DirectoryInfo("C:\Users\mho\Documents\Inventor\UserParameterTest\")

Hope it helps, I can maybe help troubleshoot some more if you post your path of DXF files, and your iLogic rule.

Message 7 of 7

王承之pmhker
Advisor
Advisor

thanks,it's working,thankyou


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

0 Likes