How to get Parameter's unit in C#.Net

How to get Parameter's unit in C#.Net

Anonymous
Not applicable
3,064 Views
10 Replies
Message 1 of 11

How to get Parameter's unit in C#.Net

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
3,065 Views
10 Replies
Replies (10)
Message 2 of 11

rjay75
Collaborator
Collaborator
Accepted 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();

 

0 Likes
Message 3 of 11

rjay75
Collaborator
Collaborator
0 Likes
Message 4 of 11

Anonymous
Not applicable

Hi Rodney ,

 

Thanks for your Support.

 

Regards,

Appadurai.G

0 Likes
Message 5 of 11

LukeDavenport
Collaborator
Collaborator

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

 

 

0 Likes
Message 6 of 11

YuhanZhang
Autodesk
Autodesk

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.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 7 of 11

LukeDavenport
Collaborator
Collaborator

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

0 Likes
Message 8 of 11

adam.nagy
Autodesk Support
Autodesk Support

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 



Adam Nagy
Autodesk Platform Services
Message 9 of 11

oransen
Collaborator
Collaborator

@rjay75does get_Units still work for you? When I try it (Inventor 2019) it crashes....

0 Likes
Message 10 of 11

Michael.Navara
Advisor
Advisor

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

 

Message 11 of 11

Prashant.Baher
Observer
Observer

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.

0 Likes