Announcements
Welcome to the Revit Ideas Board! Before posting, please read the helpful tips here. Thank you for your Ideas!
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Allow Material API access

Allow Material API access

It seems that Revit has a closed API for it's materials. It's very hard for plugin creators to have access to Revit's material maps and properties.

 

https://forums.autodesk.com/t5/revit-api-forum/how-to-get-the-material-s-image-path-or-name/td-p/580...
http://thebuildingcoder.typepad.com/blog/2013/07/texture-bitmap-and-uv-coordinates.html

https://render.otoy.com/forum/viewtopic.php?f=25&t=52667&p=317585

 

Please open up the API to developers so that they can create plugins that capture our design intents in Revit. Otherwise, we'll have to input the data ourselves. We want you to make it easy for developers to have access to your material information, instead of closing up the process and making it obscure.

16 Comments
sasha.crotty
Community Manager
Status changed to: Implemented

Thanks for submitting your idea. I'm happy to say that an API for Appearance Assets is available starting with Revit 2018.1. I am marking this idea as Implemented.

sarsenault2CCSS
Advisor

Amazing! Thank you Sasha!

pfk
Enthusiast
Enthusiast
Sasha - how do I get the full file path string from a string Asset from an AppearanceAssetElement please? I get a string like "Mats\\Metal\\external.dependency\\Simple_Metal_Mtl_Brush_pattern.jpg" which is not the full file path. Thanks. Paul
sarsenault2CCSS
Advisor

@sasha.crotty Please have someone help Paul if possible 😄 😄 😄

 

Revit materials in Octane render will be amazing!

bshafiro
Autodesk

@pfk If the file is in the default system library folder, - only the relative path is saved as a value of AssetPropertyString.

If it is not, then the absolute path is saved. But it is possible to get from the relative path to the full path by using Application.GetLibraryPaths(). I hope this helps.

pfk
Enthusiast
Enthusiast
Thanks. It's still not particularly clear how this is used. For example, how do I get the Generic Image texturemap from the Carpet(1) material of the rac_basic_sample_project.rvt? The Material panel shows this texturemap as finishes.flooring.carpet.needlepunch.white.jpg, but which AssetProperty from element.GetRenderingAsset() contains this map name? It would be great to have this info in the documentation rather than requiring plugin devs to reverse engineer things. Thanks. Paul
bshafiro
Autodesk

You can search for the schema in RevitAPI help. Here is the list of properties for an appearance asset of Generic schema: the property that is looking for is “GenericDiffuse”: the description in the help usually maps the name in Material browser.

 

Untitled.png 

 

Now, as “GenericDiffuse” is a property that can be connected to another property, like all a texture map, he has to do the following (this is based from the code snippet we provide for new method GetSingleConnectedAsset):

 

ElementId appearanceAssetId = material.AppearanceAssetId;

 

   AppearanceAssetElement assetElem = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;

 

   using (Transaction t = new Transaction(material.Document, "Change material bumpmap bitmap"))

   {

      t.Start();

 

      using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(assetElem.Document))

      {

         Asset editableAsset = editScope.Start(assetElem.Id);   // returns an editable copy of the appearance asset

 

         AssetProperty genericDiffuseProperty = editableAsset.FindByName(Generic.GenericDiffuse);

 

         // Find the connected asset (with a shortcut to get the only one)

 

         Asset connectedAsset = genericDiffuseProperty.GetSingleConnectedAsset();

 

 

         if (connectedAsset != null)

         {

            // Find the target asset property

            AssetPropertyString bitmapProperty = connectedAsset.FindByName( "unifiedbitmap_Bitmap") as AssetPropertyString;

 

            if (bitmapProperty.IsValidValue(imageFilePath))

 

               bitmapProperty.Value = imageFilePath;

         }

 

 

         editScope.Commit(true);

      }

 

      t.Commit();

   }

 

 

 

I hope that helps.

 

