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: 

To add custom materials

6 REPLIES 6
Reply
Message 1 of 7
krisnakumar
1301 Views, 6 Replies

To add custom materials

I am new to Autodesk Inventor, I need to add custom material to apply for the elements.   Please guide me.. 

6 REPLIES 6
Message 2 of 7

See overview article on Materials and Appearances  and code samples in the Inventor API Help.

 

The following method could help you:

Assets.Add( AssetType As AssetTypeEnum, LocalType As String, [Name] As Variant, [DisplayName] As Variant ) As Asset

 

Sub AddNewMaterial()
    Dim doc As Document
    Set doc = ThisApplication.ActiveDocument
    ' Only document appearances can be edited, so that's what's created.
    ' This assumes a part or assembly document is active.
    Dim docAssets As Assets
    Set docAssets = doc.Assets
    ' Create a new appearance asset.
    Dim appearance As Asset
    Set appearance = docAssets.Add( _
            AssetTypeEnum.kAssetTypeMaterial, _
            "Generic", "MySuperAlloy", "My Super Alloy")
End Sub

 Materials and Appearances.JPG


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 7

Thank you Vladimir for your reply,  I am trying the same with c# API.  However I could not add the Assert AS you done

 "Assets.AddAssetType As AssetTypeEnum, LocalType As String, [Name] As Variant, [DisplayName] As Variant ) As Asset".

 

Also, Please guide me to get the API for C#.

 

Thank you. 

Message 4 of 7

Try this:

private void btn_AddMaterial_Click(object sender, EventArgs e)
{
    Inventor.PartDocument doc = (PartDocument)oApp.ActiveDocument;
    // Only document appearances can be edited, so that's what's created.
    // This assumes a part or assembly document is active.
    Assets docAssets = doc.Assets;

    // Create a new appearance asset.
    Asset appearance = docAssets.Add(
            AssetTypeEnum.kAssetTypeMaterial,
            "Generic", 
            "MySuperAlloy", 
            "My Super Alloy"); 
}

 Result:

NewMaterial.JPG

 

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 7

Thank you Vladimir for you valuable support,

 I am glad that it has been working,  Here for this assert I have to edit Or add my custom "Physical Properties".  I have found a working code 

 

 

Dim oNewMaterial As Inventor.Material
oNewMaterial = oPart.Materials.Add("newmaterial", 1)
' Define the other properties of the material

oNewMaterial.LinearExpansion = 1.19
oNewMaterial.PoissonsRatio = 0.33
' Arbitrarily assigns the first render style in the render styles collection.
oNewMaterial.RenderStyle = oPart.RenderStyles.Item(1)
oNewMaterial.SpecificHeat = 0.23
oNewMaterial.ThermalConductivity = 1.505
oNewMaterial.UltimateTensileStrength = 2.683
oNewMaterial.YieldStrength = 1.813
oNewMaterial.YoungsModulus = 1.6

 

 

Is ther any way we can set our own properties for added assert.  I need to achieve this c sharp. 

 

Also I am not sure how we got the appreance,color for the assert.  

 

Thank you. 

Message 6 of 7

Here is the sample. It creates new material asset and set Poisson ratio value,

then it creates a new appearance asset and change its properties - color and reflectivity.

 

Inventor.PartDocument doc = (PartDocument)oApp.ActiveDocument;
// Only document appearances can be edited, so that's what's created.
// This assumes a part or assembly document is active.
Assets docAssets = doc.Assets;

//-------------------------------------------------------
// Create a new material asset
MaterialAsset m = (MaterialAsset)docAssets.Add(
        AssetTypeEnum.kAssetTypeMaterial,
        "Metal",
        "MySuperAlloy",
        "My Super Alloy AAA");

// access some existing material asset
MaterialAsset m = (MaterialAsset)doc.Assets["My Super Alloy AAA"];

// get the current Poisson ratio value
AssetValue v = m.PhysicalPropertiesAsset["structural_Poisson_ratio"];
Console.WriteLine("Initial value: {0:G}", ((FloatAssetValue)v).Value);

//change the Poisson ratio value
FloatAssetValue x = (FloatAssetValue)m
        .PhysicalPropertiesAsset["structural_Poisson_ratio"];
x.Value = 0.13;
Console.WriteLine("New value: {0:G}", ((FloatAssetValue)v).Value);

//-------------------------------------------------------
// Create a new appearance asset.
Asset appearance = docAssets.Add(
        AssetTypeEnum.kAssetTypeAppearance,
        "Generic", "AAAAA", "AAAAA");
// new color
TransientObjects oTransObjects = oApp.TransientObjects;
ColorAssetValue color = (ColorAssetValue)appearance["generic_diffuse"];
color.Value = oTransObjects.CreateColor(255, 15, 15);
// set reflectivity
x = (FloatAssetValue)appearance["generic_reflectivity_at_0deg"];
x.Value = 0.7;
x = (FloatAssetValue)appearance["generic_reflectivity_at_90deg"];
x.Value = 0.7;
//-------------------------------------------------------

Inventor API Help contains the code sample “Write out all materials to a file” that writes out information about all of the materials in all libraries. This can help to find out physical property names available for a material.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 7 of 7

Thanks Vladimir,

 

With this I can add phusical properties of PossionRatio ..

 

             FloatAssetValue x = (FloatAssetValue)m
                 .PhysicalPropertiesAsset["structural_Poisson_ratio"];
             x.Value = 0.13;

 

 

I have tried to add other properties like "Shear Modulus", "YouungModulus" and all other Properties

 However I could not achieve this...

I need to add/change a properties of my material.

 

Can you please help on this..

 

Thank you

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

Post to forums  

Autodesk Design & Make Report