Exemple #1
0
        /// <summary>
        /// Sets the 3D view's orientation.
        /// </summary>
        /// <param name="View3D">A Dynamo wrapped View3D</param>
        /// <param name="ViewOrient">A Revit ViewOrientation3D element</param>
        /// <returns name="View3D">A Dynamo wrapped View3D</returns>
        public static dynaView3D SetViewOrientation(dynaView3D View3D, revitViewOrientation ViewOrient)
        {
            revitView3D rView    = (revitView3D)View3D.InternalElement;
            revitDoc    document = rView.Document;

            if (document.IsModifiable)
            {
                TransactionManager.Instance.EnsureInTransaction(document);
                rView.SetOrientation(ViewOrient);
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                {
                    trans.Start("Set view orientation");
                    rView.SetOrientation(ViewOrient);
                    trans.Commit();
                }
            }
            return(View3D);
        }
Exemple #2
0
        void ReconstructView3DByPlane
        (
            DB.Document doc,
            ref DB.View3D view,

            Rhino.Geometry.Plane plane,
            Optional <DB.ElementType> type,
            Optional <string> name,
            Optional <bool> perspective
        )
        {
            SolveOptionalType(ref type, doc, DB.ElementTypeGroup.ViewType3D, nameof(type));

            var orientation = new DB.ViewOrientation3D
                              (
                plane.Origin.ToXYZ(),
                plane.YAxis.ToXYZ(),
                plane.ZAxis.ToXYZ()
                              );

            if (view is null)
            {
                var newView = perspective.IsNullOrMissing ?
                              DB.View3D.CreatePerspective
                              (
                    doc,
                    type.Value.Id
                              ) :
                              DB.View3D.CreateIsometric
                              (
                    doc,
                    type.Value.Id
                              );

                var parametersMask = new DB.BuiltInParameter[]
                {
                    DB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
                    DB.BuiltInParameter.ELEM_FAMILY_PARAM,
                    DB.BuiltInParameter.ELEM_TYPE_PARAM
                };

                newView.SetOrientation(orientation);
                view.get_Parameter(DB.BuiltInParameter.VIEWER_CROP_REGION).Set(0);
                ReplaceElement(ref view, newView, parametersMask);
            }
            else
            {
                view.SetOrientation(orientation);

                if (perspective.HasValue)
                {
                    view.get_Parameter(DB.BuiltInParameter.VIEWER_PERSPECTIVE).Set(perspective.Value ? 1 : 0);
                }

                ChangeElementTypeId(ref view, type.Value.Id);
            }

            if (name.HasValue && view is object)
            {
                try { view.Name = name.Value; }
                catch (Autodesk.Revit.Exceptions.ArgumentException e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, $"{e.Message.Replace($".{Environment.NewLine}", ". ")}");
                }
            }
        }