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

Another .NET API bug: DatabaseSummaryInfo.CustomProperties

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
638 Views, 3 Replies

Another .NET API bug: DatabaseSummaryInfo.CustomProperties


I just ran into another .NET API bug (Acad2006).

 

The bug is with
Autodesk.AutoCAD.DatabaseServices.DatabaseSummaryInfo.CustomProperties.

 

According to .NET API, DatabaseSummaryInfo.CustomProperties is
an IDictionaryEnumerator object, so, one can call Reset(), MoveNext() to loop
through each element in the collection, that is (make sure you use a drawing
that has a few custom properties):

 

Document
doc=Application.DocumentManager.MdiActiveDocument;

 

//Loop through drawing's custom properties

doc.SummaryInfo.CustomProperties.Reset();

while
(doc.SummaryInfo.CustomProperties.MoveNext())

{

    MessageBox.Show ("KEY: " +
doc.SummaryInfo.CustomProperties.Key + "\nVALUE: " +
doc.SummaryInfo.CustomProperties.Value)

 

    //Or, more clearly

    //MessageBox.Show ("KEY: " +
doc.SummaryInfo.CustomProperties.Current.Key + "\nVALUE: " +
doc.SummaryInfo.CustomProperties.Current.Value)

}

 

However, above code will generate exception.

 

The error occurs on the first line of code in the loop when
you try to access

 

doc.SummaryInfo.CustomProperties.Current

 

The exception indicates that there is no element in the
collection. If you remove all code in the loop, you will be trapped in an
endless loop. You have to kill Acad session to stop it.

 

It cost whole morning to find the workaround:

 

You do not loop through the "doc.SummaryInfo.CustomProperties"
object, you do:

 

System.Collection.IDictionaryEnumerator
de=doc.SummaryInfo.CustomProperties

de.Reset();

while(de.MoveNext())

{

    MessageBox.Show ("KEY: " + de.Key +
"\nVALUE: " + de.Value)

}

 

Magically, explitly assign
DatabaseSummaryInfo.CustomProperties to a IDictionaryEnumerator variable
ridicularly solve the problem.

 

It is obviously that the implementation of
DatabaseSummaryInfo.CustomProperties to AutoCAD .NET API does not do it
correctly.

 

Can someone else verify this on Acad2006, 2007?

 

Here is the whole test code (note: you need to open a drawing
with a few custom properties to run the test):

 

using System;
using Autodesk.AutoCAD.Runtime;
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.DatabaseServices;
using System.Windows.Forms;

 

[assembly:
CommandClass(typeof(ClassLibrary.WDSGClass))]

 

namespace ClassLibrary
{
    ///
<summary>
    /// Summary description for
WDSGClass.
    /// </summary>
   
public class WDSGClass
    {

 

        private
Autodesk.AutoCAD.ApplicationServices.Document
mDoc;
       

