Extracting cell Data from Excel

Extracting cell Data from Excel

Nigel.Sims
Advocate Advocate
1,391 Views
4 Replies
Message 1 of 5

Extracting cell Data from Excel

Nigel.Sims
Advocate
Advocate

Hi all,

I have been trying to add an iLogic rule to populate a custom iProperty using an external excel spreadsheet. I have got it working once, but if i save the assembly as something else the custom iProperty doesn't update. Ilogic compares the Project iProperty and then  finds this value in the excel file and returns another value in the corresponding column. I have attached the code below.

 

SyntaxEditor Code Snippet

'Populate iProperties from filename
iProperties.Value("Summary", "Title") = (Mid(ThisDoc.FileName(False),11, 100))
iProperties.Value("Project", "Project") = (Left(ThisDoc.FileName(False), 4))
iProperties.Value("Custom", "SYSTEM") = (Mid(ThisDoc.FileName(False), 6,4))

'Project number variable
ProjectNo = iProperties.Value("Project", "Project")

'Spreadsheet rows start on the 3rd row
GoExcel.TitleRow = 3
'compare the project number variable against work order number column in spreadsheet.
i = GoExcel.FindRow("C:\Vault Work\Design Projects\Title Block Info.xlsx", "Sheet1", "Work Order Number", "=", "ProjectNo")
iProperties.Value("Custom", "Client") = GoExcel.CurrentRowValue("Client")

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

 Many thanks

Nigel

0 Likes
Accepted solutions (1)
1,392 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

I removed the quotation marks from around ProjectNo as it's used in the FindRow line so that it uses the value, and not the 'dumb' string "ProjectNo"

 

'Populate iProperties from filename
iProperties.Value("Summary", "Title") = (Mid(ThisDoc.FileName(False),11, 100))
iProperties.Value("Project", "Project") = (Left(ThisDoc.FileName(False), 4))
iProperties.Value("Custom", "SYSTEM") = (Mid(ThisDoc.FileName(False), 6,4))

'Project number variable
ProjectNo = iProperties.Value("Project", "Project")

'Spreadsheet rows start on the 3rd row
GoExcel.TitleRow = 3
'compare the project number variable against work order number column in spreadsheet.
i = GoExcel.FindRow("C:\Vault Work\Design Projects\Title Block Info.xlsx", "Sheet1", "Work Order Number", "=", ProjectNo)
iProperties.Value("Custom", "Client") = GoExcel.CurrentRowValue("Client")

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

 


--------------------------------------
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
0 Likes
Message 3 of 5

Nigel.Sims
Advocate
Advocate

@MechMachineMan That works brilliantly, thank you. 

0 Likes
Message 4 of 5

Nigel.Sims
Advocate
Advocate

Although the code works great when the I run the rule manually, getting the rule to trigger when the document is saved is another issue. On the first save of the document I can get the rule to work and populate the iProperties fine, but if I save as another document with a different name the rule doesn't run. I then have to run the rule manually to get it to work. 

Any ideas are highly appreciated.

 

Nigel

0 Likes
Message 5 of 5

MechMachineMan
Advisor
Advisor

A simple test to do is to put a rule in that reads the file name and apply that on save - much like your rule - to see when the rule actually runs.

 

After doing that, it's apparent that the SaveAs will not actually trigger the rule on the newly saved document (regardless of whether you use the beforesave or aftersave triggers). I'm assuming this is because it saves the document first (without running the rule) then opens it second to make it visible, so it's never actually saved within the context of the iLogic rule.

 

I can't think of any workarounds that don't involve more advanced programming, but the fact that it will run when you save it anyways doesn't make it seem like it's that big of an issue.

 

Perhaps @chandra.shekar.g can comment on whether this is intended behavior or not.


--------------------------------------
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
0 Likes