public Dictionary <string, Partinfo> GetPartDictionary(Document doc)
        {
            var legends = Getmodelelement.Getlegends(doc);
            Dictionary <string, Partinfo> dictionary = new Dictionary <string, Partinfo>();
            FilteredElementCollector      filteredElementCollector = new FilteredElementCollector(doc);
            IList <Element> list = filteredElementCollector.OfClass(typeof(FamilyInstance)).ToElements();

            foreach (Element item in list)
            {
                FamilyInstance familyInstance  = item as FamilyInstance;
                FamilyInstance familyInstance2 = familyInstance?.SuperComponent as FamilyInstance;
                if (familyInstance2 != null && familyInstance2.SuperComponent == null)
                {
                    Autodesk.Revit.DB.Parameter parameter = familyInstance.Symbol.LookupParameter("CONTROL_MARK");
                    if (parameter != null && parameter.StorageType == StorageType.String)
                    {
                        string text = parameter.AsString();
                        if (!string.IsNullOrEmpty(text))
                        {
                            string name  = familyInstance2.Symbol.Name;
                            string text2 = familyInstance.LookupParameter("BOM_PRODUCT_HOST")?.AsString() ?? "";
                            if (dictionary.ContainsKey(text))
                            {
                                if (string.IsNullOrEmpty(dictionary[text].ProductName))
                                {
                                    dictionary[text].ProductName = text2;
                                }
                                else if (!dictionary[text].ProductName.Contains(text2))
                                {
                                    dictionary[text].ProductName = dictionary[text].ProductName + "; " + text2;
                                }
                                if (dictionary[text].Connection == null)
                                {
                                    dictionary[text].Connection = name;
                                }
                                else if (!dictionary[text].Connection.Contains(name))
                                {
                                    dictionary[text].Connection = dictionary[text].Connection + "; " + name;
                                }
                                bool flag = (from x in legends where x.Name.Equals(text) select x).ToList().Count != 0;
                                if (flag)
                                {
                                    dictionary[text].Draw = "true";
                                }
                                else
                                {
                                    dictionary[text].Draw = "false";
                                }
                            }
                            else
                            {
                                dictionary[text] = new Partinfo
                                {
                                    ProductName = text2
                                };
                                string description = familyInstance.Symbol.LookupParameter("IDENTITY_DESCRIPTION")?.AsString();
                                dictionary[text].Description = description;
                                dictionary[text].Connection  = name;
                                bool flag = (from x in legends where x.Name.Equals(text) select x).ToList().Count != 0;
                                if (flag)
                                {
                                    dictionary[text].Draw = "true";
                                }
                                else
                                {
                                    dictionary[text].Draw = "false";
                                }
                            }
                        }
                    }
                }
            }
            return(dictionary);
        }