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: 

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

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
gadurai
2500 Views, 10 Replies

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

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

10 REPLIES 10
Message 2 of 11
rjay75
in reply to: gadurai

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();

 

Message 3 of 11
rjay75
in reply to: gadurai

Message 4 of 11
gadurai
in reply to: rjay75

Hi Rodney ,

 

Thanks for your Support.

 

Regards,

Appadurai.G

Message 5 of 11
LukeDavenport
in reply to: rjay75

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

 

 

Message 6 of 11
YuhanZhang
in reply to: LukeDavenport

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.

Message 7 of 11
LukeDavenport
in reply to: YuhanZhang

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

Message 8 of 11
adam.nagy
in reply to: LukeDavenport

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
in reply to: rjay75

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

Message 10 of 11
Michael.Navara
in reply to: gadurai

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
in reply to: gadurai

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.

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

Post to forums  

Autodesk Design & Make Report