how to change camera

how to change camera

Anonymous
Not applicable
2,904 Views
6 Replies
Message 1 of 7

how to change camera

Anonymous
Not applicable

Hello,

How to change current view to perspective mode and use given EyePoint, TargetPoint, and FieldofView?

0 Likes
Accepted solutions (1)
2,905 Views
6 Replies
Replies (6)
Message 2 of 7

rosalesduquej
Alumni
Alumni
Accepted solution

Hello,

 

The best way to get started will be reading about the View3D class and its members. One that comes to mind is the CreatePerspective one based on your question.

 

Check the following link http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-A7FA8DBC-830E-482D-9B66-147399524442 

 

In there you will find a snippet of code in order to create a perspective view.

 

// Find a 3D view type
IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType))
                                                let type = elem as ViewFamilyType
                                                where type.ViewFamily == ViewFamily.ThreeDimensional
                                                select type;
// Create a new Perspective View3D
View3D view3D = View3D.CreatePerspective(document, viewFamilyTypes.First().Id);
if (null != view3D)
{
    // By default, the 3D view uses a default orientation.
    // Change the orientation by creating and setting a ViewOrientation3D 
    XYZ eye = new XYZ(0, -100, 10); 
    XYZ up = new XYZ(0, 0, 1); 
    XYZ forward = new XYZ(0, 1, 0); 
    view3D.SetOrientation(new ViewOrientation3D(eye, up, forward));

    // turn off the far clip plane with standard parameter API
    Parameter farClip = view3D.LookupParameter("Far Clip Active");
    farClip.Set(0);
}

Cheers, 



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
0 Likes
Message 3 of 7

Anonymous
Not applicable
0 Likes
Message 4 of 7

rosalesduquej
Alumni
Alumni

Remy, Just beat you by 30 seconds 😉 

 

Hehe,

Cheers,



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Message 5 of 7

Anonymous
Not applicable
LOL
0 Likes
Message 6 of 7

Anonymous
Not applicable

Seems SetOrientation can set view direction.

Is there an API to set field of view?

thanks!

0 Likes
Message 7 of 7

rosalesduquej
Alumni
Alumni

Hi,

 

So setting the Field of View from the UI means cropping the region right? 

 

use one of the following methods:

  • select the perspective view, and drag the controls to change the field of view, also referred to as the crop region
  • click Modify | Cameras tabCrop panel (Size Crop)

If you check the link I shared with you before, there is also another section which is called View Cropping which basically does this action. 

 

The ViewCropRegionShapeManager.Valid property indicates whether the view is allowed to manage the crop region shape while the ShapeSet property indicates whether a shape has been set. The following example crops a view around the boundary of a room.

 

public void CropAroundRoom(Room room, View view)
{
    if (view != null)
    {
        IList<IList<Autodesk.Revit.DB.BoundarySegment>>  segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

        if (null != segments)  //the room may not be bound
        {
            foreach (IList<Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
            {
                CurveLoop loop = new CurveLoop();
                foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
                {
                    loop.Append(boundarySegment.Curve);
                }

                ViewCropRegionShapeManager vcrShapeMgr = view.GetCropRegionShapeManager();
                vcrShapeMgr.SetCropRegionShape(loop);
                break;  // if more than one set of boundary segments for room, crop around the first one
            }
        }
    }
}

I haven't tried it myself but it seems like can point you out in the right direction. 

 

Cheers,

 

 



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
0 Likes