Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
[CommandMethod("NLTAG")]
             public void ListAttributes()

             {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor ed=Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            Transaction tr = db.TransactionManager.StartTransaction();

            try
            {


            TypedValue[] filList = new TypedValue[1] { new                           TypedValue((int)DxfCode.Start, "INSERT") };
           SelectionFilter filter = new SelectionFilter(filList);

           // Do nothing if selection is unsuccessful
           if (res.Status != PromptStatus.OK)
               return;

           SelectionSet selSet = res.Value;
           ObjectId[] idArray = selSet.GetObjectIds();



           foreach (ObjectId blkId in idArray)
           {
               BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead);
               BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);
               ////ed.WriteMessage(
               ////  "\nBlock: " + btr.Name
               ////);
               btr.Dispose();

               AttributeCollection attCol = blkRef.AttributeCollection;
               AttributeCollection parts = blkRef.AttributeCollection;
               foreach (ObjectId attId in attCol)
               {

               AttributeReference attRef(AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);



     string str = ("\n " + attRef.TextString);//here i get duplicate value
                   ed.WriteMessage(str);
               }
           }
           tr.Commit();
       }
       catch (Autodesk.AutoCAD.Runtime.Exception ex)
       {
           ed.WriteMessage(("Exception: " + ex.Message));
       }
       finally
       {
           tr.Dispose();
       }


What I have tried:

This is my c# code which get all attributes from selected block and print it and i want to avoid the duplicate attributes so i get each attribute onec only.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900