Add Material information to iProperty.

Add Material information to iProperty.

Rahul.Khande
Enthusiast Enthusiast
833 Views
4 Replies
Message 1 of 5

Add Material information to iProperty.

Rahul.Khande
Enthusiast
Enthusiast

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.

0 Likes
834 Views
4 Replies
Replies (4)
Message 2 of 5

Jef_E
Collaborator
Collaborator

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
0 Likes
Message 3 of 5

Rahul.Khande
Enthusiast
Enthusiast

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 ?

0 Likes
Message 4 of 5

Jef_E
Collaborator
Collaborator

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
0 Likes
Message 5 of 5

Rahul.Khande
Enthusiast
Enthusiast

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.

0 Likes