        public
WDSGClass()
       
{
           

        }

 

       
[CommandMethod("DwgTest")]
        public
void test() // This method can have any
name
       
{
            mDoc =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
           
Database db = mDoc.Database;

 


size=2>            int
propCount = 0;

 


size=2>           
/*==This part of code generates exception, although it should
work
           
db.SummaryInfo.CustomProperties.Reset();
           
while
(db.SummaryInfo.CustomProperties.MoveNext())
           
{
               
propCount++;

 

           
    //if you comment out this line of code, you get endless loop,
until propCount overflows or you kill Acad
session
               
MessageBox.Show(db.SummaryInfo.CustomProperties.Key + "\n" +
db.SummaryInfo.CustomProperties.Value);
           
}
            
*/

 

           
//This part code is OK


size=2>           
System.Collections.IDictionaryEnumerator de =
db.SummaryInfo.CustomProperties;
           
de.Reset();
           
while
(de.MoveNext())
           
{
               
propCount++;
               
MessageBox.Show(de.Key + "\n" +
de.Value);
           
}

 


size=2>           
MessageBox.Show(propCount + " custom
properties.");
       
}
    }
}
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

{
Database db = ...

DatabaseSummaryInfoBuilder builder =
new DatabaseSummaryInfoBuilder(db.SummaryInfo);

StringDictionary dict = builder.CustomProperties;

foreach( DictionaryEntry entry in dict )
{
Console.WriteLine("{0} = {1}", entry.Key, entry.Value);
}

int PropertyCount = dict.Count;

}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Norman Yuan" wrote in message news:5255180@discussion.autodesk.com...
I just ran into another .NET API bug (Acad2006).

The bug is with Autodesk.AutoCAD.DatabaseServices.DatabaseSummaryInfo.CustomProperties.

According to .NET API, DatabaseSummaryInfo.CustomProperties is an IDictionaryEnumerator object, so, one can call Reset(), MoveNext() to loop through each element in the collection, that is (make sure you use a drawing that has a few custom properties):

Document doc=Application.DocumentManager.MdiActiveDocument;

//Loop through drawing's custom properties
doc.SummaryInfo.CustomProperties.Reset();
while (doc.SummaryInfo.CustomProperties.MoveNext())
{
MessageBox.Show ("KEY: " + doc.SummaryInfo.CustomProperties.Key + "\nVALUE: " + doc.SummaryInfo.CustomProperties.Value)

//Or, more clearly
//MessageBox.Show ("KEY: " + doc.SummaryInfo.CustomProperties.Current.Key + "\nVALUE: " + doc.SummaryInfo.CustomProperties.Current.Value)
}

However, above code will generate exception.

The error occurs on the first line of code in the loop when you try to access

doc.SummaryInfo.CustomProperties.Current

The exception indicates that there is no element in the collection. If you remove all code in the loop, you will be trapped in an endless loop. You have to kill Acad session to stop it.

It cost whole morning to find the workaround:

You do not loop through the "doc.SummaryInfo.CustomProperties" object, you do:

System.Collection.IDictionaryEnumerator de=doc.SummaryInfo.CustomProperties
de.Reset();
while(de.MoveNext())
{
MessageBox.Show ("KEY: " + de.Key + "\nVALUE: " + de.Value)
}

Magically, explitly assign DatabaseSummaryInfo.CustomProperties to a IDictionaryEnumerator variable ridicularly solve the problem.

It is obviously that the implementation of DatabaseSummaryInfo.CustomProperties to AutoCAD .NET API does not do it correctly.

Can someone else verify this on Acad2006, 2007?

Here is the whole test code (note: you need to open a drawing with a few custom properties to run the test):

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using System.Windows.Forms;

[assembly: CommandClass(typeof(ClassLibrary.WDSGClass))]

namespace ClassLibrary
{
///
/// Summary description for WDSGClass.
///

public class WDSGClass
{

private Autodesk.AutoCAD.ApplicationServices.Document mDoc;

public WDSGClass()
{

}

[CommandMethod("DwgTest")]
public void test() // This method can have any name
{
mDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = mDoc.Database;

int propCount = 0;

/*==This part of code generates exception, although it should work
db.SummaryInfo.CustomProperties.Reset();
while (db.SummaryInfo.CustomProperties.MoveNext())
{
propCount++;

//if you comment out this line of code, you get endless loop, until propCount overflows or you kill Acad session
MessageBox.Show(db.SummaryInfo.CustomProperties.Key + "\n" + db.SummaryInfo.CustomProperties.Value);
}
*/

//This part code is OK
System.Collections.IDictionaryEnumerator de = db.SummaryInfo.CustomProperties;
de.Reset();
while (de.MoveNext())
{
propCount++;
MessageBox.Show(de.Key + "\n" + de.Value);
}

MessageBox.Show(propCount + " custom properties.");
}
}
}
Message 3 of 4
Anonymous
in reply to: Anonymous

I use DatabaseSummaryInfoBuilder object when I need to modify a drawing's
Database.SummaryInfo object. But sometimes I only need to read drawing
properties, including custom properties. Since
DatabaseSummaryInfo.CustomProperties is an IDictionaryEnumerator object,
according to .NET document, it can be used to read elements in the
collection, but not modify it, so I did not thing at first that I have to
use DatabaseSummaryInfoBuilder object to read. And the ridicular thing is
that you can not directly iterate the IDirectionaryEnumerator (i.e.
DatabaseSummaryInfo.CustomProperties), but you can if you assign it to
another IDictionaryEnumerator reference.

I understand the .NET API is simply the wrapper of C/C++ based library,
there may not be easy to translate underline C/C++ functions into a perfect
suitable .NET objects, so it could be this way intentionally (i.e. one
should always access DatabaseSummaryInfo via DatabaseSummaryInfoBuilder,
whether you want to "build" it or simply read it), but Autodesk is simply
too busy for yearly new release to bother to do some very basic
documentation to let its users/developers to know it.


"Tony Tanzillo" wrote in message
news:5255549@discussion.autodesk.com...
{
Database db = ...

DatabaseSummaryInfoBuilder builder =
new DatabaseSummaryInfoBuilder(db.SummaryInfo);

StringDictionary dict = builder.CustomProperties;

foreach( DictionaryEntry entry in dict )
{
Console.WriteLine("{0} = {1}", entry.Key, entry.Value);
}

int PropertyCount = dict.Count;

}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Norman Yuan" wrote in message
news:5255180@discussion.autodesk.com...
I just ran into another .NET API bug (Acad2006).

The bug is with
Autodesk.AutoCAD.DatabaseServices.DatabaseSummaryInfo.CustomProperties.

According to .NET API, DatabaseSummaryInfo.CustomProperties is an
IDictionaryEnumerator object, so, one can call Reset(), MoveNext() to loop
through each element in the collection, that is (make sure you use a drawing
that has a few custom properties):

Document doc=Application.DocumentManager.MdiActiveDocument;

//Loop through drawing's custom properties
doc.SummaryInfo.CustomProperties.Reset();
while (doc.SummaryInfo.CustomProperties.MoveNext())
{
MessageBox.Show ("KEY: " + doc.SummaryInfo.CustomProperties.Key +
"\nVALUE: " + doc.SummaryInfo.CustomProperties.Value)

//Or, more clearly
//MessageBox.Show ("KEY: " +
doc.SummaryInfo.CustomProperties.Current.Key + "\nVALUE: " +
doc.SummaryInfo.CustomProperties.Current.Value)
}

