Beispiel #1
0
        /// <summary>
        /// 以名字设置工作视图
        /// </summary>
        /// <param name="viewName"></param>
        /// <returns></returns>
        public static ModelingView SetWorkViewForName(string viewName)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Layout       layout1       = ((NXOpen.Layout)workPart.Layouts.FindObject("L1"));
            NXOpen.ModelingView modelingView1 = null;
            try
            {
                modelingView1 = workPart.ModelingViews.FindObject(viewName) as ModelingView;
            }
            catch
            {
            }
            if (modelingView1 == null)
            {
                return(null);
            }
            try
            {
                layout1.ReplaceView(workPart.ModelingViews.WorkView, modelingView1, true);
                return(modelingView1);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("LayerUtils.SetWorkViewForName            " + ex.Message);
                throw ex;
            }
        }
        /// <summary>
        /// 创建主视图
        /// </summary>
        /// <param name="viewName"></param>
        /// <param name="point"></param>
        /// <param name="scaleNumerator"></param>
        /// <param name="mat"></param>
        /// <param name="hiddenComp"></param>
        /// <returns></returns>
        public static BaseView CreateView(string view, Point3d point, double scaleNumerator, Matrix4 mat, params NXOpen.Assemblies.Component[] hiddenComp)
        {
            Part    workPart = theSession.Parts.Work;
            Point3d origin   = new Point3d(0, 0, 0);
            Matrix4 inver    = mat.GetInversMatrix();

            inver.ApplyPos(ref origin);
            Vector3d  xVec = mat.GetXAxis();
            Vector3d  zVec = mat.GetZAxis();
            Direction zDir = workPart.Directions.CreateDirection(origin, zVec, NXOpen.SmartObject.UpdateOption.AfterModeling);
            Direction xDir = workPart.Directions.CreateDirection(origin, xVec, NXOpen.SmartObject.UpdateOption.AfterModeling);

            NXOpen.Drawings.BaseView        nullNXOpen_Drawings_BaseView = null;
            NXOpen.Drawings.BaseViewBuilder baseViewBuilder1;
            baseViewBuilder1 = workPart.DraftingViews.CreateBaseViewBuilder(nullNXOpen_Drawings_BaseView);
            NXOpen.ModelingView modelingView1 = (NXOpen.ModelingView)workPart.ModelingViews.FindObject(view);
            baseViewBuilder1.SelectModelView.SelectedView   = modelingView1;
            baseViewBuilder1.Placement.Associative          = false;
            baseViewBuilder1.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry;
            baseViewBuilder1.Style.ViewStyleBase.Part       = workPart;
            baseViewBuilder1.Style.ViewStyleOrientation.Ovt.NormalDirection = zDir;
            baseViewBuilder1.Style.ViewStyleOrientation.Ovt.XDirection      = xDir;
            baseViewBuilder1.HiddenObjects.Objects.Add(hiddenComp);
            baseViewBuilder1.Scale.Numerator   = scaleNumerator;
            baseViewBuilder1.Scale.Denominator = 1.0;

            baseViewBuilder1.Placement.Placement.SetValue(null, workPart.Views.WorkView, point);

            try
            {
                return(baseViewBuilder1.Commit() as BaseView);
            }

            catch (NXException ex)
            {
                LogMgr.WriteLog("DrawingUtils:CreateView" + ex.Message);
                throw ex;
            }
            finally
            {
                baseViewBuilder1.Destroy();
            }
        }