/// <summary> /// Get the material type via giving material. /// According to my knowledge, the material type can be retrieved by two ways now: /// 1. If the PropertySetElement exists, retrieve it by PHY_MATERIAL_PARAM_CLASS parameter. (via PropertySetElement class) /// 2. If it's indenpendent, retrieve it by PHY_MATERIAL_PARAM_TYPE parameter(via Material class) /// </summary> /// <param name="material"></param> /// <returns></returns> private StructuralAssetClass GetMaterialType(Material material) { if (material.StructuralAssetId != ElementId.InvalidElementId) { PropertySetElement propElem = m_revit.ActiveUIDocument.Document.GetElement(material.StructuralAssetId) as PropertySetElement; Parameter propElemPara = propElem.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS); if (propElemPara != null) { return((StructuralAssetClass)propElemPara.AsInteger()); } } return(StructuralAssetClass.Undefined); //ElementId propElemId = material.GetMaterialAspectPropertySet(MaterialAspect.Structural); //if (ElementId.InvalidElementId == propElemId) //{ // Parameter independentPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_TYPE); // if (null == independentPara) // { // return MaterialType.Generic; // } // return (MaterialType)independentPara.AsInteger(); //} //PropertySetElement propElem = m_revit.ActiveUIDocument.Document.GetElement(propElemId) as PropertySetElement; //Parameter propElemPara = propElem.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS); //if (null == propElemPara) //{ // return MaterialType.Generic; //} //return (MaterialType)propElemPara.AsInteger(); }
private DiffuseMaterial getMaterial(Face face) { ElementId matId = face.MaterialElementId; Autodesk.Revit.DB.Material mat = this.doc.GetElement(matId) as Autodesk.Revit.DB.Material; return(this.getMaterial(mat)); }
public RevitCSLayer CreateCompoundStructureLayer( [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc Document) { RevitCSLayer layer = new RevitCSLayer(); layer.DeckEmbeddingType = (RevitDB.StructDeckEmbeddingType) Enum.Parse( typeof(RevitDB.StructDeckEmbeddingType), this.DeckEmbeddingType); RevitDB.Element deck = this.DeckProfileId.GetElem(Document); if (deck != null) { layer.DeckProfileId = deck.Id; } layer.Function = (RevitDB.MaterialFunctionAssignment) Enum.Parse( typeof(RevitDB.MaterialFunctionAssignment), this.Function); layer.LayerCapFlag = this.LayerCapFlag; RevitDB.Material mat = (RevitDB.Material) this.MaterialId.GetElem(Document); if (mat != null) { layer.MaterialId = mat.Id; } layer.Width = this.Width; return(layer); }
}//end fun //以下是舊版主控台範例程式碼,所以把它封存起來 #region prototype public void GetMaterial(Document document, Wall wall) { foreach (Parameter parameter in wall.Parameters) { Definition definition = parameter.Definition; // material is stored as element id if (parameter.StorageType == StorageType.ElementId) { if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS && definition.ParameterType == ParameterType.Material) { Autodesk.Revit.DB.Material material = null; Autodesk.Revit.DB.ElementId materialId = parameter.AsElementId(); if (-1 == materialId.IntegerValue) { //Invalid ElementId, assume the material is "By Category" if (null != wall.Category) { material = wall.Category.Material; } } else { material = document.GetElement(materialId) as Material; } Console.WriteLine("Revit", "Element material: " + material.Name + "\t" + material.Id); //TaskDialog.Show("Revit", "Element material: " + material.Name); break; } } } }//end fun
public static string GetMaterialName(Document document, Element element) { string returnString = string.Empty; foreach (Autodesk.Revit.DB.Parameter parameter in element.Parameters) { Definition definition = parameter.Definition; //material is stored as element id if (parameter.StorageType == StorageType.ElementId) { if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS && definition.ParameterType == ParameterType.Material) { Autodesk.Revit.DB.Material material = null; Autodesk.Revit.DB.ElementId materialId = parameter.AsElementId(); if (-1 == materialId.IntegerValue) { //Invalid ElementId, assume the material is "By Category" returnString = "<ByCategory>"; } else { material = document.GetElement(materialId) as Material; returnString = material.Name; } } } } return(returnString); }
/// <summary> /// Creates a string representation of the object. /// </summary> /// <returns nampe="string">A string representation of the object.</returns> public override string ToString() { int i = 0; string s = base.ToString(); if (this.internalLayers.Count != 0) { s = s + ": Core Layers " + internalFirstCoreLayerIndex + " to " + internalLastCoreLayerIndex; foreach (cg.Dictionary <string, object> layer in this.internalLayers) { string materialName = "<By Category>"; string functionName = "None"; string widthName = "None"; revitDB.Material material = (revitDB.Material)layer["Material"]; if (material != null) { materialName = material.Id.ToString(); } if (layer["Layer Function"] != null) { functionName = layer["Layer Function"].ToString(); } if (layer["Width"] != null) { widthName = layer["Width"].ToString(); } s = s + "\n Layer " + i + ": " + layer["Layer Function"] + ", Width-> " + layer["Width"] + ", MaterialId-> " + materialName; i++; } } return(s); }
public static Material GetMaterial(Document document, Element element) { Autodesk.Revit.DB.Material material = null; foreach (Autodesk.Revit.DB.Parameter parameter in element.Parameters) { Definition definition = parameter.Definition; // material is stored as element id if (parameter.StorageType == StorageType.ElementId) { if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS && definition.ParameterType == ParameterType.Material) { Autodesk.Revit.DB.ElementId materialId = parameter.AsElementId(); if (-1 == materialId.IntegerValue) { //Invalid ElementId, assume the material is "By Category" if (null != element.Category) { material = element.Category.Material; } } else { material = document.GetElement(materialId) as Material; } break; } } } return(material); }
/// <summary> /// Dump properties specific to a decking layer /// </summary> /// <param name="deck"></param> private void DumbDeck(CompoundStructureLayer deck) { m_displayForm.WriteLine("Dumping Deck"); if (deck.MaterialId != ElementId.InvalidElementId) { // get the deck material object. In this sample all we need to display is the // name, but other properties are readily available from the material object. Autodesk.Revit.DB.Material deckMaterial = m_document.GetElement(deck.MaterialId) as Material; m_displayForm.WriteLine("Deck Material = " + deckMaterial.Name); } if (deck.DeckProfileId != ElementId.InvalidElementId) { // the deck profile is actually a family symbol from a family of profiles Autodesk.Revit.DB.FamilySymbol deckProfile = m_document.GetElement(deck.DeckProfileId) as FamilySymbol; // firstly display the full name as the user would see it in the user interface // this is done in the format Family.Name and then Symbol.Name m_displayForm.WriteLine("Deck Profile = " + deckProfile.Family.Name + " : " + deckProfile.Name); // the symbol object also contains parameters that describe how the deck is // specified. From these parameters an external application can generate // identical decking for analysis purposes DumpParameters(deckProfile); } }
/// <summary> /// Creates Synthetic.Revit.CompoundStructure in a destination document by changing the material ids to correspond to materials in the destination document. Materials not in the destination document are copied into the document. /// </summary> /// <param name="compoundStructure">A Synthetic.Revit.CompoundStructure from the source document</param> /// <param name="destinationDoc">The document to copy the CompoundStructure into.</param> /// <returns name="compoundStructure">A Synthetic.Revit.CompoundStructure in the destination document.</returns> internal static CompoundStructure _CopyToDocument(CompoundStructure compoundStructure, revitDoc destinationDoc) { revitDoc doc = compoundStructure.internalDocument; cg.List <revitCSLayer> destinationLayers = new cg.List <revitCSLayer>(); foreach (revitCSLayer sourceLayer in compoundStructure.internalCompoundStructure.GetLayers()) { revitCSLayer destintationLayer = sourceLayer; revitDB.Material sourceMaterial = (revitDB.Material)doc.GetElement(sourceLayer.MaterialId); revitDB.Material destinationMaterial = Select.GetMaterialByName(Select.AllMaterials(destinationDoc), sourceMaterial.Name); if (destinationMaterial == null) { cg.List <int> sourceMaterialIds = new cg.List <int>(); sourceMaterialIds.Add(sourceMaterial.Id.IntegerValue); cg.List <revitDB.ElementId> destinationElemIds = Elements.CopyElements(compoundStructure.internalDocument, sourceMaterialIds, destinationDoc); //destinationMaterial = Select.GetMaterialByName(Select.AllMaterials(destinationDoc), sourceMaterial.Name); destintationLayer.MaterialId = destinationElemIds[0]; } else { destintationLayer.MaterialId = destinationMaterial.Id; } destinationLayers.Add(destintationLayer); } return(new CompoundStructure(destinationLayers, destinationDoc)); }
public void AddMaterial(Document inDocument, MaterialNode inNode) { if (!m_pMaterialDict.ContainsKey(inNode.MaterialId.IntegerValue)) { Autodesk.Revit.DB.Material _revitMat = inDocument.GetElement(inNode.MaterialId) as Autodesk.Revit.DB.Material; if (_revitMat != null && _revitMat.IsValidObject) { BoldarcManagedFbx.Material _mat = new BoldarcManagedFbx.Material(_revitMat.Name); _mat.Red = _revitMat.Color.Red; _mat.Green = _revitMat.Color.Green; _mat.Blue = _revitMat.Color.Blue; _mat.Shininess = _revitMat.Shininess; _mat.Smoothness = _revitMat.Smoothness; _mat.Transparency = _revitMat.Transparency; m_pMaterialDict.Add(inNode.MaterialId.IntegerValue, _mat); m_pCurrentMesh.MaterialIDPerFace.Add(m_pCurrentMesh.FaceCount, inNode.MaterialId.IntegerValue); } else { m_pCurrentMesh.MaterialIDPerFace.Add(m_pCurrentMesh.FaceCount, -1); } } else { m_pCurrentMesh.MaterialIDPerFace.Add(m_pCurrentMesh.FaceCount, inNode.MaterialId.IntegerValue); } }
private DiffuseMaterial getMaterial(Autodesk.Revit.DB.Material mat) { if (mat == null) { failedMatParse++; return(this.DefaultMaterial.CloneCurrentValue()); } System.Windows.Media.Brush brush = null; try { System.Windows.Media.Color clr = System.Windows.Media.Color.FromRgb( mat.Color.Red, mat.Color.Green, mat.Color.Blue); float r = 1 - ((float)mat.Transparency) / 100; clr.A = (byte)(r * 255); brush = new System.Windows.Media.SolidColorBrush(clr); } catch (Exception) { failedMatParse++; } if (brush != null) { return(new DiffuseMaterial(brush)); } failedMatParse++; return(this.DefaultMaterial.CloneCurrentValue()); }
public static Rhino.Display.DisplayMaterial ToRhino(this DB.Material material, Rhino.Display.DisplayMaterial parentMaterial) { return((material is null) ? parentMaterial ?? defaultMaterial : new Rhino.Display.DisplayMaterial() { Diffuse = material.Color.ToRhino(), Transparency = material.Transparency / 100.0, Shine = material.Shininess / 128.0 }); }
/// <summary> /// Update cache material /// </summary> /// <param name="obj">new material</param> public void UpdateMaterial(object obj) { if (null == obj) { throw new ArgumentNullException(); } { m_cacheMaterial = obj as Material; } }
static internal Rhino.Display.DisplayMaterial ToRhino(this Autodesk.Revit.DB.Material material, Rhino.Display.DisplayMaterial parentMaterial) { return((material == null) ? parentMaterial ?? defaultMaterial : new Rhino.Display.DisplayMaterial() { Diffuse = material.Color.ToRhino(), Transparency = material.Transparency / 100.0, Shine = material.Shininess / 128.0 }); }
/// <summary> /// Sets the properties of a layer at the specified index in the CompoundStructure. /// </summary> /// <param name="compoundStructure">The CompoundStructure to modify.</param> /// <param name="layerIndex">Index of the layer to be modified.</param> /// <param name="width">Width of the layer.</param> /// <param name="layerFunction">Autodesk.Revit.DB.MaterialFunctionAssignment enumeration of the layer.</param> /// <param name="material">Autodesk.Revit.DB.Materials of the layer. Dynamo wrapped Revit.Material objects will not work.</param> /// <returns name="compoundStructure">The modified CompoundStructure.</returns> public static CompoundStructure SetLayer(CompoundStructure compoundStructure, int layerIndex, double width, revitDB.MaterialFunctionAssignment layerFunction, revitDB.Material material) { CompoundStructure.SetLayerWidth(compoundStructure, layerIndex, width); CompoundStructure.SetLayerFunction(compoundStructure, layerIndex, layerFunction); CompoundStructure.SetLayerMaterial(compoundStructure, layerIndex, material); return(compoundStructure); }
public static DisplayMaterial ToDisplayMaterial(this DB.Material material, DisplayMaterial parentMaterial) { return((material is null) ? parentMaterial ?? DefaultMaterial : new DisplayMaterial() { Diffuse = material.Color.ToColor(), Transparency = material.Transparency / 100.0, Shine = material.Shininess / 128.0 }); }
internal Layer( string layerFunction, Autodesk.Revit.DB.Material layerMaterial, double layerThickness, bool isStructuralLayer, bool isCoreLayer) { this.Function = layerFunction; this.Material = layerMaterial; this.Width = layerThickness; this.IsStructural = isStructuralLayer; this.IsCore = isCoreLayer; }
public static revitMaterial ToMaterial(MaterialJSON MatJSON, revitDoc doc) { revitMaterial rMat = (revitMaterial)doc.GetElement(MatJSON.UniqueId); rMat.Name = MatJSON.Name; foreach (ParameterJSON paramJson in MatJSON.Parameters) { ParameterJSON.ModifyParameter(paramJson, rMat); } return(rMat); }
/// <summary> /// Returns the properties of a Autodesk.Revit.DB.CompoundStructureLayer as a dictionary. /// </summary> /// <param name="layer">Autodesk.Revit.DB.CompoundStructureLayer</param> /// <param name="doc">Autodesk.Revit.DB.Document</param> /// <returns></returns> internal static cg.Dictionary <string, object> _RevitLayerToDictionary(revitCSLayer layer, revitDoc doc) { double width = layer.Width; revitDB.MaterialFunctionAssignment layerFunction = layer.Function; revitDB.Material material = (revitDB.Material)doc.GetElement(layer.MaterialId); return(new cg.Dictionary <string, object> { { "Width", width }, { "Layer Function", layerFunction }, { "Material", material } }); }
/// <summary> /// for non deck layers this method is called and it displays minimal information /// about the layer /// </summary> /// <param name="layer"></param> private void DumpLayer(CompoundStructureLayer layer) { // Display the name of the material. More detailed material properties can // be found form the material object m_displayForm.WriteLine("Dumping Layer"); Autodesk.Revit.DB.Material material = m_document.GetElement(layer.MaterialId) as Material; if (material != null) { m_displayForm.WriteLine("Layer material = " + material.Name); } // display the thickness of the layer in inches. m_displayForm.WriteLine("Layer Thickness = " + layer.Width.ToString()); }
/// <summary> /// Creates a new layer at the specified index in the CompoundStructure. /// </summary> /// <param name="compoundStructure">The CompoundStructure to modify.</param> /// <param name="layerIndex">Index of the layer to be inserted.</param> /// <param name="width">Width of the layer.</param> /// <param name="layerFunction">Autodesk.Revit.DB.MaterialFunctionAssignment enumeration of the layer.</param> /// <param name="material">Autodesk.Revit.DB.Materials of the layer. Dynamo wrapped Revit.Material objects will not work.</param> /// <returns name="compoundStructure">The modified CompoundStructure.</returns> public static CompoundStructure InsertLayerAtIndex(CompoundStructure compoundStructure, int layerIndex, double width, revitDB.MaterialFunctionAssignment layerFunction, revitDB.Material material) { revitCSLayer layer = new revitCSLayer(width, layerFunction, material.Id); cg.IList <revitCSLayer> layers = compoundStructure.internalCompoundStructure.GetLayers(); layers.Insert(layerIndex, layer); compoundStructure.internalCompoundStructure.SetLayers(layers); return(compoundStructure); }
/// <summary> /// Creates a compound structure from a list of dictionary layer properties. /// </summary> /// <param name="layers">A list of dictionary objects with layer properties.</param> /// <param name="document">An unwrapped document associated with the CompoundStructure.</param> /// <returns name="compoundStructure">A Compound Structure.</returns> public static CompoundStructure ByLayerDictionary(cg.IList <cg.Dictionary <string, object> > layers, [DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc document) { cg.List <revitCSLayer> layerList = new cg.List <revitCSLayer>(); foreach (cg.Dictionary <string, object> layerDict in layers) { revitDB.Material material = (revitDB.Material)layerDict["Material"]; revitCSLayer layer = new revitCSLayer((double)layerDict["Width"], (revitDB.MaterialFunctionAssignment)layerDict["Layer Function"], material.Id); layerList.Add(layer); } //return new CompoundStructure(revitCS.CreateSimpleCompoundStructure(layerList), document); return(new CompoundStructure(layerList, document)); }
void SetCurrentMaterial(string uidMaterial) { if (!_materials.ContainsKey(uidMaterial)) { Autodesk.Revit.DB.Material material = doc.GetElement(uidMaterial) as Autodesk.Revit.DB.Material; //Revit material GLTFExporter.Material gMaterial = new GLTFExporter.Material(); //GLTF material //convert Revit material to GLTF material gMaterial.name = material.Name; //TODO: more property need to be obtain and convert to GLTF material _materials.Add(uidMaterial, gMaterial); } _currentMaterialUid = uidMaterial; string uid_per_material = _currentElement.name + "-" + uidMaterial; // }
public MaterialJSON(revitMaterial material) { this.Class = material.GetType().Name; this.Name = material.Name; this.Id = material.Id.IntegerValue; this.UniqueId = material.UniqueId.ToString(); this.Category = material.Category.Name; this.Parameters = new List <ParameterJSON>(); //Iterate through parameters foreach (Parameter param in material.Parameters) { //If the parameter has a value, the add it to the parameter list for export if (!param.IsReadOnly) { this.Parameters.Add(new ParameterJSON(param, material.Document)); } } }
/// <summary> /// Get Material Names from a Revit Element /// </summary> /// <param name="element">Revit Element</param> /// <param name="paintMaterials">Paint Materials</param> /// <returns>List of Names</returns> public static List <string> GetMaterialNames(Revit.Elements.Element element, bool paintMaterials = false) { // Get the active Document Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; List <string> materialnames = new List <string>(); foreach (Autodesk.Revit.DB.ElementId id in element.InternalElement.GetMaterialIds(paintMaterials)) { RVT.Material material = (RVT.Material)document.GetElement(id); if (!materialnames.Contains(material.Name)) { materialnames.Add(material.Name); } } return(materialnames); }
/// <summary> /// Get Material Names from a Revit Element /// </summary> /// <param name="paintMaterials">Paint Materials</param> /// <returns>List of Names</returns> public IEnumerable <Material> GetMaterials(bool paintMaterials = false) { // Get the active Document Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; List <Material> materialnames = new List <Material>(); foreach (Autodesk.Revit.DB.ElementId id in this.InternalElement.GetMaterialIds(paintMaterials)) { Autodesk.Revit.DB.Material material = (Autodesk.Revit.DB.Material)document.GetElement(id); Material mat = Material.FromExisting(material, true); if (!materialnames.Contains(mat)) { materialnames.Add(mat); } } return(materialnames); }
/// <summary> /// update display data to selected element's material /// </summary> private void LoadCurrentMaterial() { typeComboBox.DataSource = m_dataBuffer.MaterialTypes; typeComboBox.SelectedIndex = (int)m_dataBuffer.CurrentType; if (null == m_dataBuffer.CurrentMaterial || (m_dataBuffer.CurrentType != StructuralAssetClass.Metal && m_dataBuffer.CurrentType != StructuralAssetClass.Concrete)) { return; } Autodesk.Revit.DB.Material tmp = m_dataBuffer.CurrentMaterial as Autodesk.Revit.DB.Material; if (null == tmp) { return; } subTypeComboBox.SelectedValue = tmp; parameterDataGrid.DataSource = m_dataBuffer.GetParameterTable(subTypeComboBox.SelectedValue, (StructuralAssetClass)typeComboBox.SelectedIndex); }
public static IEnumerable <ElementId> CopyMaterials(this Document document, string path, IEnumerable <string> materialNames, CopyPasteOptions copyPasteOptions = null) { Func <Document, FilteredElementCollector> function = new Func <Document, FilteredElementCollector>((Document document_Temp) => { if (document_Temp == null) { return(null); } FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document_Temp).OfCategory(BuiltInCategory.OST_Materials); IEnumerable <Element> elements = filteredElementCollector.ToElements(); if (elements == null) { return(null); } List <ElementId> elementIds = new List <ElementId>(); foreach (Element element in elements) { Autodesk.Revit.DB.Material material = element as Autodesk.Revit.DB.Material; if (!materialNames.Contains(material.Name)) { continue; } elementIds.Add(element.Id); } if (elementIds == null || elementIds.Count == 0) { return(null); } return(new FilteredElementCollector(document_Temp, elementIds).OfCategory(BuiltInCategory.OST_Materials)); }); return(CopyElements(document, path, function, copyPasteOptions)); }
/// <summary> /// Converts the material to <see cref="MeshPhongMaterial"/> instance. /// </summary> /// <param name="material">The material.</param> /// <returns></returns> public static MeshPhongMaterial ToMeshPhong(this Material material) { if (material is null) { throw new System.ArgumentNullException(nameof(material)); } var materialColor = material.Color.ToInt(); var meshPhong = new MeshPhongMaterial(material.UniqueId) { Name = material.Name, Color = materialColor, Ambient = materialColor, Emissive = 0, Specular = materialColor, Shininess = 1, Opacity = (100D - material.Transparency) / 100, Transparent = material.Transparency > 0, Wireframe = false, }; return(meshPhong); }
public static List <Autodesk.Revit.DB.Material> Materials(this Element element, bool returnPaintMaterials) { IEnumerable <ElementId> elementIds = element?.GetMaterialIds(returnPaintMaterials); if (elementIds == null) { return(null); } Document document = element.Document; List <Autodesk.Revit.DB.Material> result = new List <Autodesk.Revit.DB.Material>(); foreach (ElementId elementId in elementIds) { Autodesk.Revit.DB.Material material = document.GetElement(elementId) as Autodesk.Revit.DB.Material; if (material != null) { result.Add(material); } } return(result); }