Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

To add new attribute in CADMep+ window

SaddamShaikh77
Advocate

To add new attribute in CADMep+ window

SaddamShaikh77
Advocate
Advocate

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.

SaddamShaikh77_0-1650949504125.png

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.

0 Likes
Reply
Accepted solutions (1)
328 Views
2 Replies
Replies (2)

SaddamShaikh77
Advocate
Advocate

Also can I modify "CADMep+" to "My Properties" or if I can add new section for "My Properties" and add attributes under it for CADMep?

0 Likes

Ed__Jobe
Mentor
Mentor
Accepted solution

I could be wrong but I don't think that there are any api's for such specialized palettes and dialogs. However, which properties show up in the QUICKPROPERTIES dialog can be customized in the CUI. Perhaps your custom properties will be recognized there.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes