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

what is System.Collections.IEnumerator? I did my homework I promise....

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
566 Views, 7 Replies

what is System.Collections.IEnumerator? I did my homework I promise....

Ok, after some not so high quality posts the last few days, this one is real.
I am using the Autodesk.AutoCAD.DatabaseServices.Viewport.FreezeLayersInViewport method and its argument is
System.Collections.IEnumerator
I looked all around and just could not figure out what that is. Yes, this is because I am green at .net, for sure.
I thought an IEnumerator was an objectID at first but objectid's are typically passed as arrays, like a selection set.
I looked in my books and the help files with no luck.
So I need to be schooled, what is a System.Collections.IEnumerator in this context?

thanks
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

you know, I never tried the layer name. I looked at this example code:
http://msdn2.microsoft.com/en-us/library/system.collections.ienumerator.aspx

the hard part about .net for me is I know the framework to a certain level, but I'm not slick with inheritance.
Things like interfaces and abstract classes are still soaking in. I get inheritance though, mostly.

James Maeding
|>Ok, after some not so high quality posts the last few days, this one is real.
|>I am using the Autodesk.AutoCAD.DatabaseServices.Viewport.FreezeLayersInViewport method and its argument is
|>System.Collections.IEnumerator
|>I looked all around and just could not figure out what that is. Yes, this is because I am green at .net, for sure.
|>I thought an IEnumerator was an objectID at first but objectid's are typically passed as arrays, like a selection set.
|>I looked in my books and the help files with no luck.
|>So I need to be schooled, what is a System.Collections.IEnumerator in this context?
|>
|>thanks
|>James Maeding
|>Civil Engineer and Programmer
|>jmaeding - at - hunsaker - dotcom
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 3 of 8
Anonymous
in reply to: Anonymous

The more I read on this the wierder it gets. I understand that the IEnumerator is used to loop through collections, but
have no idea why the FreezeLayersInViewport method does not simply ask for an array of object ID's.

The methods name implies you can do several layers at once, while an IEnumerator object seems to only point to one item
in a collection at once.
Here is typical code for looping:

LayerTable ltbl = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead, false);
IEnumerator ltblItem = ltbl.GetEnumerator();
while (ltblItem.MoveNext()) ;<---here is where you jump to next item in collection, it only holds one item
{
ObjectId id = (ObjectId)ltblItem.Current;
using (LayerTableRecord rec = (LayerTableRecord)tm.GetObject(id, OpenMode.ForRead))
{
ed.WriteMessage(string.Format("\nLayer Name : {0}", rec.Name));
}
}

Do I have to loop through the layertable and run the FreezeLayersInViewport method as I go?
It seems like it was designed this way.
any help appreciated.


James Maeding
|>Ok, after some not so high quality posts the last few days, this one is real.
|>I am using the Autodesk.AutoCAD.DatabaseServices.Viewport.FreezeLayersInViewport method and its argument is
|>System.Collections.IEnumerator
|>I looked all around and just could not figure out what that is. Yes, this is because I am green at .net, for sure.
|>I thought an IEnumerator was an objectID at first but objectid's are typically passed as arrays, like a selection set.
|>I looked in my books and the help files with no luck.
|>So I need to be schooled, what is a System.Collections.IEnumerator in this context?
|>
|>thanks
|>James Maeding
|>Civil Engineer and Programmer
|>jmaeding - at - hunsaker - dotcom
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 4 of 8
cgay
in reply to: Anonymous

James,

The method you want to use is expecting you to pass a type that implements the IEnumerable interface. Looking at this method, I can also see that it is expecting the collection to contain ObjectIDs. A good collection to use in this situation is Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection. This collection internally implements the IList interface which in turn implements the IEnumerable interface.

If you look at the method declaration for FreezeLayersInViewport, the name of the variable gives away what you should be passing (layerIDs) or the ObjectIDs of the layers you want to freeze in the viewport.

So:

1. declare a variable of type Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection (make sure you NEW this)
[code]
Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDList =new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
[/code]
2. add the object ids of the layers you want to freeze to this
[code]
IDList.Add(Layer.ObjectID);
[/code]
3. call the FreezeLayersInViewport method passing the collection of Layer ObjectIDs to freeze
[code]
viewport.FreezeLayersInViewport(IDList);
[/code]

