Beispiel #1
0
    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);
            }
        }
    }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        //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");
                }
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        /// <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);
        }
        /// <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);
        }
Beispiel #9
0
        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);
        }
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        //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);
            }
        }
Beispiel #13
0
        static private ElementBinding GetParameterBinding(Document doc, string parameterName)
        {
            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                if (it.Key.Name == parameterName)
                {
                    return(it.Current as ElementBinding);
                }
            }
            return(null);
        }
Beispiel #14
0
        protected internal static Definition GetParameterDefinition(Document doc, string name)
        {
            BindingMap val = doc.get_ParameterBindings();
            DefinitionBindingMapIterator val2 = val.ForwardIterator();

            val2.Reset();
            while (val2.MoveNext())
            {
                InternalDefinition val3 = val2.get_Key();
                if (val3.get_Name().Equals(name))
                {
                    return(val3);
                }
            }
            return(null);
        }
Beispiel #15
0
        static List <RoomProjectParametersData> GetRoomProjectParametersData(Document doc)
        {
            // Following good SOA practices, first validate incoming parameters
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }

            if (doc.IsFamilyDocument)
            {
                throw new Exception("This plugin cannot be run on a family document.");
            }

            List <RoomProjectParametersData> result
                = new List <RoomProjectParametersData>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it
                = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                RoomProjectParametersData newProjectParameterData
                    = new RoomProjectParametersData();

                newProjectParameterData.Binding = it.Current
                                                  as ElementBinding;

                Category roomCategory = Category.GetCategory(doc, BuiltInCategory.OST_Rooms);

                IEnumerable <Category> catSet = newProjectParameterData.Binding.Categories.Cast <Category>();

                if (catSet.Any(c => c.Id.Equals(roomCategory.Id)) && it.Key.ParameterType == ParameterType.Text)
                {
                    newProjectParameterData.category   = roomCategory;
                    newProjectParameterData.Definition = it.Key;
                    newProjectParameterData.Name       = it.Key.Name;
                    newProjectParameterData.type       = it.Key.ParameterType;

                    result.Add(newProjectParameterData);
                }
            }
            return(result);
        }
        internal bool DoesParameterExist(string parameterName)
        {
            // iterate the procedure over
            // all the shared parameters in the document
            BindingMap bindingMap            = m_doc.ParameterBindings;
            DefinitionBindingMapIterator itr = bindingMap.ForwardIterator();

            while (itr.MoveNext())
            {
                InternalDefinition internalDefinition
                    = itr.Key as InternalDefinition;
                if (internalDefinition.Name == parameterName)
                {
                    return(true);
                }
            }
            return(false);
        }
        internal void CanVaryBtwGroups(
            string parameterName,
            bool allowVaryBtwGrps)
        {
            BindingMap bindingMap            = m_doc.ParameterBindings;
            DefinitionBindingMapIterator itr = bindingMap.ForwardIterator();

            while (itr.MoveNext())
            {
                InternalDefinition internalDef = itr.Key as InternalDefinition;

                if (internalDef.Name == parameterName)
                {
                    using (Transaction t = new Transaction(m_doc)) {
                        t.Start("Allow varying b/w groups");
                        internalDef.SetAllowVaryBetweenGroups(m_doc, allowVaryBtwGrps);
                        t.Commit();
                    }
                }
            }
        }
Beispiel #18
0
        private static void CreateProjectParam(Autodesk.Revit.ApplicationServices.Application app,
                                               string name, ParameterType type, bool visible, CategorySet catSet, BuiltInParameterGroup group, bool inst)
        {
            // Check whether the parameter has already been added.
            BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
            DefinitionBindingMapIterator itr = map.ForwardIterator();

            while (itr.MoveNext())
            {
                Definition exstDef = itr.Key;
                if (exstDef.Name == "LinkedTag")
                {
                    return;
                }
            }

            string orgFile  = app.SharedParametersFilename;
            string tempFile = Path.GetTempFileName() + ".txt";

            using (File.Create(tempFile)) { }
            app.SharedParametersFilename = tempFile;

            ExternalDefinition def = app.OpenSharedParameterFile().Groups.Create("TemporaryDefinitionGroup").Definitions.Create
                                         (new ExternalDefinitionCreationOptions(name, type)
            {
                Visible = visible
            }) as ExternalDefinition;

            app.SharedParametersFilename = orgFile;
            File.Delete(tempFile);

            Binding binding = app.Create.NewTypeBinding(catSet);

            if (inst)
            {
                binding = app.Create.NewInstanceBinding(catSet);
            }

            map.Insert(def, binding);
        }
