how to select rectangle and polygonal viewport.

how to select rectangle and polygonal viewport.

Anonymous
Not applicable
2,379 Views
7 Replies
Message 1 of 8

how to select rectangle and polygonal viewport.

Anonymous
Not applicable

The following allows you to select a rectangle viewport

objVP .AddAllowedClass(GetType(Viewport), True)

how do you allow the user to select a rectangle viewport as well as a Polygonal viewport

 

 Dim objVP As PromptEntityOptions
        objVP = New PromptEntityOptions(vbCrLf & "Select a viewport: ")
        objVP .AllowNone = False
        objVP .SetRejectMessage(vbCrLf & "Need to select a viewport!")
        objVP .AddAllowedClass(GetType(Viewport), True)
        Dim er As PromptEntityResult = ed.GetEntity(objVP )

 

0 Likes
Accepted solutions (1)
2,380 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

That is how you would select it, but the problem is that when a viewport is associated with an other object, the other object is on top of it within the drawing.  I'm not sure in .Net how to see the relationship, but in Lisp you can see it pretty easily.

 

Entget of entity selected:
(-1 . <Entity name: -4af86ce8>)
(0 . "LWPOLYLINE")
(5 . "113")
(102 . "{ACAD_REACTORS")
(330 . <Entity name: -4af86cd8>)  <-  This is a viewport entity.
(102 . "}")
(330 . <Entity name: -4af8d2c0>)
(100 . "AcDbEntity")
(67 . 1)
(410 . "Layout1")
(8 . "0")
(100 . "AcDbPolyline")
(90 . 5)

<snip>

 

Not much help, but hope it helps a little.

0 Likes
Message 3 of 8

cadMeUp
Collaborator
Collaborator

Check out the attached C# code, will give you the idea. In AutoCAD 2011 you have to be aware of the 'SELECTIONCYCLING' system variable as well.

0 Likes
Message 4 of 8

Anonymous
Not applicable

Thanks, once again for pointing me in the right direction.

 

So what I gather is that a Poly VP is both a Pline and a viewport linked.

thus I need to set both types in my filter selection list (if I have the correct terminology)

 

so this is what I have

        Dim eo As PromptEntityOptions
        eo = New PromptEntityOptions(vbCrLf & "Select a viewport: ")
        eo.AllowNone = False
        eo.SetRejectMessage(vbCrLf & "Need to select a viewport!")
        eo.AddAllowedClass(GetType(Viewport), False)
        eo.AddAllowedClass(GetType(Polyline), False)

        Dim er As PromptEntityResult = ed.GetEntity(eo)
        If er.Status <> PromptStatus.OK Then
            Exit Sub
        End If


        If er.GetType() =  typeof(Viewport) then
            Dim vpId As ObjectId = er.ObjectId
        Else
            Dim vpId = LayoutManager.Current.GetNonRectangularViewportIdFromClipId(er.ObjectId)
        End If

However I do not have the correct code to determine if the selection is a rectangle VP or a Pline VP.

If er.GetType() =  typeof(Viewport) then (this does not compile)
forgive a newbie question, but I am just migrating from VBA.

So how do I check the type, and if you are inclined to comment on my codeing structure, please feel free to do so.

 

        If er.GetType() =  typeof(Viewport) then
            Dim vpId As ObjectId = er.ObjectId
        Else
            Dim vpId = LayoutManager.Current.GetNonRectangularViewportIdFromClipId(er.ObjectId)
        End If

 

thanks

 

 

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

An easier way might be to go with a selection set ( GetSelection ), with setting the PromptSelectionOptions propertys of SelectEverythingInAperture to true, and SinglePickInSpace to true, and set the filter like to do to only allow Viewports.

 

Sorry I'm not more helpful.

0 Likes
Message 6 of 8

cadMeUp
Collaborator
Collaborator
Accepted solution

The line:

If er.GetType() =  typeof(Viewport) then

 

is checking if er is a Viewport, but er is a PromptEntityResult object:

Dim er As PromptEntityResult = ed.GetEntity(eo)

 

So it could never equal a Viewport type. You have to get the object from the ObjectId returned from GetEntity() and then make the type comparison from there, something like:

 

Dim entId As ObjectId = er.ObjectId
Dim selEnt As Entity = entId.GetObject(OpenMode.ForRead)
If selEnt.GetType() Is GetType(Viewport) Then
 'Viewport
ElseIf selEnt.GetType() Is GetType(Polyline) Then
 'Polyline
End If 

 

I attached the equivalent code in VB...

0 Likes
Message 7 of 8

Anonymous
Not applicable

I am going to have to get used to this idea of every time I want to examine an object, I have to start a transition etc

Cheers thanks for all your help

0 Likes
Message 8 of 8

Rockit_for_Revit
Advocate
Advocate

Hi All,

Can anyone assist getting the viewport selection for the attached sample?

It seems that the viewport in this case is a Polyline and not a LWPolyline which is generally the case.

When I use the code:

Dim eo As PromptEntityOptions
        eo = New PromptEntityOptions(vbCrLf & "Select a viewport: ")
        eo.AllowNone = False
        eo.SetRejectMessage(vbCrLf & "Need to select a viewport!")
        eo.AddAllowedClass(GetType(Viewport), False)
        eo.AddAllowedClass(GetType(Polyline), False)

All I get is:

Need to select a viewport!

 

Kind Regards

David