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

Find blocks in viewports?

3 REPLIES 3
Reply
Message 1 of 4
brianroth
360 Views, 3 Replies

Find blocks in viewports?

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
3 REPLIES 3
Message 2 of 4
Anonymous
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
Message 3 of 4
brianroth
in reply to: brianroth

Thanks, Albert! Worked like a charm.

Brian
Message 4 of 4
anupb123
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);

.
.
.
.
.
}

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