Beispiel #19
0
        public static List <RawProjectParameterInfo> RawGetProjectParametersInfo(Document doc)
        {
            RawProjectParameterInfo.FileName = doc.Title;
            List <RawProjectParameterInfo> paramList = new List <RawProjectParameterInfo>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                ElementBinding  eleBinding = it.Current as ElementBinding;
                InstanceBinding insBinding = eleBinding as InstanceBinding;
                Definition      def        = it.Key;
                if (def != null)
                {
                    ExternalDefinition extDef = def as ExternalDefinition;
                    bool shared = extDef != null;
                    RawProjectParameterInfo param = new RawProjectParameterInfo
                    {
                        Name            = def.Name,
                        Group           = def.ParameterGroup,
                        Type            = def.ParameterType,
                        ReadOnly        = true, // def.IsReadOnly, def.IsReadOnly NOT working in either 2015 or 2014 but working in 2013
                        BoundToInstance = insBinding != null,
                        BoundCategories = RawConvertSetToList <Category>(eleBinding.Categories).Select(c => c.Name).ToArray(),

                        FromShared = shared,
                        GUID       = shared ? extDef.GUID.ToString() : string.Empty,
                        Owner      = shared ? extDef.OwnerGroup.Name : string.Empty,
                        Visible    = shared ? extDef.Visible : true,
                    };

                    paramList.Add(param);
                }
            }

            return(paramList);
        }
