Pulling data for parameters from spreadsheet

Pulling data for parameters from spreadsheet

BeasterlyJEC92
Contributor Contributor
309 Views
3 Replies
Message 1 of 4

Pulling data for parameters from spreadsheet

BeasterlyJEC92
Contributor
Contributor

I am trying to grab parameters from a spreadsheet to generate parts (similar to an i-part but without the link to the base part). 

 

I have got it to grab the parameters I add to the sheet, but it is also assigning values to parameters that are not in the spreadsheet? seems to default to the first cell. How do I stop this behavior?

 

Incorrect values:

BeasterlyJEC92_1-1678910798736.png

 

Is there a way to tell it to only grab parameters that exist in the spreadsheet that match the model parameters? 

 

Current code:

'sets multivalue list of all model parameters
ModParams = ThisDoc.Document.ComponentDefinition.Parameters.ModelParameters

'sets associated Excell file, Passes user text for file name: 
ExcelFile = "C:\CHS\Small Cell\" & Exc_file & ".xls"

'Passes user text for coloumn name containing values: 
Col = Col_Name

'Passes user text for sheet name: 
ExSheet = Excell_Sheet

'opens the excell file
GoExcel.Open(Exc_file, ExSheet)

'sets where to find the title row
GoExcel.TitleRow = 1

'cycle through all numerical model parameters And Do a thing.
For Each oParam In ModParams
	If oParam.Units <> "Text" And oParam.Units <> "Boolean" Then 
		ParameterName = oParam.Name
			'find in spreadsheet Row matching the inventor parameter name
			Ex_Parameter_Name = GoExcel.FindRow(ExcelFile, ExSheet, "Parameter", "=", ParameterName)
		
			'get the value from user specified coloumn
			value = GoExcel.CurrentRowValue(Col)
			Parameter(ParameterName) = value
			
			
	End If
Next

GoExcel.Close
InventorVb.DocumentUpdate()

Example of parameters I want to grab:

BeasterlyJEC92_0-1678910705792.png

 

 

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

A.Acheson
Mentor
Mentor
Accepted solution

hi @BeasterlyJEC92 

Have you assigned a column name of a object type string to the variable col? At the moment you have a variable set to another vairable

Col = Col_Name

If you don’t find the parameter name in the excel sheet the code should  return -1 and you can use this in an if statement along with a continue for line to move to next parameter.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

op_thorsager
Enthusiast
Enthusiast

the long way to do this would be to use goExcel.Cellvalue instead.

example could be 

Parameter(parameter) = GoExcel.CellValue

then do that for all your parameters. its bothersome to do it this way, but it will help you specify exactly what you want to change.

 

note: are you sure that your sketches are fully constrained? the "d" parameters aren't a parameter you've named, so it could be that inventor adjusts those values because of how you change values of dimensions you've named. 

0 Likes
Message 4 of 4

BeasterlyJEC92
Contributor
Contributor

Your a absolute genius, thank you! 

0 Likes