Ilogic Excel Next Available Line

Ilogic Excel Next Available Line

Chirpyboy2060647
Advocate Advocate
2,184 Views
6 Replies
Message 1 of 7

Ilogic Excel Next Available Line

Chirpyboy2060647
Advocate
Advocate

Hey all, So the task is on me now to deal with our engineering stamp request log. And I've got the code to pull what information i want...thats taken care of. My question now is, is there a code that will fill the next available line. So if A1-D1 is filled it will pull my properties to the next open line A2-D2? Without me having to manually change this every time.

 

Thanks!

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

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Chirpyboy2060647,

 

 

I'm pretty sure I've seen an example that only looks at the rows in use and finds the last used, but this is what I had on hand. It looks at the first 2000 rows and finds the last used.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'open the spreadsheet
GoExcel.Open("MyExcelFile.xls"), "Sheet1")

'Define Range
oRowStart = 2
oRowEnd = 2000
Dim count As Double
For count = oRowStart To oRowEnd
	' If it's blank count it
	If String.IsNullOrEmpty(GoExcel.CellValue("A" & count)) Then 
		i = i + 1
	End If
Next
' Next empty row is max rows minus blank rows plus one
oEmptyRow = oRowEnd - i + 1	

EESignature

Message 3 of 7

Chirpyboy2060647
Advocate
Advocate

Oh nice, ill mess around with this and see how it works for me.

 

 

'open the spreadsheet
ExcelFile =  "Test PO" & ".xlsx"

 

GoExcel.CellValue(ExcelFile, "Sheet1", "K2")  = iProperties.Value("Custom", "FI_005") 'Drawing Number
GoExcel.CellValue(ExcelFile, "Sheet1", "K1")  = iProperties.Value("Custom", "FI_007") 'Proj Name

  Actually heere is a sample of what im using to pull to a template excel. If you could guide me on how i would modify this ( i can change the rest of what im pulling or need to) to go inline with your code?

0 Likes
Message 4 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Chirpyboy2060647,

 

So once the Empty Row is found (per the earlier example), you can use something like this to fill in each cell for that row, with the given iProperty.

 

Note that there is no need to call out the Excel file and Sheet again once it's been established in the code (Autodesk doesn't really do a great job of telling us that in the ilogic documenation or snippets).

 

 

GoExcel.CellValue("B" & oEmptyRow) = iProperties.Value("Project", "Part Number") 
GoExcel.CellValue("C" & oEmptyRow) = iProperties.Value("Project", "Revision Number")
GoExcel.CellValue("D" & oEmptyRow) = iProperties.Value("Status", "Engr Date Approved") 

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 5 of 7

MechMachineMan
Advisor
Advisor

Call me different, but I like to avoid the iLogics whenever possible. Instead, the easiest way I have found is something LIKE:

 

xlapp = GoExcel.Application
oLastRow = xlapp.ActiveWorkbook.Activesheet.UsedRange.Rows.Count

Which is actually kind of a mesh between the two; avoids the marshal call to get the excel app, but still uses the native excel API to perform the functions that you want, which makes more sense to me.

 

Then you can also access rows based off of numbers instead of having to have something solid/extra functions for alphanumeric;

 

Ie;

 

ActiveWorkBook.ActiveSheet.Cells(1,1).Value = "Text"

 

where (1,1) is (rowNumber, columnNumber)

 


--------------------------------------
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
Message 6 of 7

Chirpyboy2060647
Advocate
Advocate

Hi Curis,

 

Sorry for the late response of if this works or not, got really busy at work so i couldnt mess with this code for a bit. When i go to run the code i get the error

Error in rule: Next Line, in document: ORD-19948-A.dwg

Unable to cast object of type 'System.String' to type 'System.Object[,]'.

 

Here is my code right now 

 

'open the spreadsheet
GoExcel.Open("\\0-File Transfer\Brian\Line.xlsx", "Sheet1")

oRowStart = 2
oRowEnd = 2000
Dim count As Double
For count = oRowStart To oRowEnd
    ' If it's blank count it
    If String.IsNullOrEmpty(GoExcel.CellValue("A" & count)) Then 
        i = i + 1
    End If
Next
' Next empty row is max rows minus blank rows plus one
oEmptyRow = oRowEnd - i + 1

GoExcel.CellValue("B" & oEmptyRow) =  iProperties.Value("Custom", "FI_005")
'GoExcel.CellValue(ExcelFile, "Sheet1", "K2")  = iProperties.Value("Custom", "FI_005") 

 

Message 7 of 7

Chirpyboy2060647
Advocate
Advocate
This actually worked just fine, but ILogic doesn't like when you copy and paste and gives weird spacing. But works perfectly Thank you
0 Likes