Beispiel #20
0
        public static Dictionary <string /*paramName*/, List <string> /*categoryNames*/> GetProjectParameterInfo(Document doc)
        {
            Dictionary <string, List <string> > projectParameters = new Dictionary <string, List <string> >();

            try
            {
                BindingMap bindingMap = doc.ParameterBindings;
                DefinitionBindingMapIterator iterator = bindingMap.ForwardIterator();

                while (iterator.MoveNext())
                {
                    Definition     definition     = iterator.Key as Definition;
                    string         paramName      = definition.Name;
                    ElementBinding elementBinding = iterator.Current as ElementBinding;
                    List <string>  categoryNames  = new List <string>();
                    if (null != elementBinding)
                    {
                        foreach (Category category in elementBinding.Categories)
                        {
                            if (!string.IsNullOrEmpty(category.Name))
                            {
                                categoryNames.Add(category.Name);
                            }
                        }
                    }

                    if (!projectParameters.ContainsKey(paramName))
                    {
                        projectParameters.Add(paramName, categoryNames);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get project parameter information.\n" + ex.Message, "Get Project Parameter Info", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(projectParameters);
        }
Beispiel #21
0
        /// <summary>
        /// Method to retrieve filtered project parameters ID by category
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public static string[] ProjectParameters(Document doc, string categoryName)
        {
            List <string> parametersID = new List <string>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();

            while (it.MoveNext())
            {
                ElementBinding  eleBinding = it.Current as ElementBinding;
                InstanceBinding insBinding = eleBinding as InstanceBinding;

                if (insBinding != null && IsInstBindingOfCategory(insBinding, categoryName))
                {
                    Definition def = it.Key;
                    if (def != null)
                    {
                        ExternalDefinition extDef = def as ExternalDefinition;

                        if (extDef != null)
                        {
                            string GUID = extDef.GUID.ToString();
                            parametersID.Add(GUID);
                        }
                        else
                        {
                            InternalDefinition intDef = def as InternalDefinition;
                            string             ID     = intDef.Id.ToString();
                            parametersID.Add(ID);
                        }
                    }
                }
            }
            return(parametersID.ToArray());
        }
    {//----------------------------------------------------------
        public static void get_share_parameter(Document doc, ObservableCollection <data_parameter> my_data_parameter_need, ObservableCollection <data_parameter> my_data_parameter_current)
        {
            try
            {
                if (File.Exists(Source.path_share_parameter_default))
                {
                    List <string> du_lieu           = File.ReadAllLines(Source.path_share_parameter_default).ToList();
                    BindingMap    map               = doc.ParameterBindings;
                    DefinitionBindingMapIterator it = map.ForwardIterator();
                    while (it.MoveNext())
                    {
                        Definition def = it.Key;
                        my_data_parameter_current.Add(new data_parameter()
                        {
                            ten_parameter = def.Name,
                            color         = du_lieu.Any(x => x == def.Name) == false ? Source.color_error : Source.color
                        });
                    }



                    foreach (string data in du_lieu)
                    {
                        my_data_parameter_need.Add(new data_parameter()
                        {
                            ten_parameter = data,
                            color         = my_data_parameter_current.Any(x => x.ten_parameter == data) ? Source.color : Source.color_error
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #23
0
        //private ParameterElement projectleider { get; set; }

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            NewProjects        newProjects = new NewProjects();
            ProjectInformation information = new ProjectInformation(); // ProjectInformation Dialog

            information.OK += delegate
            {
                var templateFileName = @"C:\Users\Appie\Desktop\TestTemplate.rte";
                var file             = $"{information.FilePath}\\{information.FileName}";
                var app       = commandData?.Application?.Application;
                var activeDoc = app.NewProjectDocument(templateFileName);
                ActiveDocument = activeDoc;
                var date = DateTime.Now.ToString("dd/MM/yyyy");

                using (new TransactionManager.TransactionManager(activeDoc))
                {
                    activeDoc.ProjectInformation.Name                    = information.ProjectName;
                    activeDoc.ProjectInformation.Number                  = information.TotalProjectNumber;
                    activeDoc.ProjectInformation.BuildingName            = information.BuildingName;
                    activeDoc.ProjectInformation.Author                  = Environment.UserName;
                    activeDoc.ProjectInformation.IssueDate               = date;
                    activeDoc.ProjectInformation.ClientName              = information.ClientName;
                    activeDoc.ProjectInformation.Address                 = information.Project_adress;
                    activeDoc.ProjectInformation.Status                  = "Concept";
                    activeDoc.ProjectInformation.OrganizationName        = information.OrganizationName;
                    activeDoc.ProjectInformation.OrganizationDescription = information.OrganizationDesc;
                    // activeDoc.GetElement("").GetParameters("")[0].SetValueString("");
                    if (activeDoc == null)
                    {
                        throw new ArgumentNullException("doc");
                    }

                    if (activeDoc.IsFamilyDocument)
                    {
                        throw new Exception("doc can not be a family document.");
                    }

                    List <ProjectParameterData> result = new List <ProjectParameterData>();

                    BindingMap map = activeDoc.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);
                    }
                }

                activeDoc.SaveAs(file);
                commandData.Application.OpenAndActivateDocument(file);
            };
            newProjects.ProjectInformation = information;
            newProjects.ShowDialog();
            return(Result.Succeeded);
        }
        public Result ExecuteObsolete(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            BindingMap bindings = doc.ParameterBindings;
            //Dictionary<string, Guid> guids = new Dictionary<string, Guid>();
            Dictionary <Definition, object> mapDefToGuid = new Dictionary <Definition, object>();

            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;
                    if (d is ExternalDefinition)
                    {
                        Guid g = ((ExternalDefinition)d).GUID;
                        Debug.Print(d.Name + ": " + g.ToString());
                        mapDefToGuid.Add(d, g);
                    }
                    else
                    {
                        Debug.Assert(d is InternalDefinition);

                        // this built-in parameter is INVALID:

                        BuiltInParameter bip = ((InternalDefinition)d).BuiltInParameter;
                        Debug.Print(d.Name + ": " + bip.ToString());

                        // if have a definition file and group name, we can still determine the GUID:

                        //Guid g = SharedParamGuid( app, "Identity data", d.Name );

                        mapDefToGuid.Add(d, null);
                    }
                }
            }

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
        ? "Please select some wall elements."
        : "No wall elements found.";
            }
            else
            {
                //List<string> keys = new List<string>( mapDefToGuid.Keys );
                //keys.Sort();

                foreach (Wall wall in walls)
                {
                    Debug.Print(Util.ElementDescription(wall));

                    foreach (Definition d in mapDefToGuid.Keys)
                    {
                        object o = mapDefToGuid[d];

                        Parameter p = (null == o)
            ? wall.get_Parameter(d)
            : wall.get_Parameter((Guid)o);

                        string s = (null == p)
            ? "<null>"
            : p.AsValueString();

                        Debug.Print(d.Name + ": " + s);
                    }
                }
            }
            return(Result.Failed);
        }
Beispiel #25
0
        private void CollectProjectParam()
        {
            try
            {
                proParamDictionary = new Dictionary <int, ProjectParameter>();
                BindingMap bindingMap = doc.ParameterBindings;
                DefinitionBindingMapIterator iterator = bindingMap.ForwardIterator();

                int index = 0;
                while (iterator.MoveNext())
                {
                    ElementBinding elementBinding = iterator.Current as ElementBinding;
                    CategorySet    categories     = elementBinding.Categories;
                    Definition     definition     = iterator.Key;
                    if (CheckValidParameter(categories))
                    {
                        ProjectParameter pp = new ProjectParameter(definition, categories);
                        pp.ParameterName = pp.Definition.Name;
                        string type = elementBinding.GetType().ToString();
                        if (type.Contains("InstanceBinding"))
                        {
                            pp.IsInstance = true;
                        }
                        else
                        {
                            pp.IsInstance = false;
                        }
                        proParamDictionary.Add(index, pp);
                        index++;
                    }
                }

                foreach (int i in proParamDictionary.Keys)
                {
                    ProjectParameter pp = proParamDictionary[i];

                    foreach (Category category in pp.Categories)
                    {
                        if (!category.AllowsBoundParameters)
                        {
                            continue;
                        }
                        string catName = category.Name;
                        if (catProParamDictionary.ContainsKey(catName))
                        {
                            if (!catProParamDictionary[catName].ContainsKey(pp.ParameterName))
                            {
                                catProParamDictionary[catName].Add(pp.ParameterName, pp);
                            }
                        }
                        else
                        {
                            catProParamDictionary.Add(catName, new Dictionary <string, ProjectParameter>());
                            catProParamDictionary[catName].Add(pp.ParameterName, pp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed collect project parameters: \n" + ex.Message, "ParameterSettings Error:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #26
0
        /// <summary>
        /// Command Entry Point
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // Document
                Document m_doc = commandData.Application.ActiveUIDocument.Document;

                // Session Guid
                string m_guid = Guid.NewGuid().ToString();

                //// New Schedules
                //List<ViewSchedule> m_schedules = new List<ViewSchedule>();

                //// Project Information
                //// Wires
                //// Roads
                //// Rebar Shape
                //// Areas
                //// Materials
                //// Shaft Openings
                //// Views
                //// Sheets

                //// Start a New Transaction
                //using (Transaction t = new Transaction(m_doc))
                //{
                //  if (t.Start("Not Saved") == TransactionStatus.Started)
                //  {

                //    try
                //    {

                //      // Find Categories that Support Custom Parameter Bindings
                //      foreach (Category x in m_doc.Settings.Categories)
                //      {
                //        if (x.AllowsBoundParameters)
                //        {

                //          try
                //          {
                //            // New Schedule
                //            ViewSchedule m_vs = ViewSchedule.CreateSchedule(m_doc, x.Id);
                //            m_vs.Name = x.Name;
                //            m_schedules.Add(m_vs);

                //            if (x.Id.IntegerValue == (int)BuiltInCategory.OST_Rooms)
                //            {

                //              foreach (SchedulableField sf in m_vs.Definition.GetSchedulableFields())
                //              {



                //                m_vs.Definition.AddField(sf);

                //                //// Shared Parameters will have a Positive ID
                //                //if (sf.ParameterId.IntegerValue > 0)
                //                //{
                //                //  Element m_elem = m_doc.GetElement(sf.ParameterId);
                //                //}

                //              }

                //            }

                //          }
                //          catch { }

                //        }

                //      }

                //      // Commit
                //      t.Commit();

                //    }
                //    catch { }
                //  }
                //}



                // Show the Progressbar Form
                form_Main m_dlg = new form_Main(m_doc.ParameterBindings.Size + 1);
                m_dlg.Show();

                BindingMap m_map = m_doc.ParameterBindings;

                try
                {
                    // Iterate
                    DefinitionBindingMapIterator m_iter = m_map.ForwardIterator();
                    while (m_iter.MoveNext())
                    {
                        ElementBinding m_eb  = m_iter.Current as ElementBinding;
                        Definition     m_def = m_iter.Key;

                        try
                        {
                            ExternalDefinition m_extDev = m_def as ExternalDefinition;
                            if (m_extDev != null)
                            {
                                string m_todo = string.Empty;
                            }
                        }
                        catch { }


                        //if (m_eb != null)
                        //{
                        //  CategorySet m_set = m_eb.Categories;
                        //}
                    }
                }
                catch { }

                // Success
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                // Failure
                message = ex.Message;
                return(Result.Failed);
            }
        }