iLogic code to read a specific excel sheet in a workbook

iLogic code to read a specific excel sheet in a workbook

Anonymous
Not applicable
2,635 Views
7 Replies
Message 1 of 8

iLogic code to read a specific excel sheet in a workbook

Anonymous
Not applicable

Hello, 

 

Currently I am having trouble trying to find a way for inventor to read the coordinates (x-y) from a specific excel sheet. When I use the sketch --> insert--> points. It only pulls it from the 1st sheet of the excel.. I need it to import a different sheet. So I was wondering there is any code for VBA or ilogic to read the points from excel in different sheets in excel

0 Likes
2,636 Views
7 Replies
Replies (7)
Message 2 of 8

mcgyvr
Consultant
Consultant

The most basic is this..

If you provide more details better information can be given..

GoExcel.CellValue("filename.xls", "Sheet1", "A2")

 

and a link to the excel data functions reference for ilogic..

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

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 8

Anonymous
Not applicable

Yes I tried doing that but since inside the sketch there isnt any parameters called out.. So Inventor doesn't know what to look for in Excel to import in those points. I just need a pathway or a code to get inventor to pull in excel and picking which sheet inside of excel to use those points and the points varies depending on the requirements when generating the x and y 

0 Likes
Message 4 of 8

mcgyvr
Consultant
Consultant

Ok.. I like more details.. 🙂

 

Now we are here..

Parameter("d2") = GoExcel.CellValue("filename.xlsx", "SheetName", "Cell")
iLogicVb.UpdateWhenDone = True


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 5 of 8

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:

 ...I was wondering there is any code for VBA or ilogic to read the points from excel in different sheets in excel


Hi lle5956,

 

There is a *.zip file at this link that has a VBA project that creates and updates a 3D sketch from co-ordinates in an XLS file:

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcarticles/Import-points-associatively-from-Excel-into-Inventor-s.html

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

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

EESignature

0 Likes
Message 6 of 8

Anonymous
Not applicable

The current code i have is this 

 

Sub Main()

 

   ' Get the CommandManager object.

    Dim oCommandMgr As CommandManager

    oCommandMgr = ThisApplication.CommandManager

 

    ' Get control definition for the line command.

    Dim oControlDef As ControlDefinition

    oControlDef = oCommandMgr.ControlDefinitions.Item( _

                                                 "SCxImportPointsCmd") 

    ' Execute the command.

    Call oControlDef.Execute

End Sub

 

which basically is just the command button to browse for the excel file and once it does. it imports whatever the x-y coordinate is but i need it to where it reads from that excel file just a different sheet/tab.. 

 

0 Likes
Message 7 of 8

MechMachineMan
Advisor
Advisor

Hmm. Control Definitions.

 

http://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html

 

As this blog says, that function might be limited and you might not actually be able to specify that for the command. It's worth looking into though!

 

You may have to think of some other way of organizing your excel files so that you can give in to what inventor wants.

 


--------------------------------------
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 8 of 8

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:

The current code i have is this .... 

...which basically is just the command button to browse for the excel file...

 


Hi lle5956,

 

Yeah, I don't see that being of much use for your goal here.

 

Here's a real quick iLogic example that reads in the specified Excel sheet, and works with the specified rows (oStartRow and oRowCount ).

 

This rule expects a 2D sketch to be active for edits.

 

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

 

owbook = "C:\TEMP\Book1.xlsx"
owSheet = "Sheet2"
GoExcel.Open(owbook,owSheet)

'start row to use
Dim oStartRow As Integer
oStartRow = 1

'number of rows to use
Dim oRowCount As Long
oRowCount = 10 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

' Set a reference to the active sketch.
Dim oSketch As PlanarSketch

'catch error when sketch 
'is not in edit mode
Try
	oSketch = ThisApplication.ActiveEditObject
Catch
	MessageBox.Show("Can not continue." & vbLf & _
	"The active Object Is Not a Sketch.", "iLogic")
	Return
End Try

' Set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

Dim i As Integer
For i = oStartRow To oRowCount
	Dim strx As String, stry As String
	strx = GoExcel.CellValue(owbook,owSheet, "A" & i)
	stry = GoExcel.CellValue(owbook,owSheet, "B" & i)    
	
	oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(strx, stry))	

Next

 

 

Example XLS:

 

XLS1.JPG

 

 

Example result:

 

XLS2.JPG

EESignature