public void SaveTemplateSheet(Document doc, CegParameterSet cegParameterSet, string filename, SettingSetValueSheet setting) { string path = setting.GetFullFileName(filename); string contents = JsonConvert.SerializeObject(cegParameterSet, Formatting.Indented); File.WriteAllText(path, contents); }
private void Load() { DirectoryInfo d = new DirectoryInfo(_data.Setting.GetFolderPath()); var p = d.GetFiles().ToList(); string filename = lb_view.SelectedItem.ToString(); string pathfile = ""; foreach (var item in p) { if (item.Name.Replace(".json", "") == filename) { pathfile = item.FullName; break; } } var json = File.ReadAllText(pathfile); CegParameterSet dictemp = JsonConvert.DeserializeObject <CegParameterSet>(json); a.ViewSheet viewSheet = _doc.ActiveView as a.ViewSheet; using (a.Transaction tran = new a.Transaction(_doc, "Set Parameter Sheet")) { tran.Start(); foreach (var item in dictemp.Parameters) { foreach (var item2 in _data.dic.Parameters) { if (item.Value.Name == item2.Value.Name) { a.Parameter pa = viewSheet.LookupParameter(item2.Value.Name); if (pa != null) { a.InternalDefinition definition = pa.Definition as a.InternalDefinition; if (definition.BuiltInParameter != a.BuiltInParameter.SHEET_NAME && definition.BuiltInParameter != a.BuiltInParameter.SHEET_NUMBER) { switch (item2.Value.Type) { case a.StorageType.Double: pa.Set(item.Value.AsDouble); break; case a.StorageType.String: pa.Set(item.Value.AsString); break; case a.StorageType.Integer: pa.Set(item.Value.AsInteger); break; default: break; } } } } } } tran.Commit(); } Close(); }
//lay parameter va value public CegParameterSet GetParameter(Document doc, FamilyInstance Titleblock) { CegParameterSet cegParameterSet = new CegParameterSet(); if (doc.ActiveView.IsViewSheet()) { ViewSheet viewSheet = doc.ActiveView as ViewSheet; string sheetName = GetSheetName(viewSheet); foreach (object obj in viewSheet.Parameters) { Parameter parameter = (Parameter)obj; bool isReadOnly = parameter.IsReadOnly; if (!isReadOnly) { string name = parameter.Definition.Name; CegParameterInfo value = new CegParameterInfo(parameter); cegParameterSet.Parameters[name] = value; } } } return(cegParameterSet); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication application = commandData.Application; UIDocument activeUIDocument = application.ActiveUIDocument; Application application2 = application.Application; Document doc = activeUIDocument.Document; Selection sel = activeUIDocument.Selection; if (doc.ActiveView.ViewType == ViewType.DrawingSheet) { Setting = SettingSetValueSheet.Instance.GetSetting(""); FamilyInstance Titleblockc = SetValueTemplateSheet.Instance.Gettileblock(doc); dic = SetValueTemplateSheet.Instance.GetParameter(doc, Titleblockc); var form = new FrmSetValueTemplateSheet(this, doc); form.ShowDialog(); return(Result.Succeeded); } else { TaskDialog.Show("Error", "Please go to Sheet"); return(Result.Cancelled); } }