Cannot convert type Reference to Viewport via reference conversion

Cannot convert type Reference to Viewport via reference conversion

Anonymous
Not applicable
1,687 Views
1 Reply
Message 1 of 2

Cannot convert type Reference to Viewport via reference conversion

Anonymous
Not applicable

Hello,

 

I want to make a selection of multiple elements(viewports), and this selection, I want it to be by "PickObjects" and not "PickByRectangle". So, when trying to implement the following lines of code in order to make the desired selection, I come up with a conversion error. This error states the following:

 

 

Error CS0039: Cannot convert type 'Autodesk.Revit.DB.Reference' to 'Autodesk.Revit.DB.Viewport' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
Build failed.

 

The code is: 

 

ISelectionFilter viewportfilter = new ViewPortPickFilter();
Selection choices = uidoc.Selection;

 

IList<Reference> refa = choices.PickObjects(ObjectType.Element,viewportfilter, "Pick multiple elements one by one");

 

foreach(Reference vp in refa)
{
  var e = vp as Viewport;        
}

 

I have tried changing IList<Reference> for <Viewport> and the pertinent modifications, however, then the issue is on choices, stating that it cannot convert type reference to viewport once again...

 

Thus, If someone could give me a generic way of PickObjects. It would be really appreciated.

 

Thanks in advance! 

 

0 Likes
Accepted solutions (1)
1,688 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

Hey ljnuin,

 

Get the Element from that reference,

 

 

foreach(Reference vp in refa)
{
 Viewport viewp= doc.GetElement(vp) as Viewport;

 

 //do something...


}