pfk
Enthusiast
Enthusiast
Thanks you for the above code. Whilst I am extremely grateful for your help - I am finding the documentation on this to be woefully lacking. And the naming conventions between the different material type schemas is very inconsistent. For instance, the Concrete class has a ConcreteBmMap and a ConcreteBumpMap! And Stone has StoneBumpMap and StoneColor.
pfk
Enthusiast
Enthusiast
When I query the "unifiedbitmap_Bitmap" Value from an existing material, I get something like "1\\mats\\woods & plastics.finish carpentry.wood.walnut.png". How can I determine that the texturemap path is incomplete and needs pre-pending with a library path pls?
pfk
Enthusiast
Enthusiast
Further to the above problem, the Wood - Medium Brown material (from the rac_basic_sample_project) has a Hardwood.Hardwood color of "1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png|1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png|1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png" - which appears to be corrupt. How is a plugin meant to get the correct map name pls? Thanks
cftrevizo
Contributor

Looks like they closed this case? I was looking at just for remapping, & or to replace a Texture that has been moved/renamed & placed into a server location. Any help on which ones to use???

sarsenault2CCSS
Advisor
I suggest asking on the Revit API forums Hopefully they do a better job at supporting users than they do here https://forums.autodesk.com/t5/revit-api-forum/bd-p/160
bshafiro
Autodesk

If I understand your question correctly, you are looking for the right way to change the path for the texture in a particular Material. Please take a look at the code snippet below which does exactly that. Does it help? If not, please add more details to your question.

public void SetBumpmapBitmap(Material material, String bumpmapImageFilepath)

{

   ElementId appearanceAssetId = material.AppearanceAssetId;

   AppearanceAssetElement assetElem

      = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;

 

   using(Transaction t

            = new Transaction(material.Document, "Change material bumpmap bitmap"))

   {

      t.Start();

 

      using(AppearanceAssetEditScope editScope

               = new AppearanceAssetEditScope(assetElem.Document))

      {

         // returns an editable copy of the appearance asset

         Asset editableAsset = editScope.Start(assetElem.Id);

 

         AssetProperty bumpMapProperty = editableAsset["generic_bump_map"];

 

         // Find the connected asset (with a shortcut to get the only one)

         Asset connectedAsset = bumpMapProperty.GetSingleConnectedAsset();

         if (connectedAsset == null)

         {

            // Add a new default connected asset

            bumpMapProperty.AddConnectedAsset("UnifiedBitmap");

            connectedAsset = bumpMapProperty.GetSingleConnectedAsset();

         }

         if (connectedAsset != null)

         {

            // Find the target asset property

            AssetPropertyString bumpmapBitmapProperty

               = connectedAsset["unifiedbitmap_Bitmap"] as AssetPropertyString;

 

            if (bumpmapBitmapProperty.IsValidValue(bumpmapImageFilepath))

               bumpmapBitmapProperty.Value = bumpmapImageFilepath;

         }

         editScope.Commit(true);

      }

      t.Commit();

   }

}

pfk
Enthusiast
Enthusiast

> Does it help? If not, please add more details to your question.

 

Hi - I am still waiting on a response from Autodesk on my questions above.....in particular....

 

> Thanks you for the above code. Whilst I am extremely grateful for your help - I am finding the documentation on this to be woefully lacking. And the naming conventions between the different material type schemas is very inconsistent. For instance, the Concrete class has a ConcreteBmMap and a ConcreteBumpMap! And Stone has StoneBumpMap and StoneColor.

 

> When I query the "unifiedbitmap_Bitmap" Value from an existing material, I get something like "1\\mats\\woods & plastics.finish carpentry.wood.walnut.png". How can I determine that the texturemap path is incomplete and needs pre-pending with a library path pls?

 

> Further to the above problem, the Wood - Medium Brown material (from the rac_basic_sample_project) has a Hardwood.Hardwood color of "1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png|1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png|1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png" - which appears to be corrupt. How is a plugin meant to get the correct map name pls? Thanks

 

Paul

Tarek_K
Autodesk
Status changed to: Gathering Support
 
Tarek_K
Autodesk
Status changed to: Implemented
 

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

Submit Idea  

Rail Community


Autodesk Design & Make Report