Hi,
I am trying to get Parameters value and Units using C#.net.
It is working through VBA and .net.But while i am using C#.net, it is showing meassage that "It is not support by the Langauage".
Can any one suggets m eto get Unit fo Patrameter using C#.net.
*********Code
foreach (Parameter oParam in oParams)
{
// string Str = oParam.Units; //Getting error in this line
Tlist.Add(oParam.Name + "|" + Convert.ToString(oParam.Expression) + "|" +"in");//oParam.Units
}
Regards,
Appadurai.G
Solved! Go to Solution.
Solved by rjay75. Go to Solution.
In C# I've had to use the get_Units() method instead of the Units property. For some reason the units property can never be found.
string units = oParam.get_Units();
Also by the way, the Expression property is always a string.
Hi Rodney,
I get a 'member not found' exception at runtime when I use Parameter.get_Units(); in C#
I'm using Inventor 2019.4. Any ideas?
Thanks,
Luke
Hi Luke,
Did you set the reference Autodesk.Inventor.Interop's "Embed Interop Types" to False? Make sure to set this property to False always when you use Inventor API in C#/VB.net, otherwise it may impact some events/methods.
Thanks for the reply. This didn't solve the problem.
In the end I couldn't get the parameter units using C# despite trying a few different methods, so I had to include some VB code in my C# solution to get the units!
Full solution was as follows:
1) In Visual Studio, create a new VB.net Project (of type Class Library) and add it to the existing C# solution.
2) Add a function to the VB.net class which receives a parameter and returns the unit string.
3) Build the VB.net project.
4) Add a reference to the VB.net project dll to the top of your C# project.
5) Use the VB.net GetParameterUnits function whenever you need.
This worked fine for me.
Hope it helps
Luke
Did you recompile after setting Embed Interop Types to False?
For me too that got rid of the error.
In addition, you could also use a dynamic variable to access the property using late-binding as your VB project does:
https://modthemachine.typepad.com/my_weblog/2021/02/member-not-found-error-in-c-add-in.html
I had the same issue today. I write the fix for C# users. See my GitHub for more info.
https://github.com/CSmichaelnavara/Inventor-Parameter-Units-Fix
I am converting vb.net code into c# and face this issue.
Changing dll property gives lots of errors so that is "No-Go" for me.
Adam's reply work for me.
Specially this article's final solution of using 'dynamic' object works perfectly.