Esempio n. 1
0
        public static Element SetTransparencyProperties(
            Element appearanceAsset,
            int amount = 0)
        {
            if (appearanceAsset == null)
            {
                throw new ArgumentNullException(nameof(appearanceAsset));
            }

            if (!(appearanceAsset.InternalElement is Autodesk.Revit.DB.AppearanceAssetElement aa))
            {
                throw new Exception("Could not retrieve Appearance Asset from Material.");
            }

            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);
            using (var editScope = new Autodesk.Revit.DB.Visual.AppearanceAssetEditScope(doc))
            {
                var editableAsset = editScope.Start(aa.Id);

                if (!(editableAsset.FindByName("generic_transparency") is Autodesk.Revit.DB.Visual.AssetPropertyDouble genericTransparencyProperty))
                {
                    throw new Exception("Could not find Oblique Reflectivity property.");
                }

                genericTransparencyProperty.Value = amount / 100.0;

                editScope.Commit(false);
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(aa.ToDSType(true));
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the Diffuse Color property for the Appearance Asset inside of the Material.
        /// </summary>
        /// <param name="appearanceAsset">Appearance Asset to set the color for.</param>
        /// <param name="color">Color that property will be set to.</param>
        /// <returns>Appearance Asset with the adjusted color property.</returns>
        public static Element SetDiffuseColor(Element appearanceAsset, Color color)
        {
            if (appearanceAsset == null)
            {
                throw new ArgumentNullException(nameof(appearanceAsset));
            }
            if (color == null)
            {
                throw new ArgumentNullException(nameof(color));
            }

            var aa  = appearanceAsset.InternalElement as Autodesk.Revit.DB.AppearanceAssetElement;
            var c   = new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue);
            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);
            using (var editScope = new Autodesk.Revit.DB.Visual.AppearanceAssetEditScope(doc))
            {
                var editableAsset   = editScope.Start(aa.Id);
                var diffuseProperty = editableAsset.FindByName("generic_diffuse") as Autodesk.Revit.DB.Visual.AssetPropertyDoubleArray4d;
                diffuseProperty.SetValueAsColor(c);
                editScope.Commit(true);
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(aa.ToDSType(true));
        }
Esempio n. 3
0
        public static Element SetGenericProperties(
            Element appearanceAsset,
            Color color,
            int glossiness = 50,
            bool metallic  = false)
        {
            if (appearanceAsset == null)
            {
                throw new ArgumentNullException(nameof(appearanceAsset));
            }

            if (color == null)
            {
                throw new ArgumentNullException(nameof(color));
            }

            if (!(appearanceAsset.InternalElement is Autodesk.Revit.DB.AppearanceAssetElement aa))
            {
                throw new Exception("Could not retrieve Appearance Asset from Material.");
            }

            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);
            using (var editScope = new Autodesk.Revit.DB.Visual.AppearanceAssetEditScope(doc))
            {
                var editableAsset = editScope.Start(aa.Id);
                if (!(editableAsset.FindByName("generic_diffuse") is Autodesk.Revit.DB.Visual.AssetPropertyDoubleArray4d diffuseProperty))
                {
                    throw new Exception("Could not find Color property.");
                }

                diffuseProperty.SetValueAsColor(ColorUtilities.RevitColorByColor(color));

                if (!(editableAsset.FindByName("generic_glossiness") is Autodesk.Revit.DB.Visual.AssetPropertyDouble glossinessProperty))
                {
                    throw new Exception("Could not find Glossiness property.");
                }

                glossinessProperty.Value = glossiness / 100.0;

                if (!(editableAsset.FindByName("generic_is_metal") is Autodesk.Revit.DB.Visual.AssetPropertyBoolean isMetalProperty))
                {
                    throw new Exception("Could not find Metallic property.");
                }

                isMetalProperty.Value = metallic;

                editScope.Commit(false);
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(aa.ToDSType(true));
        }
Esempio n. 4
0
        protected void UpdateAssetElementFromInputs(DB.AppearanceAssetElement assetElement, T assetData)
        {
            // open asset for editing
            using (var scope = new DB.Visual.AppearanceAssetEditScope(assetElement.Document))
            {
                var editableAsset = scope.Start(assetElement.Id);

                UpdateAssetFromData(editableAsset, assetData);

                // commit the changes after all changes has been made
                scope.Commit(true);
            }
        }