public static void ExportParameters(Document doc, string path) { DefinitionFile existingDefFile = doc.Application.OpenSharedParameterFile(); // doc.Application.SharedParametersFilename = path; DefinitionFile tempDefFile = doc.Application.OpenSharedParameterFile(); // Manager the Exported group DefinitionGroup exported = null; var query = from dg in tempDefFile.Groups where dg.Name.Equals(doc.PathName + "-Exported") select dg; if (query.Count() == 0) { exported = tempDefFile.Groups.Create(doc.PathName + "-Exported"); } else { exported = query.First(); } // Iterate over the shared parameters in the document BindingMap bindingMap = doc.ParameterBindings; DefinitionBindingMapIterator it = bindingMap.ForwardIterator(); it.Reset(); while (it.MoveNext()) { InternalDefinition definition = it.Key as InternalDefinition; Autodesk.Revit.DB.Binding currBinding = bindingMap.get_Item(definition); // Corroborate that the current parameter has not been exported previously Definition existingDef = exported.Definitions .Where(d => (d.Name.Equals(definition.Name))).FirstOrDefault(); if (existingDef != null) { continue; } // unearth and assign the parameter's GUID SharedParameterElement sharedParamElem = doc.GetElement(definition.Id) as SharedParameterElement; if (sharedParamElem == null) { continue; } ExternalDefinitionCreationOptions options = new ExternalDefinitionCreationOptions(definition.Name, definition.ParameterType); options.GUID = sharedParamElem.GuidValue; Definition createdDefinition = exported.Definitions.Create(options); } }
public static IList <SharedParameter> GetSharedParameters(Document doc) { IList <SharedParameter> extSharedParams = new List <SharedParameter>(); BindingMap bindingMap = doc.ParameterBindings; DefinitionBindingMapIterator it = bindingMap.ForwardIterator(); it.Reset(); while (it.MoveNext()) { InternalDefinition definition = it.Key as InternalDefinition; Autodesk.Revit.DB.Binding currBinding = bindingMap.get_Item(definition); // unearth the parameter's GUID SharedParameterElement sharedParamElem = doc.GetElement(definition.Id) as SharedParameterElement; if (sharedParamElem == null) { continue; } SharedParameter sharedParam = new SharedParameter(definition.Name, definition.ParameterType, sharedParamElem.GuidValue, currBinding, definition.ParameterGroup); extSharedParams.Add(sharedParam); } return(extSharedParams); }
private void AddObjectsToTree(BindingMap map, TreeNodeCollection nodeCollection) { var iterator = map.ForwardIterator(); while (iterator.MoveNext()) { var definition = iterator.Key; var node = new TreeNode(definition.Name) { Tag = iterator.Current }; nodeCollection.Add(node); if (iterator.Current is not ElementBinding elementBinding) { continue; } var categories = elementBinding.Categories; foreach (Category category in categories) { var treeNode = new TreeNode(category.Name) { Tag = category }; node.Nodes.Add(treeNode); } } }
public BindingMapView(BindingMap map) { Text = "Snoop Binding Map"; TvObjs.BeginUpdate(); AddObjectsToTree(map, TvObjs.Nodes); TvObjs.EndUpdate(); }
/// <summary> /// Returns a list of the objects containing /// references to the project parameter definitions /// </summary> /// <param name="doc">The project document being quereied</param> /// <returns></returns> static List <ProjectParameterData> GetProjectParameterData(Document doc) { // Following good SOA practices, first validate incoming parameters if (doc == null) { throw new ArgumentNullException("doc"); } if (doc.IsFamilyDocument) { throw new Exception("doc can not be a family document."); } List <ProjectParameterData> result = new List <ProjectParameterData>(); BindingMap map = doc.ParameterBindings; DefinitionBindingMapIterator it = map.ForwardIterator(); it.Reset(); while (it.MoveNext()) { ProjectParameterData newProjectParameterData = new ProjectParameterData(); newProjectParameterData.Definition = it.Key; newProjectParameterData.Name = it.Key.Name; newProjectParameterData.Binding = it.Current as ElementBinding; result.Add(newProjectParameterData); } return(result); }
public static void sharedParameterEkle(RevitApplication app, string name, CategorySet cats, BuiltInParameterGroup group, bool inst) { DefinitionFile defFile = app.OpenSharedParameterFile(); if (defFile == null) { throw new Exception("No SharedParameter File!"); } var v = (from DefinitionGroup dg in defFile.Groups from ExternalDefinition d in dg.Definitions where d.Name == name select d); if (v == null || v.Count() < 1) { throw new Exception("Invalid Name Input!"); } ExternalDefinition def = v.First(); Autodesk.Revit.DB.Binding binding = app.Create.NewTypeBinding(cats); if (inst) { binding = app.Create.NewInstanceBinding(cats); } BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings; map.Insert(def, binding, group); }
public List <bool> SetNewParametersToInstances() { List <bool> instanceBindingOK = new List <bool>(); if (SharedParameterFile != null && ActiveDefinitions != null) { CategorySet myCategories = App.Create.NewCategorySet(); Category myCategory = UIApp.ActiveUIDocument.Document.Settings.Categories.get_Item(ActiveBuiltInCategory); myCategories.Insert(myCategory); InstanceBinding instanceBinding = App.Create.NewInstanceBinding(myCategories); BindingMap bindingMap = UIApp.ActiveUIDocument.Document.ParameterBindings; foreach (Definition definition in ActiveDefinitions) { bool IsOk = bindingMap.Insert(definition, instanceBinding, BuiltInParameterGroup.PG_TEXT); instanceBindingOK.Add(IsOk); } UIApp.ActiveUIDocument.SaveAs(); } else { instanceBindingOK.Add(false); } return(instanceBindingOK); }
} //end fun //這個方法也是被公開在官網上的,我只是小小修改並且翻譯了註解,參考以下網址 //http://www.revitapidocs.com/2017/f5066ef5-fa12-4cd2-ad0c-ca72ab21e479.htm private void AddNewParametersToCategories(UIApplication app, DefinitionFile myDefinitionFile, BuiltInCategory category, List <string> newParameters) { //在共用參數檔案當中先建立一個新的參數群組 DefinitionGroups myGroups = myDefinitionFile.Groups; DefinitionGroup myGroup = myGroups.Create("使用者定義參數群組"); // 創立參數定義,含參數名稱及參數型別 foreach (string paraName in newParameters) { ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions(paraName, ParameterType.Text); Definition myDefinition = myGroup.Definitions.Create(option); // 創建一個類別群組,將來在這個類別群組裡的所有類別都會被新增指定的參數 CategorySet myCategories = app.Application.Create.NewCategorySet(); // 創建一個類別.以牆為例 Category myCategory = Category.GetCategory(app.ActiveUIDocument.Document, category); myCategories.Insert(myCategory);//把牆類別插入類別群組,當然你可以插入不只一個類別 //以下兩者是亮點,「類別綁定」與「實體綁定」的結果不同,以本例而言我們需要的其實是實體綁定 //TypeBinding typeBinding = app.Application.Create.NewTypeBinding(myCategories); InstanceBinding instanceBinding = app.Application.Create.NewInstanceBinding(myCategories); //取得一個叫作BingdingMap的物件,以進行後續新增參數 BindingMap bindingMap = app.ActiveUIDocument.Document.ParameterBindings; // 最後將新增參數加到群組上頭,並且指定了instanceBiding的方法(也可替換為typeBinding) bool typeBindOK = bindingMap.Insert(myDefinition, instanceBinding, BuiltInParameterGroup.PG_TEXT); } }
// 定義參數與綁定類型的Function private bool setNewParameterToTypeWall(UIApplication app, DefinitionFile myDefinitionFile) { // 共用參數文檔中包含了Group,代表參數所屬的群組, // 而Group內又包含了Definition,也就是你想增加的參數, // 欲新增Definition首先必須新增一個Group DefinitionGroups myGroups = myDefinitionFile.Groups; DefinitionGroup myGroup = myGroups.Create("參數群組"); // 創建Definition的定義以及其儲存類型 ExternalDefinitionCreationOptions options = new ExternalDefinitionCreationOptions("聯絡人", ParameterType.Text); Definition myDefinition = myGroup.Definitions.Create(options); // 創建品類集並插入牆品類到裡面 CategorySet myCategories = app.Application.Create.NewCategorySet(); // 使用BuiltInCategory來取得牆品類 Category myCategory = app.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Walls); myCategories.Insert(myCategory); // 根據品類創建類型綁定的物件 TypeBinding typeBinding = app.Application.Create.NewTypeBinding(myCategories); // 取得當前文件中所有的類型綁定 BindingMap bindingMap = app.ActiveUIDocument.Document.ParameterBindings; // 將客製化的參數定義綁定到文件中 bool typeBindOK = bindingMap.Insert(myDefinition, typeBinding, BuiltInParameterGroup.PG_TEXT); return(typeBindOK); }
public static bool CreateSharedProjectParameters(Document doc, string param, CategorySet catSet) { DefinitionFile sharedParamsFile = GetSharedParamsFile(doc); if (null == sharedParamsFile) { throw new Exception("Shared Paremeter file does not exist.\nSet or Create the project Shared Parameter file."); } DefinitionGroup sharedParamsGroup = GetCreateSharedParamsGroup(sharedParamsFile, "Group6Face"); Definition definition = GetCreateSharedParamsDefinition(sharedParamsGroup, ParameterType.Text, param, true); BindingMap bindMap = doc.ParameterBindings; Autodesk.Revit.DB.Binding binding = bindMap.get_Item(definition); bindMap.ReInsert(definition, binding); InstanceBinding instanceBinding = doc.Application.Create.NewInstanceBinding(catSet); try { if (!doc.ParameterBindings.Insert(definition, instanceBinding)) { doc.ParameterBindings.ReInsert(definition, instanceBinding); } return(true); } catch (Exception ex) { throw new Exception("Uneable to create parameter bindings.\n" + ex.Message); } }
public void CanUseBaseRoute() { var balancer = new RoundRobinBalancer <Uri>(); balancer.Resources.Add(new Uri("https://127.0.0.1/api/round-robin")); balancer.Resources.Add(new Uri("http://[::1]/round-robin")); balancer.Resources.Add(new Uri("https://www.google.com/api/foo/bar/baz")); var bindingMap = new BindingMap { { "round-robin", balancer } }; var startUri = new Uri("http://round-robin/more-complex/query?foo=bar&baz=1"); bindingMap.TryRebindUri(startUri, out var newUri).Should().BeTrue(); newUri.Should() .BeEquivalentTo(new Uri("https://127.0.0.1/api/round-robin/more-complex/query?foo=bar&baz=1")); bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue(); newUri.Should().BeEquivalentTo(new Uri("http://[::1]/round-robin/more-complex/query?foo=bar&baz=1")); bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue(); newUri.Should() .BeEquivalentTo(new Uri("https://www.google.com/api/foo/bar/baz/more-complex/query?foo=bar&baz=1")); bindingMap.TryRebindUri(startUri, out newUri).Should().BeTrue(); newUri.Should() .BeEquivalentTo(new Uri("https://127.0.0.1/api/round-robin/more-complex/query?foo=bar&baz=1")); }
private void TransactionCommit(Document doc, ExternalDefinition def, Autodesk.Revit.DB.Binding binding, BuiltInParameterGroup group) { using (Transaction transNew = new Transaction(doc, "Create project parameter")) { try { transNew.Start(); BindingMap map = doc.ParameterBindings; if (SelectParameters.OverwriteParam == true) { map.ReInsert(def, binding, group); } map.Insert(def, binding, group); } catch (Exception e) { transNew.RollBack(); MessageBox.Show(e.ToString()); } transNew.Commit(); } }
private static BindingMap CreateBingingMap(Type type) { var map = new BindingMap(); var properties = type.GetProperties(); foreach (var prop in properties) { var attr = (DeserializeAsAttribute)prop.GetCustomAttribute( typeof(DeserializeAsAttribute)); if (attr != null) { if (string.IsNullOrEmpty(attr.Name)) { var error = string.Format( "Attribute DeserializeAs Name is empty for type '{0}', property {1}", type.FullName, prop.Name); throw new InvalidOperationException(error); } map.Add(attr.Name.ToUpper(), prop); } } return(map); }
/// <summary> /// Has the specific document shared parameter already been added ago? /// </summary> /// <param name="doc">Revit project in which the shared parameter will be added.</param> /// <param name="paraName">the name of the shared parameter.</param> /// <param name="boundCategory">Which category the parameter will bind to</param> /// <returns>Returns true if already added ago else returns false.</returns> private static bool AlreadyAddedSharedParameter(Document doc, string paraName, BuiltInCategory boundCategory) { try { BindingMap bindingMap = doc.ParameterBindings; DefinitionBindingMapIterator bindingMapIter = bindingMap.ForwardIterator(); while (bindingMapIter.MoveNext()) { if (bindingMapIter.Key.Name.Equals(paraName)) { ElementBinding binding = bindingMapIter.Current as ElementBinding; CategorySet categories = binding.Categories; foreach (Category category in categories) { if (category.Id.IntegerValue.Equals((int)boundCategory)) { return(true); } } } } } catch (Exception) { return(false); } return(false); }
//這個方法也是被公開在官網上的,我只是小小修改並且翻譯了註解,參考以下網址 //http://www.revitapidocs.com/2017/f5066ef5-fa12-4cd2-ad0c-ca72ab21e479.htm public bool SetNewParameterToTypeWall(UIApplication app, DefinitionFile myDefinitionFile) { //在共用參數檔案當中先建立一個新的參數群組 DefinitionGroups myGroups = myDefinitionFile.Groups; DefinitionGroup myGroup = myGroups.Create("新參數群組"); // 創立參數定義,含參數名稱及參數型別 ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions("牆上塗鴉", ParameterType.Text); Definition myDefinition_CompanyName = myGroup.Definitions.Create(option); // 創建一個類別群組,將來在這個類別群組裡的所有類別都會被新增指定的參數 CategorySet myCategories = app.Application.Create.NewCategorySet(); // 創建一個類別.以牆為例 Category myCategory = Category.GetCategory(app.ActiveUIDocument.Document, BuiltInCategory.OST_Walls); myCategories.Insert(myCategory);//把牆類別插入類別群組,當然你可以插入不只一個類別 //以下兩者是亮點,「類別綁定」與「實體綁定」的結果不同,以本例而言我們需要的其實是實體綁定 //TypeBinding typeBinding = app.Application.Create.NewTypeBinding(myCategories); InstanceBinding instanceBinding = app.Application.Create.NewInstanceBinding(myCategories); //取得一個叫作BingdingMap的物件,以進行後續新增參數 BindingMap bindingMap = app.ActiveUIDocument.Document.ParameterBindings; // 最後將新增參數加到群組上頭,並且指定了instanceBiding的方法(也可替換為typeBinding) bool typeBindOK = bindingMap.Insert(myDefinition_CompanyName, instanceBinding, BuiltInParameterGroup.PG_TEXT); //bool typeBindOK=bindingMap.Insert(myDefinition_CompanyName, typeBinding, //BuiltInParameterGroup.PG_TEXT); return(typeBindOK); }
/// <summary> /// Create a project parameter /// </summary> /// <param name="app"></param> /// <param name="name"></param> /// <param name="type"></param> /// <param name="visible"></param> /// <param name="cats"></param> /// <param name="group"></param> /// <param name="inst"></param> public static void RawCreateProjectParameter(Autodesk.Revit.ApplicationServices.Application app, string name, ParameterType type, bool visible, CategorySet cats, BuiltInParameterGroup group, bool inst) { string oriFile = app.SharedParametersFilename; string tempFile = Path.GetTempFileName() + ".txt"; using (File.Create(tempFile)) { } app.SharedParametersFilename = tempFile; ExternalDefinitionCreationOptions externalDefinitionCreationOptions = new ExternalDefinitionCreationOptions(name, type); ExternalDefinition def = app.OpenSharedParameterFile().Groups.Create("TemporaryDefintionGroup").Definitions.Create(externalDefinitionCreationOptions) as ExternalDefinition; app.SharedParametersFilename = oriFile; File.Delete(tempFile); Autodesk.Revit.DB.Binding binding = app.Create.NewTypeBinding(cats); if (inst) { binding = app.Create.NewInstanceBinding(cats); } BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings; map.Insert(def, binding, group); }
/// <summary> ///This method is provided by the official website, here is the link ///https://www.revitapidocs.com/2019/f5066ef5-fa12-4cd2-ad0c-ca72ab21e479.htm /// </summary> /// <param name="app"></param> /// <param name="myDefinitionFile"></param> /// <returns></returns> public bool SetNewParameterToTypeWall(UIApplication app, DefinitionFile myDefinitionFile) { // Create a new group in the shared parameters file DefinitionGroups myGroups = myDefinitionFile.Groups; DefinitionGroup myGroup = myGroups.Create("Revit API Course"); // Create a type definition ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions("Note", ParameterType.Text); Definition myDefinition_CompanyName = myGroup.Definitions.Create(option); // Create a category set and insert category of wall to it CategorySet myCategories = app.Application.Create.NewCategorySet(); // Use BuiltInCategory to get category of wall Category myCategory = Category.GetCategory(app.ActiveUIDocument.Document, BuiltInCategory.OST_Walls); myCategories.Insert(myCategory);//add wall into the group. Of course, you can add multiple categories //Create an object of InstanceBinding according to the Categories, //The next line: I also provide the TypeBinding example here, but hide the code by comments //TypeBinding typeBinding = app.Application.Create.NewTypeBinding(myCategories); InstanceBinding instanceBinding = app.Application.Create.NewInstanceBinding(myCategories); // Get the BingdingMap of current document. BindingMap bindingMap = app.ActiveUIDocument.Document.ParameterBindings; //Bind the definitions to the document bool typeBindOK = bindingMap.Insert(myDefinition_CompanyName, instanceBinding, BuiltInParameterGroup.PG_TEXT); //The next two lines: I also provide the TypeBinding example here, but hide the code by comments //bool typeBindOK=bindingMap.Insert(myDefinition_CompanyName, typeBinding, //BuiltInParameterGroup.PG_TEXT); return(typeBindOK); }
/// <summary> /// Checks if a parameter exists based of a name /// </summary> /// <param name="doc"></param> /// <param name="paramName"></param> /// <returns></returns> private bool ShareParameterExists(Document doc, String paramName) { BindingMap bindingMap = doc.ParameterBindings; DefinitionBindingMapIterator iter = bindingMap.ForwardIterator(); iter.Reset(); while (iter.MoveNext()) { Definition tempDefinition = iter.Key; // find the definition of which the name is the appointed one if (String.Compare(tempDefinition.Name, paramName) != 0) { continue; } // get the category which is bound ElementBinding binding = bindingMap.get_Item(tempDefinition) as ElementBinding; CategorySet bindCategories = binding.Categories; foreach (Category category in bindCategories) { if (category.Name == doc.Settings.Categories.get_Item(BuiltInCategory.OST_Rebar).Name) { return(true); } } } return(false); }
/// <summary> /// Test if the Room binds a specified shared parameter /// </summary> /// <param name="paramName">Parameter name to be checked</param> /// <returns>true, the definition exists, false, doesn't exist.</returns> private bool ShareParameterExists(String paramName) { BindingMap bindingMap = m_document.ParameterBindings; DefinitionBindingMapIterator iter = bindingMap.ForwardIterator(); iter.Reset(); while (iter.MoveNext()) { Definition tempDefinition = iter.Key; // find the definition of which the name is the appointed one if (String.Compare(tempDefinition.Name, paramName) != 0) { continue; } // get the category which is bound ElementBinding binding = bindingMap.get_Item(tempDefinition) as ElementBinding; CategorySet bindCategories = binding.Categories; foreach (Category category in bindCategories) { if (category.Name == m_document.Settings.Categories.get_Item(BuiltInCategory.OST_Rooms).Name) { // the definition with appointed name was bound to Rooms, return true return(true); } } } // // return false if shared parameter doesn't exist return(false); }
//Method deletes parameters public void RemoveSharedParameterBinding(Application app, string name, ParameterType type) { BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings; DefinitionBindingMapIterator it = map.ForwardIterator(); it.Reset(); Definition def = null; while (it.MoveNext()) { if (it.Key != null && it.Key.Name == name && type == it.Key.ParameterType) { def = it.Key; break; } } if (def == null) { sbFeedback.Append("Parameter " + name + " does not exist.\n"); } else { map.Remove(def); if (map.Contains(def)) { sbFeedback.Append("Failed to delete parameter " + name + " for some reason.\n"); } else { sbFeedback.Append("Parameter " + name + " deleted.\n"); } } }
private void AddSharedParameters(Application app, Document doc) { //Save the previous shared param file path string previousSharedParam = app.SharedParametersFilename; //Extract shared param to a txt file string tempPath = System.IO.Path.GetTempPath(); string SPPath = Path.Combine(tempPath, "bimsyncSharedParameter.txt"); if (!File.Exists(SPPath)) { //extract the familly List <string> files = new List <string>(); files.Add("bimsyncSharedParameter.txt"); Services.ExtractEmbeddedResource(tempPath, "bimsync.Resources", files); } //set the shared param file app.SharedParametersFilename = SPPath; //Define a category set containing the project properties CategorySet myCategorySet = app.Create.NewCategorySet(); Categories categories = doc.Settings.Categories; Category projectCategory = categories.get_Item(BuiltInCategory.OST_ProjectInformation); myCategorySet.Insert(projectCategory); //Retrive shared parameters DefinitionFile myDefinitionFile = app.OpenSharedParameterFile(); DefinitionGroup definitionGroup = myDefinitionFile.Groups.get_Item("bimsync"); foreach (Definition paramDef in definitionGroup.Definitions) { // Get the BingdingMap of current document. BindingMap bindingMap = doc.ParameterBindings; //the parameter does not exist if (!bindingMap.Contains(paramDef)) { //Create an instance of InstanceBinding InstanceBinding instanceBinding = app.Create.NewInstanceBinding(myCategorySet); bindingMap.Insert(paramDef, instanceBinding, BuiltInParameterGroup.PG_IDENTITY_DATA); } //the parameter is not added to the correct categories else if (bindingMap.Contains(paramDef)) { InstanceBinding currentBinding = bindingMap.get_Item(paramDef) as InstanceBinding; currentBinding.Categories = myCategorySet; bindingMap.ReInsert(paramDef, currentBinding, BuiltInParameterGroup.PG_IDENTITY_DATA); } } //Reset to the previous shared parameters text file app.SharedParametersFilename = previousSharedParam; File.Delete(SPPath); }
public void WillIgnoreUrisNotConfigured() { var bindingMap = new BindingMap(); var startUri = new Uri("http://test/resource"); bindingMap.TryRebindUri(startUri, out var newUri).Should().BeFalse(); newUri.Should().BeEquivalentTo(startUri); }
public void UriIsRequired() { var bindingMap = new BindingMap(); Action action = () => bindingMap.TryRebindUri(null, out _); action.Should() .Throw <ArgumentNullException>() .WithMessage("Value cannot be null.\nParameter name: *"); }
public IDisposable Attach(TContext context) { var map = new BindingMap <TContext>(_actions); map.SetContext(context); var watcher = _rootNode.CreateWatcher(map); watcher.Attach(context); return(watcher); }
private Dictionary <string, Dictionary <string, ParameterProperties> > GetProjectParameters() { Dictionary <string, Dictionary <string, ParameterProperties> > paramDictionary = new Dictionary <string, Dictionary <string, ParameterProperties> >(); try { BindingMap bindingMap = m_doc.ParameterBindings; DefinitionBindingMapIterator iterator = bindingMap.ForwardIterator(); while (iterator.MoveNext()) { Definition definition = iterator.Key as Definition; string paramName = definition.Name; ElementBinding binding = iterator.Current as ElementBinding; ParameterProperties pp = new ParameterProperties(); pp.ParameterName = paramName; if (binding is InstanceBinding) { pp.IsInstance = true; } else if (binding is TypeBinding) { pp.IsInstance = false; } foreach (Category category in binding.Categories) { if (!string.IsNullOrEmpty(category.Name)) { if (!paramDictionary.ContainsKey(category.Name)) { Dictionary <string, ParameterProperties> dictionary = new Dictionary <string, ParameterProperties>(); dictionary.Add(pp.ParameterName, pp); paramDictionary.Add(category.Name, dictionary); } else { if (!paramDictionary[category.Name].ContainsKey(pp.ParameterName)) { paramDictionary[category.Name].Add(pp.ParameterName, pp); } } } } } } catch (Exception ex) { MessageBox.Show("Failed to get project parameters\n" + ex.Message, "Get Project Parameters", MessageBoxButton.OK, MessageBoxImage.Warning); } return(paramDictionary); }
static public bool IsParameterInProject(Document doc, string parameterName, BuiltInCategory cat) { Category category = doc.Settings.Categories.get_Item(cat); BindingMap map = doc.ParameterBindings; DefinitionBindingMapIterator it = map.ForwardIterator(); bool result = false; it.Reset(); while (it.MoveNext()) { result = result || (it.Key.Name == parameterName && (it.Current as ElementBinding).Categories.Contains(category)); } return(result); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; BindingMap bindings = doc.ParameterBindings; int n = bindings.Size; Debug.Print("{0} shared parementer{1} defined{2}", n, Util.PluralSuffix(n), Util.DotOrColon(n)); if (0 < n) { DefinitionBindingMapIterator it = bindings.ForwardIterator(); while (it.MoveNext()) { Definition d = it.Key as Definition; Binding b = it.Current as Binding; Debug.Assert(b is ElementBinding, "all Binding instances are ElementBinding instances"); Debug.Assert(b is InstanceBinding || b is TypeBinding, "all bindings are either instance or type"); // All definitions obtained in this manner // are InternalDefinition instances, even // if they are actually associated with // shared parameters, i.e. external. Debug.Assert(d is InternalDefinition, "all definitions obtained from BindingMap are internal"); string sbinding = (b is InstanceBinding) ? "instance" : "type"; Debug.Print("{0}: {1}", d.Name, sbinding); } } return(Result.Succeeded); }
public void WillReplaceHostNameWhenConfigured() { var balancer = new RandomLoadBalancer <Uri>(); balancer.Resources.Add(new Uri("https://127.0.0.1")); var bindingMap = new BindingMap { { "test", balancer } }; var startUri = new Uri("http://test/resource"); bindingMap.TryRebindUri(startUri, out var newUri).Should().BeTrue(); newUri.Should().BeEquivalentTo(new Uri("https://127.0.0.1/resource")); }
/// <summary> /// Add Shared GID Parameter to active Document /// </summary> /// <param name="document"></param> /// <returns>returns if operation succeeded</returns> public static bool GrevitAddSharedParameter(this Document document) { try { string parameterName = "GID"; ParameterType parameterType = ParameterType.Text; string sharedParameterFile = document.Application.SharedParametersFilename; string tempSharedParameterFile = System.IO.Path.GetTempFileName() + ".txt"; using (System.IO.File.Create(tempSharedParameterFile)) { } document.Application.SharedParametersFilename = tempSharedParameterFile; // Create a new Category Set to apply the parameter to CategorySet categories = document.Application.Create.NewCategorySet(); // Walk thru all categories and add them if they allow bound parameters foreach (Category cat in document.Settings.Categories) { if (cat.AllowsBoundParameters) { categories.Insert(cat); } } // Create and External Definition in a Group called Grevit and a Parameter called GID #if (!Revit2015) ExternalDefinition def = document.Application.OpenSharedParameterFile().Groups.Create("Grevit").Definitions.Create(new ExternalDefinitionCreationOptions(parameterName, parameterType)) as ExternalDefinition; #else ExternalDefinition def = document.Application.OpenSharedParameterFile().Groups.Create("Grevit").Definitions.Create(new ExternalDefinitonCreationOptions(parameterName, parameterType)) as ExternalDefinition; #endif document.Application.SharedParametersFilename = sharedParameterFile; System.IO.File.Delete(tempSharedParameterFile); // Apply the Binding to almost all Categories Autodesk.Revit.DB.Binding bin = document.Application.Create.NewInstanceBinding(categories); BindingMap map = (new UIApplication(document.Application)).ActiveUIDocument.Document.ParameterBindings; map.Insert(def, bin, BuiltInParameterGroup.PG_DATA); return(true); } catch (Exception e) { return(false); } }
//Shared Parameters //----------------- public static bool CheckCreateProjectParameter(Document doc, string param, BuiltInCategory bicCheck) { try { BindingMap map = doc.ParameterBindings; DefinitionBindingMapIterator it = map.ForwardIterator(); it.Reset(); Category cat = Category.GetCategory(doc, bicCheck); CategorySet catSet = new CategorySet(); catSet.Insert(Category.GetCategory(doc, bicCheck)); ElementBinding eb = null; while (it.MoveNext()) { if (param == it.Key.Name) { eb = it.Current as ElementBinding; if (eb.Categories.Contains(cat)) { return(true); } } } Transaction trans = new Transaction(doc); try { trans.Start("Project Parameters"); CreateSharedProjectParameters(doc, param, catSet); trans.Commit(); return(true); } catch (Exception ex) { trans.RollBack(); throw new Exception("Exception in Create Shared Parameters" + ex.Message); } } catch (Exception ex) { throw new Exception("Exception in Check Project Parameter.\n" + ex); } }
private static void TestMatch(ParserMatchExpectedValue expectedValue, BindingMap bindingMap) { expectedValue.MatchPathNamespace = expectedValue.MatchPathHasNamespace ? expectedValue.MatchPathNamespace : String.Empty; expectedValue.BindingPathRootDepth = expectedValue.BindingPathIsRelative ? expectedValue.BindingPathRootDepth : 0; expectedValue.BindingPathNamespace = expectedValue.BindingPathHasNamespace ? expectedValue.BindingPathNamespace : String.Empty; Assert.AreEqual(expectedValue.MatchPathIsWildCard, bindingMap.MatchPath.IsWildcard); Assert.AreEqual(expectedValue.MatchPathHasNamespace, bindingMap.MatchPath.HasNamespace); Assert.AreEqual(expectedValue.MatchPathNamespace, bindingMap.MatchPath.Namespace); Assert.AreEqual(expectedValue.BindingPathIsRelative, bindingMap.BindingPath.IsRelative); Assert.AreEqual(expectedValue.BindingPathRootDepth, bindingMap.BindingPath.RootDepth); Assert.AreEqual(expectedValue.BindingPathHasNamespace, bindingMap.BindingPath.HasNamespace); Assert.AreEqual(expectedValue.BindingPathNamespace, bindingMap.BindingPath.Namespace); Assert.AreEqual(expectedValue.ExpectedStringValue, bindingMap.Value); }
private static BindingMap ParseMap(StringScan scan) { var state = MapState.Begin; var map = new BindingMap(); var current = StringScan.EOF; //Parsing State Machine switch (state) { case MapState.Begin: current = scan.SkipWhitespace(); if (current == '*') goto case MapState.WildCardMatch; if (char.IsLetter(current) || current == '_') goto case MapState.AmbiguousNamespace; if (current == '~') { map.MatchPath.IsWildcard = true; goto case MapState.RelativeBinding; } if (current == '-') { map.MatchPath.IsWildcard = true; goto case MapState.RelativeRootBinding; } throw scan.CreateException(); case MapState.WildCardMatch: map.MatchPath.IsWildcard = true; current = scan.MoveNext(); if (current == '.') { scan.MoveNext(); goto case MapState.MatchNamespace; } if (char.IsWhiteSpace(current)) { current = scan.SkipWhitespace(); if (current == '=') goto case MapState.MapOp; throw scan.CreateException(); } if (current == '=') goto case MapState.MapOp; throw scan.CreateException(); case MapState.AmbiguousNamespace: string nsp = ScanNamespace(scan); current = scan.Current(); if (char.IsWhiteSpace(current)) { current = scan.SkipWhitespace(); if (current == '=') { map.MatchPath.Namespace = nsp; goto case MapState.MapOp; } map.MatchPath.IsWildcard = true; map.BindingPath.Namespace = nsp; goto case MapState.End; } if (current == '=') { map.MatchPath.Namespace = nsp; goto case MapState.MapOp; } map.MatchPath.IsWildcard = true; map.BindingPath.Namespace = nsp; goto case MapState.End; case MapState.MatchNamespace: map.MatchPath.Namespace = ScanNamespace(scan); current = scan.Current(); if (char.IsWhiteSpace(current)) { current = scan.SkipWhitespace(); if (current == '=') goto case MapState.MapOp; throw scan.CreateException(); } if (current == '=') goto case MapState.MapOp; throw scan.CreateException(); case MapState.MapOp: current = scan.MoveNext(); if (current == '>') goto case MapState.Binding; throw scan.CreateException(); case MapState.Binding: scan.MoveNext(); current = scan.SkipWhitespace(); if (char.IsLetter(current) || current == '_') goto case MapState.BindingNamespace; if (current == '~') goto case MapState.RelativeBinding; if (current == '-') goto case MapState.RelativeRootBinding; throw scan.CreateException(); case MapState.BindingNamespace: map.BindingPath.Namespace = ScanNamespace(scan); goto case MapState.End; case MapState.RelativeBinding: map.BindingPath.IsRelative = true; current = scan.MoveNext(); if (current == '.') { scan.MoveNext(); goto case MapState.BindingNamespace; } goto case MapState.End; case MapState.RelativeRootBinding: map.BindingPath.IsRelative = true; while (true) { map.BindingPath.RootDepth++; current = scan.MoveNext(); if (current == '.') { current = scan.MoveNext(); if (current == '-') continue; if (char.IsLetter(current) || current == '_') goto case MapState.BindingNamespace; throw scan.CreateException(); } goto case MapState.End; } case MapState.End: scan.SkipWhitespace(); break; } return map; }