Example #1
0
        public static revitElem ModifyElement(ElementJSON JSON, revitDoc doc)
        {
            revitElem elem = (revitElem)doc.GetElement(JSON.UniqueId);

            elem.Name = JSON.Name;

            foreach (ParameterJSON paramJson in JSON.Parameters)
            {
                ParameterJSON.ModifyParameter(paramJson, elem);
            }

            return(elem);
        }
Example #2
0
        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);
        }
Example #3
0
        public static RevitElem ModifyParameter(ParameterJSON paramJSON, RevitElem Elem)
        {
            RevitParam param = null;

            if (paramJSON.IsShared)
            {
                param = Elem.get_Parameter(new Guid(paramJSON.GUID));
            }
            else if (paramJSON.Id < 0)
            {
                param = Elem.get_Parameter((BuiltInParameter)paramJSON.Id);
            }
            else if (paramJSON.Id > 0)
            {
                revitDoc         doc       = Elem.Document;
                ParameterElement paramElem = (ParameterElement)doc.GetElement(new ElementId(paramJSON.Id));
                if (paramElem != null)
                {
                    Definition def = paramElem.GetDefinition();
                    param = Elem.get_Parameter(def);
                }
            }

            if (param != null && !param.IsReadOnly)
            {
                switch (paramJSON.StorageType)
                {
                case "Double":
                    param.Set(Convert.ToDouble(paramJSON.Value));
                    break;

                case "ElementId":
                    param.Set(new ElementId(Convert.ToInt32(paramJSON.Value)));
                    break;

                case "Integer":
                    param.Set(Convert.ToInt32(paramJSON.Value));
                    break;

                case "String":
                default:
                    param.Set(paramJSON.Value);
                    break;
                }
            }

            return(Elem);
        }
Example #4
0
 public static string ToJSON(ParameterJSON parameter)
 {
     return(Newtonsoft.Json.JsonConvert.SerializeObject(parameter, Formatting.Indented));
 }