Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic and CAM API get operation parameter value by name rather than index?

3 REPLIES 3
Reply
Message 1 of 4
Chris.Brough
196 Views, 3 Replies

iLogic and CAM API get operation parameter value by name rather than index?

Hello, is there a way to get operations parameter value by using the parameter name rather than its index?

 

Currently pulling mainly tooling information via the following method.  (obviously missing a good amount of setup but gets the idea across)

 

Dim toolOALength As Double
Dim toolDia As Double
Dim thisOpObject As HSMOperation
toolOALength = thisOpObject.Parameters.Item(53).Value
toolDia = thisOpObject.Parameters.Item(41).Value

 

 

this works great for most operations, though i just output a Drill operation where the index is different for the parameter named tool_overallLengthWhile most operations seem to have tool_overallLength as index #53;  "Drill" operation uses index #54 for tool_overallLength since there is an added parameter at index #18 which offsets the parameters by one for most tooling info.

 

What I'm looking for is something like:

 

toolOALength = thisOpObject.Parameters.Name("tool_overallLength").Value

 

 

Hoping someone else has some experience with this in the iLogic cam API?

 

The primary function here is for iLogic to pull a tooling list and compare it to our machine's proprietary tooling library file.  If the tool isn't seen in the library or set up with the proper parameters required by the machine, it then prompts the user to set up the tooling prior to posting.

 

PS: hoping parameters will be read/write soon??

 

ChrisBrough_0-1694023049599.png

 

EDIT: here's my current work-around, which I'll need to customize for each operation where indices are different offsets.  you'll notice all indices in the "IF" are increased by 1 compared to those within the "ELSE"

If thisOpObject.Strategy = "drill" Then  'all operations equal to "drill", parameter index is +1 compared to most others
	toolOALength = thisOpObject.Parameters.Item(54).Value
	toolDia = thisOpObject.Parameters.Item(42).Value
	toolName = thisOpObject.Parameters.Item(38).Value
	toolClockwise = thisOpObject.Parameters.Item(90).Value 'tool_clockwise, true/false
	toolFeedSpeed = thisOpObject.Parameters.Item(80).Value
	If toolClockwise = True Then
		toolSpindleSpeed = thisOpObject.Parameters.Item(76).Value 'positive RPM for CW rotation
		Logger.Info("Tool spins clockwise; rpm is " & toolSpindleSpeed)
	Else
		toolSpindleSpeed = -thisOpObject.Parameters.Item(76).Value 'negative RPM for CCW rotation
		Logger.Info("Tool spins counter-clockwise; rpm is " & toolSpindleSpeed)
	End If
Else	'all non-drill operations
	toolOALength = thisOpObject.Parameters.Item(53).Value
	toolDia = thisOpObject.Parameters.Item(41).Value
	toolName = thisOpObject.Parameters.Item(37).Value
	toolClockwise = thisOpObject.Parameters.Item(89).Value 'tool_clockwise, true/false
	Logger.Info(toolClockwise)
	toolFeedSpeed = thisOpObject.Parameters.Item(79).Value
	If toolClockwise = True Then
		toolSpindleSpeed = thisOpObject.Parameters.Item(75).Value 'positive RPM for CW rotation
		Logger.Info("Tool spins clockwise; rpm is " & toolSpindleSpeed)
	Else
		toolSpindleSpeed = -thisOpObject.Parameters.Item(75).Value 'negative RPM for CCW rotation
		Logger.Info("Tool spins counter-clockwise; rpm is " & toolSpindleSpeed)
	End If
End If

 

Labels (3)
3 REPLIES 3
Message 2 of 4
A.Acheson
in reply to: Chris.Brough

Hi @Chris.Brough 

 

I have no expeirience with CAM API  but if the dll is loaded and the correct object declared you should be able to see what methods and properties the object has. You should be able to access the parameter object once declared. 

 

Also if you go type in the parameter index does it show the parameter listed by index or object? If object you can use a string value directly. 

 

Can you test and see if it returns a name for the parameter?

Dim toolOALength As Double
Dim toolDia As Double
Dim thisOpObject As HSMOperation
Dim toolDiaParam As Parameter = thisOpObject.Parameters.Item(41)

MessageBox.Show(toolDiaParam.Name)

If that works then you can simply loop through the parameters collection and check the name and perform an operation on finding that name.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 4
Chris.Brough
in reply to: Chris.Brough

Hi Alan, the numbers where you show "Item(41)" are not consistent across all operation styles.  So the main goal is to grab data from the parameter by using the name property which is more consistent than the item number (at least if it exists in the operation)

 

so basically avoiding the need for using the item # since that method is not reliably consistent.  not to mention if they add new operation types in the future, they're more likely to keep the parameter names matching than the index numbers.

Message 4 of 4
JelteDeJong
in reply to: Chris.Brough

There is a workaround to select a parameter. You can cast the "Parameters" object to a list of parameters. Then use LINQ to find the parameter with some name.

consider the following example iLogic rule. It takes the first feature of a part document. and then selects the parameter with the name Depth.

Dim doc As PartDocument = ThisDoc.Document
Dim features = doc.ComponentDefinition.Features
Dim thisOpObject = features.Item(1)

Dim parameter = thisOpObject.Parameters.Cast(Of Parameter).FirstOrDefault(Function(p) p.Name.Equals("Depth"))

Logger.Info(parameter.Value)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report