.NET

Reply
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 1 of 7 (257 Views)
Accepted Solution

Find Clip Id from NonRectangularViewPort Object ID t?

257 Views, 6 Replies
12-04-2012 09:14 PM

Hello,

Need help  and could not find a solution for it.

I have  the ID of non rectangular view port and I need to find the Polyline attached to it.

How do you do that ?

Thanks,

 

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(Rivilis.Lesson))]
namespace Rivilis
{
public class Lesson
{
[CommandMethod("TestViewport")]
public void TestViewport()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptSelectionResult res = ed.GetSelection();
if (res.Status == PromptStatus.OK) {
using (Transaction t = doc.TransactionManager.StartTransaction()) {
foreach (ObjectId id in res.Value.GetObjectIds()) {
Viewport vp = t.GetObject(id, OpenMode.ForRead) as Viewport;
if (vp != null) {
ObjectId idPoly = vp.NonRectClipEntityId;
if (!idPoly.IsNull) {
// ObjectId of polyline
ed.WriteMessage("\nid = {0} NonRectClipEntityId = {1}", id, idPoly);
}
else {
ed.WriteMessage("\nid = {0} Viewport is not clipping with polyline", id);
}
}
else {
ed.WriteMessage("\nid = {0} is not Viewport", id);
}
}
t.Commit();
}
}
}
}
}

 

http://www.developerfusion.com/tools/convert/csharp-to-vb/  for converting C# to VB.NET

 

Moderator
Alexander.Rivilis
Posts: 1,446
Registered: ‎04-09-2008
Message 2 of 7 (251 Views)

Re: Find Clip Id from NonRectangularViewPort Object ID t?

12-04-2012 09:52 PM in reply to: JanetDavidson

Hi, Janet!

Please attach a simplest dwg-file with such viewport and correspondent Polyline.

 

P.S.: Maybe method Viewport.NonRectClipEntityId can help you?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 3 of 7 (249 Views)

Re: Find Clip Id from NonRectangularViewPort Object ID t?

12-04-2012 09:58 PM in reply to: JanetDavidson

Hi,

 

Once you have a viewport ObjectId, use viewport.NonRectClipEntityId (that should be not ObjectId.Null) to get its non-rectangular viewport, see the following code snippet:

 

transaction.GetObject(viewport.NonRectClipEntityId, OpenMode.ForRead) as Polyline

 

-Khoa

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 4 of 7 (231 Views)

Re: Find Clip Id from NonRectangularViewPort Object ID t?

12-05-2012 05:11 AM in reply to: JanetDavidson

Thanks Khao for your time,

 Actually My Problem it the otherway around.  I mean I want the PolyLine ObjectId of sorrouding ViewPort (Which I have the ID.

 

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 5 of 7 (230 Views)

Re: Find Clip Id from NonRectangularViewPort Object ID t?

12-05-2012 05:11 AM in reply to: Alexander.Rivilis

Hi Alex,

I need the object ID of Polyline which is attached to viewport.

 

Moderator
Alexander.Rivilis
Posts: 1,446
Registered: ‎04-09-2008
Message 6 of 7 (221 Views)

Re: Find Clip Id from NonRectangularViewPort Object ID t?

12-05-2012 05:52 AM in reply to: JanetDavidson
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(Rivilis.Lesson))]

namespace Rivilis
{
  public class Lesson
  {
    [CommandMethod("TestViewport")]
    public void TestViewport()
    {
      Document doc = Application.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;
      PromptSelectionResult res = ed.GetSelection();
      if (res.Status == PromptStatus.OK) {
        using (Transaction t = doc.TransactionManager.StartTransaction()) {
          foreach (ObjectId id in res.Value.GetObjectIds()) {
            Viewport vp = t.GetObject(id, OpenMode.ForRead) as Viewport;
            if (vp != null) {
              ObjectId idPoly = vp.NonRectClipEntityId;
              if (!idPoly.IsNull) {
                // ObjectId of polyline
                ed.WriteMessage("\nid = {0} NonRectClipEntityId = {1}", id, idPoly);
              }
              else {
                ed.WriteMessage("\nid = {0} Viewport is not clipping with polyline", id);
              }
            }
            else {
              ed.WriteMessage("\nid = {0} is not Viewport", id);
            }
          }
          t.Commit();
        }
      }
    }
  }
}

 

http://www.developerfusion.com/tools/convert/csharp-to-vb/  for converting C# to VB.NET

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 7 of 7 (189 Views)

Re: Find Clip Id from NonRectangularViewPort Object ID t?

12-05-2012 07:15 PM in reply to: Alexander.Rivilis

 

Alex Thank you so much. That was it.

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post