.NET

Reply
Active Member
brianroth
Posts: 10
Registered: ‎05-31-2005
Message 1 of 4 (118 Views)

Find blocks in viewports?

118 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
Message 2 of 4 (118 Views)

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
brianroth
Posts: 10
Registered: ‎05-31-2005
Message 3 of 4 (118 Views)

Re: Find blocks in viewports?

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

Brian
Contributor
anupb123
Posts: 11
Registered: ‎12-02-2007
Message 4 of 4 (118 Views)

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

.
.
.
.
.
}
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.