Anuncios
Welcome to the Revit Ideas Board! Before posting, please read the helpful tips here. Thank you for your Ideas!
Comentario
Autodesk
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();

   }

}