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;
Solved! Go to Solution.
Solved by ianteneth. Go to Solution.
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);
Can't find what you're looking for? Ask the community or share your knowledge.