- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Add Material information to iProperty.
Hello,
I have developed my plugin for Inventor which imports my CAD file into Inventor.
While importing file, I write properties related to part file in iProperties-> Custom. I could do this successfully.
Now, I want to write material property. I tried by code below but it doesn't work for 'Material'.
In code below, you can see that I have updated property for 'Material' and 'Engineer' but only 'Engineer' property gets updated not the 'Material'.
PropertySets pSets = partDoc.PropertySets;
foreach (PropertySet set in pSets)
{
String name = set.Name;
if (name.Equals("Design Tracking Properties"))
{
Property prop = set.get_ItemByPropId(20);
prop.Value = "My Material String";
Property prop1 = set.get_ItemByPropId(42);
prop1.Value = "Engineer";
}
}
Can someone please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I believe that the material does not exist? And also you are not able to change the material by hand as it is greyed out?
note that you can only change material to materials that exist in the material library.
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for your suggestions.
Asset asset = partDoc.Assets.Add(AssetTypeEnum.kAssetTypeMaterial, "Test Material", "Test Material"); partDoc.ActiveMaterial = asset;
I tried above code by adding asset material and then using asset as ActiveMaterial but still it didn't work.
Any other work around you would suggest ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is straight from my addin and it works for me. This allows you to take an existing material and set it for the file.
' Get the asset that corresponds with the selected material
Dim oAsset As Asset
oAsset = EM_AddIn.StandardAddInServer.m_inventorApplication.AssetLibraries.Item("EllimetalMaterialLibrary") _
.MaterialAssets.Item("Material name here")
' Set the document material
oDoc.ActiveMaterial = oAsset
Your code seems odd to me to always add a material to use it. Just use a existing one.
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you !!
Actually, I need to add a custom material and apply that to part document.
I never worked on material yet. So don't know how it works. What all I have for my material is only name for e.g. "CustomMaterial". Rest material properties can be default.
I have few questions :
1. Can we add custom material ? If yes, how can we ?
2. How to apply that custom material ?
3. Is there any working C# code snippet ?
I tried your snippet as below :
ThisApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
foreach (AssetLibraries lib in ThisApplication.AssetLibraries)
{
foreach (AssetLibrary assetlib in lib)
{
string name = assetlib.DisplayName;
}
}But it's crashing at highlighted code above.