Should do it for ya,
C
Message 5 of 8
Anonymous
in reply to: Anonymous

got it, that totally makes sense now. Its still odd to me that selection sets are arrays of objectID's while other
methods want collections of them.
much appreciated.

CougerAC <>
|>James,
|>
|>The method you want to use is expecting you to pass a type that implements the IEnumerable interface. Looking at this method, I can also see that it is expecting the collection to contain ObjectIDs. A good collection to use in this situation is Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection. This collection internally implements the IList interface which in turn implements the IEnumerable interface.
|>
|>If you look at the method declaration for FreezeLayersInViewport, the name of the variable gives away what you should be passing (layerIDs) or the ObjectIDs of the layers you want to freeze in the viewport.
|>
|>So:
|>
|>1. declare a variable of type Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection (make sure you NEW this)
|>[code]
|>Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDList =new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
|>[/code]
|>2. add the object ids of the layers you want to freeze to this
|>[code]
|>IDList.Add(Layer.ObjectID);
|>[/code]
|>3. call the FreezeLayersInViewport method passing the collection of Layer ObjectIDs to freeze
|>[code]
|>viewport.FreezeLayersInViewport(IDList);
|>[/code]
|>
|>Should do it for ya,
|>C
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 6 of 8
Anonymous
in reply to: Anonymous

Hey Cougar,
lookslike you have to call the getenumerator method for that function, like:

vPort.FreezeLayersInViewport(IDList.GetEnumerator())

This enumerator concept still does not make sense to me.
What actual info does the Enumerator object hold?
I am guessing its a pointer to an object in a collection, but not quite sure.

I took Tony's advice and found an online forum where people were willing to help...whoops, ended up right here 🙂

CougerAC <>
|>James,
|>
|>The method you want to use is expecting you to pass a type that implements the IEnumerable interface. Looking at this method, I can also see that it is expecting the collection to contain ObjectIDs. A good collection to use in this situation is Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection. This collection internally implements the IList interface which in turn implements the IEnumerable interface.
|>
|>If you look at the method declaration for FreezeLayersInViewport, the name of the variable gives away what you should be passing (layerIDs) or the ObjectIDs of the layers you want to freeze in the viewport.
|>
|>So:
|>
|>1. declare a variable of type Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection (make sure you NEW this)
|>[code]
|>Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDList =new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
|>[/code]
|>2. add the object ids of the layers you want to freeze to this
|>[code]
|>IDList.Add(Layer.ObjectID);
|>[/code]
|>3. call the FreezeLayersInViewport method passing the collection of Layer ObjectIDs to freeze
|>[code]
|>viewport.FreezeLayersInViewport(IDList);
|>[/code]
|>
|>Should do it for ya,
|>C
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 7 of 8
Anonymous
in reply to: Anonymous

Like many (maybe even most) things in programing, an enumerator is an
abstraction: rather than fix that things are always stored in 0-based
arrays, and that you can only walk the array from 0 to n-1, you create an
abstraction. This lets you store things in linked lists, stacks, binary
trees, XML, etc. and still use the same code to process this data. This
abstraction also lets you easily process your data in different ways, for
example n-1 to 0 for an array or depth-first vs. breadth-first for a tree.

Here (http://msdn2.microsoft.com/en-us/vcsharp/bb264519.aspx) is a recent
MSDN article that shows some of the ways these abstractions can be so
useful.

Parts (much) of the AutoCAD .NET API was designed and implemented with .NET
1.0, before the introduction of generics in .NET 2.0. As a result, some of
the APIs aren't quite as clear as they could be now with generics. For
example, if written today, this API might use IEnumerable rather
than just IEnumerable.

Dan

"James Maeding" wrote in message
news:5502479@discussion.autodesk.com...
Hey Cougar,
lookslike you have to call the getenumerator method for that function, like:

vPort.FreezeLayersInViewport(IDList.GetEnumerator())

This enumerator concept still does not make sense to me.
What actual info does the Enumerator object hold?
I am guessing its a pointer to an object in a collection, but not quite
sure.

I took Tony's advice and found an online forum where people were willing to
help...whoops, ended up right here 🙂

CougerAC <>
|>James,
|>
|>The method you want to use is expecting you to pass a type that implements
the IEnumerable interface. Looking at this method, I can also see that it is
expecting the collection to contain ObjectIDs. A good collection to use in
this situation is Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection. This
collection internally implements the IList interface which in turn
implements the IEnumerable interface.
|>
|>If you look at the method declaration for FreezeLayersInViewport, the name
of the variable gives away what you should be passing (layerIDs) or the
ObjectIDs of the layers you want to freeze in the viewport.
|>
|>So:
|>
|>1. declare a variable of type
Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection (make sure you NEW
this)
|>[code]
|>Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDList =new
Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
|>[/code]
|>2. add the object ids of the layers you want to freeze to this
|>[code]
|>IDList.Add(Layer.ObjectID);
|>[/code]
|>3. call the FreezeLayersInViewport method passing the collection of Layer
ObjectIDs to freeze
|>[code]
|>viewport.FreezeLayersInViewport(IDList);
|>[/code]
|>
|>Should do it for ya,
|>C
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 8 of 8
Anonymous
in reply to: Anonymous

Thanks J,
Very nice article, much appreciated.
I think I am getting the idea now, the ienumerator is simply an object that contains whatever the class definition tells
it to. That makes perfect sense because looping is so common, and being able to control what get exposed from a
collection or array or whatever is very useful.
good stuff.

J. Daniel Smith
|>Like many (maybe even most) things in programing, an enumerator is an
|>abstraction: rather than fix that things are always stored in 0-based
|>arrays, and that you can only walk the array from 0 to n-1, you create an
|>abstraction. This lets you store things in linked lists, stacks, binary
|>trees, XML, etc. and still use the same code to process this data. This
|>abstraction also lets you easily process your data in different ways, for
|>example n-1 to 0 for an array or depth-first vs. breadth-first for a tree.
|>
|>Here (http://msdn2.microsoft.com/en-us/vcsharp/bb264519.aspx) is a recent
|>MSDN article that shows some of the ways these abstractions can be so
|>useful.
|>
|>Parts (much) of the AutoCAD .NET API was designed and implemented with .NET
|>1.0, before the introduction of generics in .NET 2.0. As a result, some of
|>the APIs aren't quite as clear as they could be now with generics. For
|>example, if written today, this API might use IEnumerable rather
|>than just IEnumerable.
|>
|> Dan
|>
|>"James Maeding" wrote in message
|>news:5502479@discussion.autodesk.com...
|>Hey Cougar,
|>lookslike you have to call the getenumerator method for that function, like:
|>
|>vPort.FreezeLayersInViewport(IDList.GetEnumerator())
|>
|>This enumerator concept still does not make sense to me.
|>What actual info does the Enumerator object hold?
|>I am guessing its a pointer to an object in a collection, but not quite
|>sure.
|>
|>I took Tony's advice and found an online forum where people were willing to
|>help...whoops, ended up right here 🙂
|>
|>CougerAC <>
|>|>James,
|>|>
|>|>The method you want to use is expecting you to pass a type that implements
|>the IEnumerable interface. Looking at this method, I can also see that it is
|>expecting the collection to contain ObjectIDs. A good collection to use in
|>this situation is Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection. This
|>collection internally implements the IList interface which in turn
|>implements the IEnumerable interface.
|>|>
|>|>If you look at the method declaration for FreezeLayersInViewport, the name
|>of the variable gives away what you should be passing (layerIDs) or the
|>ObjectIDs of the layers you want to freeze in the viewport.
|>|>
|>|>So:
|>|>
|>|>1. declare a variable of type
|>Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection (make sure you NEW
|>this)
|>|>[code]
|>|>Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDList =new
|>Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
|>|>[/code]
|>|>2. add the object ids of the layers you want to freeze to this
|>|>[code]
|>|>IDList.Add(Layer.ObjectID);
|>|>[/code]
|>|>3. call the FreezeLayersInViewport method passing the collection of Layer
|>ObjectIDs to freeze
|>|>[code]
|>|>viewport.FreezeLayersInViewport(IDList);
|>|>[/code]
|>|>
|>|>Should do it for ya,
|>|>C
|>James Maeding
|>Civil Engineer and Programmer
|>jmaeding - at - hunsaker - dotcom
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom

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