.NET

Reply
Active Member
10 Posts
0 Kudos
Registered: ‎05-31-2005
Post 1 of 4

Find blocks in viewports?

127 Views, 3 Replies
05-31-2005 01:59 PM
I am trying to write a routine that will iterate though all the viewports in a drawing and determine what blocks are contained within which viewports. I'm not sure the best way to go about this, but here's the path that I've started down:

1. Loop through all objects in paperspace and get all of the viewport objects
2. Loop through all the blocks in the BlockTable
3. For each block loop through all of the BlockReference instances
4. Get the coordinates of the BlockReference and determine if it is inside one of the viewports.

I'm having a problem with step 4 in that I'm not sure how to get the ModelSpace coordinates of the viewports. Any ideas as to how this might be done? Also, if anyone has any ideas of an easier way to go about this, I'm all ears.

Thanks!
Brian
*Albert Szilvasy
Post 2 of 4

Re: Find blocks in viewports?

06-01-2005 07:16 PM in reply to: brianroth
Look at the ViewTarget, ViewHeight, ViewWidth properties for the viewport. I
think that's what you are looking for. Actually, an easier way to do this
would be to simply calculate the view rectangle for each viewport and use
that as input Editor.SelectCrossingWindow.

Albert

wrote in message news:4861198@discussion.autodesk.com...
I am trying to write a routine that will iterate though all the viewports in
a drawing and determine what blocks are contained within which viewports.
I'm not sure the best way to go about this, but here's the path that I've
started down:

1. Loop through all objects in paperspace and get all of the viewport
objects
2. Loop through all the blocks in the BlockTable
3. For each block loop through all of the BlockReference instances
4. Get the coordinates of the BlockReference and determine if it is inside
one of the viewports.

I'm having a problem with step 4 in that I'm not sure how to get the
ModelSpace coordinates of the viewports. Any ideas as to how this might be
done? Also, if anyone has any ideas of an easier way to go about this, I'm
all ears.

Thanks!
Brian
Active Member
10 Posts
0 Kudos
Registered: ‎05-31-2005
Post 3 of 4

Re: Find blocks in viewports?

06-02-2005 01:24 PM in reply to: brianroth
Thanks, Albert! Worked like a charm.

Brian
Contributor
11 Posts
0 Kudos
Registered: ‎12-02-2007
Post 4 of 4

Re: Find blocks in viewports?

12-13-2007 08:58 PM in reply to: brianroth
any other way to do this?? Editor.SelectCrossingWindow didnt help me as i am not opening the drawing... this is what i am doing.

db1.ReadDwgFile(@"c:\ll.dwg", System.IO.FileShare.Read, false, "");

Transaction trans1 = db1.TransactionManager.StartTransaction();

BlockTable bt = (BlockTable)trans1.GetObject(db1.BlockTableId, OpenMode.ForRead);

foreach (ObjectId btrid in bt)
{

BlockTableRecord btr = (BlockTableRecord)trans1.GetObject(btrid, OpenMode.ForRead);

.
.
.
.
.
}
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!