However, above code will generate exception.

The error occurs on the first line of code in the loop when you try to
access

doc.SummaryInfo.CustomProperties.Current

The exception indicates that there is no element in the collection. If you
remove all code in the loop, you will be trapped in an endless loop. You
have to kill Acad session to stop it.

It cost whole morning to find the workaround:

You do not loop through the "doc.SummaryInfo.CustomProperties" object, you
do:

System.Collection.IDictionaryEnumerator de=doc.SummaryInfo.CustomProperties
de.Reset();
while(de.MoveNext())
{
MessageBox.Show ("KEY: " + de.Key + "\nVALUE: " + de.Value)
}

Magically, explitly assign DatabaseSummaryInfo.CustomProperties to a
IDictionaryEnumerator variable ridicularly solve the problem.

It is obviously that the implementation of
DatabaseSummaryInfo.CustomProperties to AutoCAD .NET API does not do it
correctly.

Can someone else verify this on Acad2006, 2007?

Here is the whole test code (note: you need to open a drawing with a few
custom properties to run the test):

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using System.Windows.Forms;

[assembly: CommandClass(typeof(ClassLibrary.WDSGClass))]

namespace ClassLibrary
{
///
/// Summary description for WDSGClass.
///

public class WDSGClass
{

private Autodesk.AutoCAD.ApplicationServices.Document mDoc;

public WDSGClass()
{

}

[CommandMethod("DwgTest")]
public void test() // This method can have any name
{
mDoc =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = mDoc.Database;

int propCount = 0;

/*==This part of code generates exception, although it should
work
db.SummaryInfo.CustomProperties.Reset();
while (db.SummaryInfo.CustomProperties.MoveNext())
{
propCount++;

//if you comment out this line of code, you get endless
loop, until propCount overflows or you kill Acad session
MessageBox.Show(db.SummaryInfo.CustomProperties.Key + "\n" +
db.SummaryInfo.CustomProperties.Value);
}
*/

//This part code is OK
System.Collections.IDictionaryEnumerator de =
db.SummaryInfo.CustomProperties;
de.Reset();
while (de.MoveNext())
{
propCount++;
MessageBox.Show(de.Key + "\n" + de.Value);
}

MessageBox.Show(propCount + " custom properties.");
}
}
}
Message 4 of 4
Anonymous
in reply to: Anonymous

Because DatabaseSummaryInfo appears to be a read-only object
it can't expose the custom properties as a StringDictionary, because
that can be modified.

So, I will presume they exposed the enumerator to prevent
changes to the elements, but of course, it wasn't really a
good idea to say the least.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Norman Yuan" wrote in message news:5256137@discussion.autodesk.com...
I use DatabaseSummaryInfoBuilder object when I need to modify a drawing's
Database.SummaryInfo object. But sometimes I only need to read drawing
properties, including custom properties. Since
DatabaseSummaryInfo.CustomProperties is an IDictionaryEnumerator object,
according to .NET document, it can be used to read elements in the
collection, but not modify it, so I did not thing at first that I have to
use DatabaseSummaryInfoBuilder object to read. And the ridicular thing is
that you can not directly iterate the IDirectionaryEnumerator (i.e.
DatabaseSummaryInfo.CustomProperties), but you can if you assign it to
another IDictionaryEnumerator reference.

I understand the .NET API is simply the wrapper of C/C++ based library,
there may not be easy to translate underline C/C++ functions into a perfect
suitable .NET objects, so it could be this way intentionally (i.e. one
should always access DatabaseSummaryInfo via DatabaseSummaryInfoBuilder,
whether you want to "build" it or simply read it), but Autodesk is simply
too busy for yearly new release to bother to do some very basic
documentation to let its users/developers to know it.


"Tony Tanzillo" wrote in message
news:5255549@discussion.autodesk.com...
{
Database db = ...

DatabaseSummaryInfoBuilder builder =
new DatabaseSummaryInfoBuilder(db.SummaryInfo);

StringDictionary dict = builder.CustomProperties;

foreach( DictionaryEntry entry in dict )
{
Console.WriteLine("{0} = {1}", entry.Key, entry.Value);
}

int PropertyCount = dict.Count;

}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Norman Yuan" wrote in message
news:5255180@discussion.autodesk.com...
I just ran into another .NET API bug (Acad2006).

The bug is with
Autodesk.AutoCAD.DatabaseServices.DatabaseSummaryInfo.CustomProperties.

According to .NET API, DatabaseSummaryInfo.CustomProperties is an
IDictionaryEnumerator object, so, one can call Reset(), MoveNext() to loop
through each element in the collection, that is (make sure you use a drawing
that has a few custom properties):

Document doc=Application.DocumentManager.MdiActiveDocument;

//Loop through drawing's custom properties
doc.SummaryInfo.CustomProperties.Reset();
while (doc.SummaryInfo.CustomProperties.MoveNext())
{
MessageBox.Show ("KEY: " + doc.SummaryInfo.CustomProperties.Key +
"\nVALUE: " + doc.SummaryInfo.CustomProperties.Value)

//Or, more clearly
//MessageBox.Show ("KEY: " +
doc.SummaryInfo.CustomProperties.Current.Key + "\nVALUE: " +
doc.SummaryInfo.CustomProperties.Current.Value)
}

However, above code will generate exception.

The error occurs on the first line of code in the loop when you try to
access

doc.SummaryInfo.CustomProperties.Current

The exception indicates that there is no element in the collection. If you
remove all code in the loop, you will be trapped in an endless loop. You
have to kill Acad session to stop it.

It cost whole morning to find the workaround:

You do not loop through the "doc.SummaryInfo.CustomProperties" object, you
do:

System.Collection.IDictionaryEnumerator de=doc.SummaryInfo.CustomProperties
de.Reset();
while(de.MoveNext())
{
MessageBox.Show ("KEY: " + de.Key + "\nVALUE: " + de.Value)
}

Magically, explitly assign DatabaseSummaryInfo.CustomProperties to a
IDictionaryEnumerator variable ridicularly solve the problem.

It is obviously that the implementation of
DatabaseSummaryInfo.CustomProperties to AutoCAD .NET API does not do it
correctly.

Can someone else verify this on Acad2006, 2007?

Here is the whole test code (note: you need to open a drawing with a few
custom properties to run the test):

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using System.Windows.Forms;

[assembly: CommandClass(typeof(ClassLibrary.WDSGClass))]

namespace ClassLibrary
{
///
/// Summary description for WDSGClass.
///

public class WDSGClass
{

private Autodesk.AutoCAD.ApplicationServices.Document mDoc;

public WDSGClass()
{

}

[CommandMethod("DwgTest")]
public void test() // This method can have any name
{
mDoc =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = mDoc.Database;

int propCount = 0;

/*==This part of code generates exception, although it should
work
db.SummaryInfo.CustomProperties.Reset();
while (db.SummaryInfo.CustomProperties.MoveNext())
{
propCount++;

//if you comment out this line of code, you get endless
loop, until propCount overflows or you kill Acad session
MessageBox.Show(db.SummaryInfo.CustomProperties.Key + "\n" +
db.SummaryInfo.CustomProperties.Value);
}
*/

//This part code is OK
System.Collections.IDictionaryEnumerator de =
db.SummaryInfo.CustomProperties;
de.Reset();
while (de.MoveNext())
{
propCount++;
MessageBox.Show(de.Key + "\n" + de.Value);
}

MessageBox.Show(propCount + " custom properties.");
}
}
}

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