.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LIST command addition

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
RichardCammeray
1672 Views, 3 Replies

LIST command addition

When you run LIST  command is it possible to write some additional information at the end (as example Entity with Xrecord )?

 

Thanks,

Richard

3 REPLIES 3
Message 2 of 4
khoa.ho
in reply to: RichardCammeray

Without .NET programming, you can use the available XDLIST command from Express Tool to see XData of a selected entity. You can use AutoLISP to group LIST and XDLIST commands to write more additional info at the end.

If you want to use AutoLISP to make your own command to see both XData and XRecord, this link is useful: http://www.afralisp.net/autolisp/tutorials/dictionaries-and-xrecords.php

The following are .NET methods to get all XData and XRecord values of a selected entity by its ObjectId:

// Get all XData of a selected entity
public static ResultBuffer[] GetAllXData(ObjectId objectId)
{
	var list = new ArrayList();
	Database db = objectId.Database;
	using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction())
	{
		var entity = (Entity)objectId.GetObject(OpenMode.ForRead);
		list.Add(entity.XData);
	}
	return (ResultBuffer[])list.ToArray(typeof(ResultBuffer));
}

// Get all XRecords of a selected entity
public static Dictionary<string, ObjectId> GetAllXRecord(ObjectId objectId)
{
	var dictionary = new Dictionary<string, ObjectId>();
	Database db = objectId.Database;
	using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction())
	{
		var entity = (Entity)trans.GetObject(objectId, OpenMode.ForRead);
		var extDictionary = (DBDictionary)trans.GetObject(entity.ExtensionDictionary, OpenMode.ForRead);
		foreach (DBDictionaryEntry entry in extDictionary)
		{
			dictionary.Add(entry.Key, entry.Value);
		}
	}
	return dictionary;
}

 

-Khoa

Message 3 of 4

Yes, you can use a PropertiesOverrule to add additional information to the output of the LIST command.

 

Here's an example:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using System.Collections;

namespace ListCommandExtensionExample
{
   class MyPropertiesOverrule : PropertiesOverrule
   {
      static RXClass rxclass = RXClass.GetClass( typeof( Entity ) );
      const short xDataAppId = (short) DxfCode.ExtendedDataRegAppName;

      public MyPropertiesOverrule()
      {
         AddOverrule( rxclass, this, true );
         Overruling = true;
      }

      public override void List( Entity entity )
      {
         base.List( entity ); // Default behavior

         // Now list the names of the items in the entity's 
         // extension dictionary if it has one:

         ObjectId idXDict = entity.ExtensionDictionary;
         if( !idXDict.IsNull )
         {
            using( Transaction tr = idXDict.Database.TransactionManager.StartTransaction() )
            {
               DBDictionary xDict = (DBDictionary) idXDict.GetObject( OpenMode.ForRead );
               if( xDict.Count > 0 )
               {
                  WriteMessage( "\nExtension Dictionary Entries:" );
                  foreach( string name in ((IDictionary) xDict).Keys )
                  {
                     WriteMessage( "\n  {0}", name );
                  }
               }
               tr.Commit();
            }
         }

         // List the Xdata application names if there are any:

         ResultBuffer xdata = entity.XData;
         if( xdata != null )
         {
            var items = xdata.Cast<TypedValue>();
            if( items.Any() )
            {
               WriteMessage( "\nExtended Data Application Ids: " );
               foreach( TypedValue tv in items.Where( tv => tv.TypeCode == xDataAppId ) )
               {
                  WriteMessage( "\n  {0}", tv.Value );
               }
            }
         }
      }

      bool disposed = false;
      protected override void Dispose( bool disposing )
      {
         bool flag = this.disposed;
         this.disposed = true;
         if( disposing && !flag )
         {
            try
            {
               RemoveOverrule( rxclass, this );
            }
            catch // we might get here if this instance is garbage-collected at shutdown
            {
            }
         }
         base.Dispose( disposing );
      }

      static void WriteMessage( string fmt, params object[] args )
      {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         if( doc != null )
            doc.Editor.WriteMessage( fmt, args );
      }

   }
}

 

 

 
Message 4 of 4

Thank you for both answers.

But the second is exactly what I wanted to achieve.

I thought that using overrule would be the option but I didn’t  have time to explore this option so you save my time.

 

Richard

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost