Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Viewport Properties

1 REPLY 1
SOLVED
Reply
Message 1 of 2
grahamcook
698 Views, 1 Reply

Viewport Properties

Hi

Anyone know if its possible to access the "type" properties of a viewport via the API.  After creating a new viewport object i'd like to be able to change the type as highlighted in the image below.  This snapshot was taken after selecting a viewport.  I'm using 2013.

 

Thanks.

 

viewPort_Properties.JPG

 

1 REPLY 1
Message 2 of 2
grahamcook
in reply to: grahamcook

I figured this one out in the end.  Viewport is system family that has types, the types represented the items in the menu in the original post above.  So i grabbed the first viewport object on the model, looped through the types until the type name matched the name i was looking for.  This gave me the id of the type i needed so i could then set the type of the viewport using the viewport.ChangeTypeId method.  Code below assumes vp is the new View Port.

 

Viewport firstViewPort = new FilteredElementCollector(doc)
    .OfClass(typeof(Viewport)).Cast<Viewport>().FirstOrDefault<Viewport>();

ICollection<ElementId> vpt = firstViewPort.GetValidTypes();

foreach (ElementId e in vpt)
{
    ElementType type = doc.GetElement(e) as ElementType;

    // Edit line to suit or pass in variable
    if (type.Name == "Title w Line")
    {
        vp.ChangeTypeId(type.Id);
    }
}

 

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


Rail Community