public void CurentViewpoint_Save()
        //Get current viewpoint and save it to items
        {
            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            // Create the saved viewpoint with the new viewpoint
            SavedViewpoint oNewVP = new SavedViewpoint(oDoc.CurrentViewpoint.ToViewpoint());

            oNewVP.DisplayName = "MySavedView";

            //Add viewpoint to saved items
            oDoc.SavedViewpoints.AddCopy(oNewVP);
        }
        public void HomeViewpoint_IfSet()
        //Get home viewpoint (if it was set) and save it to items
        {
            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            try
            {
                // Create the saved viewpoint with the new viewpoint
                SavedViewpoint oNewVP = new SavedViewpoint(oDoc.HomeView);

                oNewVP.DisplayName = "MyHomeView";

                //Add viewpoint to saved items
                oDoc.SavedViewpoints.AddCopy(oNewVP);

                //Set current viewpoint to oNewVP
                oDoc.CurrentViewpoint.CopyFrom(oNewVP.Viewpoint);
            }
            catch (Exception e)
            {
                MessageBox.Show("No set home view in model!" + "\n\n" + e);
            };
        }
Example #3
0
        public override int Execute(params string[] parameters)
        {
            // document
            Document doc = Application.ActiveDocument;

            // make a copy of current viewpoint
            Viewpoint vpoint = doc.CurrentViewpoint.CreateCopy();

            #region MoveCamera

            // move to the new position
            // get the position of the camera
            Point3D curPos = vpoint.Position;
            // create a position in 3D space
            Point3D newPos = new Point3D(curPos.X + 10, curPos.Y, curPos.Z);
            // set viewpoint camera value
            vpoint.Position = newPos;
            // update the current view point
            doc.CurrentViewpoint.CopyFrom(vpoint);


            #endregion MoveCamera

            #region RotateCamera

            // collect the rotational axis and angle
            AxisAndAngleResult axisAngleResult = vpoint.Rotation.ToAxisAndAngle();
            // A vector with unit length, represents a direction in 3D space.
            UnitVector3D axis = axisAngleResult.Axis;
            // angle in radians
            double angle = axisAngleResult.Angle;

            // to set values
            // creates a new angle value (10 degree)
            double newAngle = 10 * (3.14 / 180);
            // creates a new axis to rotate (z axis)
            UnitVector3D newAxis = new UnitVector3D(0, 0, 1);
            // creates rotation about given axis by angle in radians (Quaternion)
            Rotation3D newRotation = new Rotation3D(newAxis, newAngle);

            // multiply the current 3D Rotation value with the new value
            vpoint.Rotation = Multiply(vpoint.Rotation, newRotation);

            // update the current viewpoint
            doc.CurrentViewpoint.CopyFrom(vpoint);

            SavedViewpoint savedViewpoint = new SavedViewpoint(vpoint);
            savedViewpoint.DisplayName = "Lab10_Viewpoint";
            doc.SavedViewpoints.AddCopy(savedViewpoint);

            /*
             * f.MessageBox.Show(String.Format("{0}", newAngle));
             * f.MessageBox.Show(String.Format("{0} {1} {2} {3}", newRotation.A,newRotation.B,
             *      newRotation.C,newRotation.D));
             *
             * f.MessageBox.Show(String.Format("Axis : {0} , Angle : {1} ",
             * axis.ToString(),angle.ToString()));
             */


            #endregion RotateCamera


            return(0);
        }
        /// <summary>
        /// Set Appearance from color to selection
        /// </summary>
        /// <param name="input"></param>
        /// <param name="color"></param>
        /// <returns>Returns input</returns>
        private object setAppearanceBySelections(object input, object color, object transparency)
        {
            object   output = null;
            Document doc    = Autodesk.Navisworks.Api.Application.ActiveDocument;

            if (input != null)
            {
                if (input is SelectionSet)
                {
                    double t = transparency != null ? (double.Parse(transparency.ToString())) / 100: -1;

                    var CurrentColor = color != null?TransformColor((media.Color) color) : null;

                    if (Override)
                    {
                        foreach (object item in SavedViewpoints)
                        {
                            SavedItemReference vp = item as SavedItemReference;
                            if (vp != null)
                            {
                                SavedViewpoint current = doc.SavedViewpoints.ResolveReference(vp) as SavedViewpoint;
                                doc.ActiveView.CopyViewpointFrom(current.Viewpoint, ViewChange.JumpCut);
                                ApplyAppearance(input as SelectionSet, CurrentColor, t);
                                doc.ActiveView.RequestDelayedRedraw(ViewRedrawRequests.All);
                                doc.SavedViewpoints.ReplaceFromCurrentView(current);
                            }
                        }
                    }
                    ApplyAppearance(input as SelectionSet, CurrentColor, t);
                }

                if (input is ModelItem)
                {
                    List <ModelItem> searchs = new List <ModelItem>()
                    {
                        input as ModelItem
                    };

                    //Convert ARGB Alpha to normaliced transparency
                    double t = transparency != null ? (int.Parse(transparency.ToString())) * 100 : -1;


                    var CurrentColor = color != null?TransformColor((media.Color) color) : null;

                    if (Override)
                    {
                        foreach (object item in SavedViewpoints)
                        {
                            SavedItemReference vp = item as SavedItemReference;
                            if (vp != null)
                            {
                                SavedViewpoint current = doc.SavedViewpoints.ResolveReference(vp) as SavedViewpoint;
                                doc.ActiveView.CopyViewpointFrom(current.Viewpoint, ViewChange.JumpCut);
                                ApplyAppearance(input as SelectionSet, CurrentColor, t);
                                doc.ActiveView.RequestDelayedRedraw(ViewRedrawRequests.All);
                                doc.SavedViewpoints.ReplaceFromCurrentView(current);
                            }
                        }
                    }

                    ApplyAppearance(input as ModelItem, CurrentColor, t);
                }
            }
            output = input;
            return(output);
        }