- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello forum,
I can fetch and modify the attributed from the CADMEP+ window where I am using AutoCAD CADMep.
I want to add new attributes to the same window. I can add it using code but can't see it in the property window under CADMep+ section. Please refere image below.
I can add modify the existing attributes shown in the image above.
I want to add new attributes say ("Test" and Value "123") below Spool or anywhere. The sequence doesn't matter.
Below is the code sample which I have tried.
public void GetSelectedObjProp()
{
Dictionary<string, Dictionary<string, string>> PropDetails = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> propVal = new Dictionary<string, string>();
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
PromptSelectionOptions Options = new PromptSelectionOptions();
Options.SingleOnly = true;
Options.SinglePickInSpace = true;
PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection(Options);
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
foreach (SelectedObject acSSObj in acSSet)
{
if (acSSObj != null)
{
acDoc.LockDocument();
Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,OpenMode.ForWrite) as Entity;
propVal = new Dictionary<string, string>();
object acadObj = acEnt.AcadObject;
var props = TypeDescriptor.GetProperties(acadObj);
foreach (PropertyDescriptor prop in props)
{
object value = prop.GetValue(acadObj);
if(prop.DisplayName == "Notes")
{
System.ComponentModel.AttributeCollection acol = prop.Attributes;
Attribute attr = new CategoryAttribute("Model123");
Attribute attr1 = new DescriptionAttribute("Note1234");
Attribute attr2 = new DesignTimeVisibleAttribute(true);
Attribute attr3 = new BrowsableAttribute(true);
Attribute[] attributes = new Attribute[4];
attributes[0] = attr;
attributes[1] = attr1;
attributes[2] = attr2;
attributes[3] = attr3;
PropertyDescriptor newProp = TypeDescriptor.CreateProperty(prop.ComponentType, prop, attributes);
PropertyDescriptor newProp1 = TypeDescriptor.CreateProperty(typeof(object), "WXYZ1234", typeof(string),
new BrowsableAttribute(true));
System.ComponentModel.AttributeCollection attrCol = newProp.Attributes;
int i = attrCol.Count;
TypeDescriptionProvider tdp = TypeDescriptor.AddAttributes(acadObj ,attrCol);
props.Add(newProp);
}
if (value != null)
{
ed.WriteMessage("\n{0} = {1}", prop.DisplayName, value.ToString());
propVal.Add(prop.DisplayName, value.ToString());
_attributeValues.Add(new AttributeParams { Name = prop.DisplayName, Value = value.ToString() });
}
}
string name = "";
propVal.TryGetValue("Name", out name);
string category = "";
category = GetCategoryAttribute(name, "Category", acCurDb);
}
}
acTrans.Commit();
}
}
}
Please let me know if I am missing something or if there is another way to achieve this.
Thank you.
Solved! Go to Solution.