QQ群友提出的问题,
当问点编组设置用户自定义属性分类并修改自定义属性值后,
想删除自定义属性时提示属性正在使用,
无法删除.....
为实现删除功能,
使用COM API,
顺利实现删除。
测试代码如下:
civil 3d版本为2022,
"AeccXUiLand.AeccApplication.13.4";中的13.4需要根据使用的civil 3d版本就行修改,
注释掉的代码不能实现自定义属性的删除。
public void C_TestUDP() { Document doc = Application.DocumentManager.MdiActiveDocument; CivilDocument civilDoc = CivilApplication.ActiveDocument; PointGroup pg; using (Transaction tr = doc.TransactionManager.StartTransaction()) { PointGroupCollection pgcs = civilDoc.PointGroups; foreach (ObjectId id in pgcs) { pg = id.GetObject(OpenMode.ForWrite) as PointGroup; pg.UseNoneClassification(); } tr.Commit(); } //using (Transaction tr = doc.TransactionManager.StartTransaction()) //{ // UDPClassification udpc; // if (civilDoc.PointUDPClassifications.Contains("桩参数")) // { // udpc = civilDoc.PointUDPClassifications["桩参数"]; // for (int i = udpc.UDPs.Count - 1; i >= 0; i--) // { // udpc.RemoveUDP(udpc.UDPs[i]); // } // } // tr.Commit(); //} string m_sAcadProdID = "AutoCAD.Application"; string m_sAeccAppProgId = "AeccXUiLand.AeccApplication.13.4"; var m_oAcadApp = (IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(m_sAcadProdID); var m_oAeccApp = (IAeccApplication)m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId); var m_oAeccDoc = (IAeccDocument)m_oAeccApp.ActiveDocument; var m_oAeccDb = (AeccDatabase)m_oAeccApp.ActiveDocument.Database; var m_oAeccudpc = m_oAeccDb.PointUserDefinedPropertyClassifications.Item("桩参数"); try { for (int i = m_oAeccudpc.UserDefinedProperties.Count - 1; i >= 0; i--) { m_oAeccudpc.UserDefinedProperties.Remove(i); } } catch (System.Exception ex) { } }