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: 

Assets object missing "Item" property - Inventor API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
tu.phan
601 Views, 2 Replies

Assets object missing "Item" property - Inventor API

Hello everybody,

 

I'm trying to set the material of a part inside an assembly using the material's name as a string. Code snippet is as follows. occMaterial is the string for the name of the material. oPartDoc is the PartDocument. oOcc is the ComponentOccurrence inside the assembly. 

 

I'm getting an error saying "'Assets' does not contain a definition for 'Item' and no accessible extension method 'Item' accepting a first argument of type 'Assets' could be found..."

 

Attached screenshot shows the Assets object in the object browser in Visual Studio.

 

What gives?

 

Thanks!

 

Asset oAsset = oPartDoc.Assets.Item(occMaterial);
            oPartDoc.ActiveMaterial = oAsset;
            oOcc.Appearance = oAsset;

 

2 REPLIES 2
Message 2 of 3
ianteneth
in reply to: tu.phan

Hi @tu.phan,

 

In case you haven't figured this out yet, or if anyone in the future has this problem, I think I know what you need to change to make your code work. I am not sure what an Asset is, but this code below seems to work.

 

Change this line:

Asset oAsset = oPartDoc.Assets.Item(occMaterial);

 

To this line:

Asset oAsset = oPartDoc.Assets[occMaterial];

 

I think the "Items" method is more of a VB.Net or VBA thing which is why it isn't working in C#. Here is a code snippet that successfully retrieves the material asset(?) from the active part. Should display "Aluminum - Flat". Hope this helps!

Application application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application"        ) as Application;
PartDocument oPartDoc = application.ActiveDocument as PartDocument;
string occMaterial = "Aluminum - Flat";

Asset oAsset = oPartDoc.Assets[occMaterial];
Console.WriteLine(oAsset.DisplayName);

 

Message 3 of 3
tu.phan
in reply to: ianteneth

Thanks, @ianteneth I was able to figure it out 😀.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report