drawing properties-> custom tab【.net programming】

drawing properties-> custom tab【.net programming】

Anonymous
Not applicable
2,698 Views
11 Replies
Message 1 of 12

drawing properties-> custom tab【.net programming】

Anonymous
Not applicable

Hi, everyone

Now i am using c# for my autocad2014 development. 

may I ask how can I get the data from this custom tab?

I hava try this , but not work, pls help.Smiley Frustrated 

 String test = thisDrawing.SummaryInfo.Keywords;

 

GUID-240E96EB-60DE-4DBB-B337-64686649006A (1).png

0 Likes
2,699 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

pls help, really in urgent

0 Likes
Message 3 of 12

Anonymous
Not applicable

or can just provide me an interface to access this custom tab is ok, thx thx.

0 Likes
Message 4 of 12

Anonymous
Not applicable

I'm not a C# & NET user (yet)

 

but I read about a similar subject in this Forum VBA thread

maybe you can get some elements from and "translate" into C# and NET

0 Likes
Message 5 of 12

_Tharwat
Advisor
Advisor

Hi.

 

You can explore it yourself when you know that it is a property under Database.SummerayInfo 

 

Good luck.

0 Likes
Message 6 of 12

_gile
Consultant
Consultant

Hi,

 

You can use these extension methods.

 

using System.Collections;
using System.Collections.Generic;

namespace Autodesk.AutoCAD.DatabaseServices
{
    /// <summary>
    /// Provides extension methods for the Database type
    /// </summary>
    public static class DatabaseExtension
    {
        /// <summary>
        /// Gets the drawing custom properties.
        /// </summary>
        /// <param name="db">Database instance this method applies to.</param>
        /// <returns>A strongly typed dictionary containing the entries.</returns>
        public static Dictionary<string, string> GetCustomProperties(this Database db)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            IDictionaryEnumerator dictEnum = db.SummaryInfo.CustomProperties;
            while (dictEnum.MoveNext())
            {
                DictionaryEntry entry = dictEnum.Entry;
                result.Add((string)entry.Key, (string)entry.Value);
            }
            return result;
        }

        /// <summary>
        /// Gets a drawing custom property.
        /// </summary>
        /// <param name="db">Database instance this method applies to.</param>
        /// <param name="key">Property key.</param>
        /// <returns>The property value or null if not found</returns>
        public static string GetCustomProperty(this Database db, string key)
        {
            DatabaseSummaryInfoBuilder sumInfo = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
            IDictionary custProps = sumInfo.CustomPropertyTable;
            return (string)custProps[key];
        }

        /// <summary>
        /// Sets a property value
        /// </summary>
        /// <param name="db">Database instance this method applies to.</param>
        /// <param name="key">Property key.</param>
        /// <param name="value">Property value.</param>
        public static void SetCustomProperty(this Database db, string key, string value)
        {
            DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(db.SummaryInfo);
            IDictionary custProps = infoBuilder.CustomPropertyTable;
            if (custProps.Contains(key))
                custProps[key] = value;
            else
                custProps.Add(key, value);
            db.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
        }
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 12

Anonymous
Not applicable

Thx for your answer and quick response.

here's the problem,

while I am using this class to get the drawing,

Autodesk.AutoCAD.Interop.Common;

however, your entension method is using Autodesk.AutoCAD.DatabaseServices, seems cant link together.

May I ask how can i fill in the this Database db by using  Autodesk.AutoCAD.Interop.Common??

public static Dictionary<string, string> GetCustomProperties(this Database db)
{
Dictionary<string, string> result = new Dictionary<string, string>();
IDictionaryEnumerator dictEnum = db.SummaryInfo.CustomProperties;
while (dictEnum.MoveNext())
{
DictionaryEntry entry = dictEnum.Entry;
result.Add((string)entry.Key, (string)entry.Value);
}
return result;
}

0 Likes
Message 8 of 12

Anonymous
Not applicable
cant change “Autodesk.AutoCAD.Interop.Common.AcadDatabase”to “Autodesk.AutoCAD.DatabaseServices.Database”
here's the problem
0 Likes
Message 9 of 12

Anonymous
Not applicable

I'm answering mainly to learn myself from your feedbacks then to actually help the OP. though I hope I will, too

 

Should extension methods be possible with reference to COM namespaces ones, then I'd just use the proper COM class name instead of "Database".

Since in ActiveX the "SummaryInfo" object is accessed via the "SummaryInfo" property of "Database" or "Document" objects, whose class names are "AcadDatabase" and "AcadDocument",  and since the OP's using "Autodesk.AutoCAD.Interop.Common", then I would try "AcadDatabase"

 

 

On the other hand I think he could go on with the "totally COM" approach and use quite much the same code of the link in post #4

 

I'd highly appreciate you all to elaborate on what above

 

 

 

0 Likes
Message 10 of 12

_gile
Consultant
Consultant

Sorry.

 

As you wrote: "Now i am using c# for my autocad2014 development.", I thaught you wanted a .NET reply and didn't saw you use the COM/ActiveX API.

By my side, I try to avoid, as far as I can, tu use the COM API which is really less powerfull (should I say 'crappy' ?) compared the the .NET one.

 

Anyway, the SummaryInfo.Keywords property corresponds to an entry in the "Summary" tab.

If you want to access to the "Custom" tab entries, you have to use the following methods:

 

  • thisDrawing.SummaryInfo.AddCustomInfo()
  • thisDrawing.SummaryInfo.GetCustomByIndex()
  • thisDrawing.SummaryInfo.GetCustomByKey()
  • thisDrawing.SummaryInfo.NumCustomInfo()
  • thisDrawing.SummaryInfo.RemoveCustomByIndex()
  • thisDrawing.SummaryInfo.RemoveCustomByKey()
  • thisDrawing.SummaryInfo.SetCustomByIndex()
  • thisDrawing.SummaryInfo.SetCustomByKey()


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 12

_gile
Consultant
Consultant

RICVBA a écrit :
Should extension methods be possible with reference to COM namespaces ones

 


You can do something like this (but, one more time, use .NET API instead of COM API as soon as it's possible)

 

using System.Collections.Generic;

namespace Autodesk.AutoCAD.Interop.Common
{
    public static class InteropExtension
    {
        public static Dictionary<string, string> GetCustomProperties(this AcadDocument thisDrawing)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            AcadSummaryInfo info = thisDrawing.SummaryInfo;
            for (int i = 0; i < info.NumCustomInfo(); i++)
            {
                string key, val;
                info.GetCustomByIndex(i, out key, out val);
                result.Add(key, val);
            }
            return result;
        }
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 12

Anonymous
Not applicable

thank you Gile

 

glad to see my guessing was nearly correct.

 

and I assure you: when in .NET I'll only use its API!

although, in regard to that, I read sometimes that there still lingers the need of COM ones for some specific purposes...

0 Likes