.NET

Reply
Active Contributor
RichardCammeray
Posts: 46
Registered: ‎12-08-2010
Message 1 of 4 (676 Views)
Accepted Solution

LIST command addition

676 Views, 3 Replies
08-22-2012 10:30 PM

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

 

Thanks,

Richard

Distinguished Contributor
khoa.ho
Posts: 148
Registered: ‎09-15-2011
Message 2 of 4 (657 Views)

Re: LIST command addition

08-23-2012 07:27 AM 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

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 4 (636 Views)

Re: LIST command addition

08-23-2012 03:46 PM in reply to: RichardCammeray

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 );
      }

   }
}

 

 

 
Active Contributor
RichardCammeray
Posts: 46
Registered: ‎12-08-2010
Message 4 of 4 (631 Views)

Re: LIST command addition

08-23-2012 04:28 PM in reply to: RichardCammeray

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community