Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

'Autodesk.Revit.DB.Element' to 'Autodesk.Revit.DB.Wall' error

1 REPLY 1
SOLVED
Reply
Message 1 of 2
atis.sed
983 Views, 1 Reply

'Autodesk.Revit.DB.Element' to 'Autodesk.Revit.DB.Wall' error

Hi,

just starting to learn revit API and I get these two error when trying to execute simple sample Macro:

https://knowledge.autodesk.com/support/revit/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Revit/f...

 

 

Cannot implicitly convert type 'Autodesk.Revit.DB.Element' to 'Autodesk.Revit.DB.Wall'. An explicit conversion exists (are you missing a cast?) (CS0266) 

Argument 1: cannot convert from 'Autodesk.Revit.UI.UIDocument' to 'Autodesk.Revit.DB.Document' (CS1503)

 

		public void GetWallLayerMaterial(Autodesk.Revit.DB.Document document, Wall wall)
{
    // get WallType of wall
    WallType aWallType = wall.WallType;
    // Only Basic Wall has compoundStructure
    if (WallKind.Basic == aWallType.Kind)
    {
        // Get CompoundStructure
        CompoundStructure comStruct = aWallType.GetCompoundStructure();
        Categories allCategories = document.Settings.Categories;

        // Get the category OST_Walls default Material; 
        // use if that layer's default Material is <By Category>
        Category wallCategory = allCategories.get_Item(BuiltInCategory.OST_Walls);
        Autodesk.Revit.DB.Material wallMaterial = wallCategory.Material;

        foreach (CompoundStructureLayer structLayer in comStruct.GetLayers())
        {
            Autodesk.Revit.DB.Material layerMaterial = document.GetElement(structLayer.MaterialId) as Material;

            // If CompoundStructureLayer's Material is specified, use default
            // Material of its Category
            if (null == layerMaterial)
            {
                switch (structLayer.Function)
                {
                    case MaterialFunctionAssignment.Finish1:
                        layerMaterial = 
                            allCategories.get_Item(BuiltInCategory.OST_WallsFinish1).Material;
                        break;
                    case MaterialFunctionAssignment.Finish2:
                        layerMaterial = 
                            allCategories.get_Item(BuiltInCategory.OST_WallsFinish2).Material;
                        break;
                    case MaterialFunctionAssignment.Membrane:
                        layerMaterial = 
                            allCategories.get_Item(BuiltInCategory.OST_WallsMembrane).Material;
                        break;
                    case MaterialFunctionAssignment.Structure:
                        layerMaterial =  
                            allCategories.get_Item(BuiltInCategory.OST_WallsStructure).Material;
                        break;
                    case MaterialFunctionAssignment.Substrate:
                        layerMaterial = 
                            allCategories.get_Item(BuiltInCategory.OST_WallsSubstrate).Material;
                        break;
                    case MaterialFunctionAssignment.Insulation:
                        layerMaterial = 
                            allCategories.get_Item(BuiltInCategory.OST_WallsInsulation).Material;
                        break;
                    default:
                        // It is impossible to reach here
                        break;
                }
                if (null == layerMaterial)
                {
                    // CompoundStructureLayer's default Material is its SubCategory
                    layerMaterial = wallMaterial;
                }
            }
            TaskDialog.Show("Revit","Layer Material: " + layerMaterial);
        }
    }
}
		
		
public void TestMacro()
			{
		UIDocument uidoc = Application.ActiveUIDocument;
		Document doc = Application.ActiveUIDocument.Document;
		
		Wall UserWall = null;
		Reference wallreference = null;
			
		wallreference = uidoc.Selection.PickObject(ObjectType.Element);
		UserWall = uidoc.Document.GetElement(wallreference);
		
		GetWallLayerMaterial(uidoc, UserWall);
			}
		}
	}

 

 

Tags (1)
Labels (1)
1 REPLY 1
Message 2 of 2
Organon
in reply to: atis.sed

@atis.sed 

 

Hi,

 

Try this:

UserWall = uidoc.Document.GetElement(wallreference) as Wall;

 

You're passing the  uidoc argument instead doc in your  GetWallLayerMaterial method.

 

Regards,


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube

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

Post to forums  

Rail Community


Autodesk Design & Make Report