VB.NET to select object in paperspace and get Layout name

VB.NET to select object in paperspace and get Layout name

Sgear
Advocate Advocate
2,381 Views
3 Replies
Message 1 of 4

VB.NET to select object in paperspace and get Layout name

Sgear
Advocate
Advocate

Hi


somtime I have 5 Layout or more

is it poseble in VB.NET to select object in paperspace and get Layout name if the Object ar in any Viewport

 

Regards

Sgear

0 Likes
Accepted solutions (1)
2,382 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

You may want to clarify this:

 

...if the Object ar in any Viewport 

 

When you say "Viewport", I assume it is a Viewport opened on given layout (PaperSpace).

 

Does "Objects are in any Viewport" mean objects in ModelSpace that can be seen in the Viewport on layout? If so, these objects are in ModelSpace obviously.

 

Or Do you mean objects actually in the PaperSpace of the layout but happen to sit in the area where a Viewport covers. In this case, why even mention Viewport? It has nothing to do with finding these objects' layout name.

 

But since you say "select object in paperspace and get Layout name", you can find any entity's layout name (including "Model" for ModelSpace, like this  extension method (not tested):

 

Public static string GetEntityLayoutName(this ObjectId entId)

{

  var layoutName="";

  using (var tran = entId.Database.TransactionManager.StartTransaction())

  {

    var ent = (Entity) tran.GetObject(entId, OpenMode.ForRead);

    var owner = (BlockTableRecord)tran.GetObject(ent.OwnerId, OpenMode.ForRead);

    If (owner.IsLayout)

    {

      var layout = (Layout)tran.GetObject(owner.LayoutId, OpenMode.ForRead);

      layoutName = layout.LayoutName;

    }

    tran.Commit();

  }

  return layoutName;

}

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

Sgear
Advocate
Advocate

Sorry the text was not right

 

1. the object are in ModelSpace that can be seen in the Viewport on layout

I have large drawing with 10 or more Layout I need to select object in ModelSpace and get the layout name

 

see attachment
1. if I select Object 1 or 2 I get the name "Layout-A4-name1"
2. if I select Object 3 or 4 I get the name "Layout-A4-name2"
3. if I select Object 5 Nothing happens object 5 can not seen in the Viewport on layout

0 Likes
Message 4 of 4

norman.yuan
Mentor
Mentor
Accepted solution

So, your goal is to identify/select entities in MOdalSpace which can be seen from a Viewport on a paperspace layout . In this case, how many layouts, how many viewpoers on these layouts does not matter, as long as you can identify entities with a given Viewport (I say this because in your original post you mention "5 Layouts or more" and also emphasized in next reply with "large drawing with 10 or more layouts).

 

So, basically, for any given paperspace viewport, you need to find its corner coordinates (be it rectangle or non-rectangle) in PaperSpace, and then translate them into ModelSpace coordinate, thus you'll have points for a window/closed polygon in ModelSpace. Now, you can find which entities are enclosed inside it. YOu can use Editor.SelectWindow[CrossingPolygon]() to select entities (you need to switch AutoCAD to ModelSpace), or you can write code to test if an entity is inside the window/plygon.

 

I do have a post quite a few years ago on how to select Entities in ModelSpace through a paperspace viewport:

 

https://drive-cad-with-code.blogspot.com/2014/03/selecting-entities-in-modelspace.html

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes