Пример #1
0
        /// <summary>
        /// 设置属性表达式
        /// </summary>
        /// <param name="expName"></param>
        /// <param name="attrName"></param>
        /// <param name="type"></param>
        /// <param name="attNumber">属性组号</param>
        public static Expression SetAttrExp(string expName, string attrName, NXObject.AttributeType type, int attNumber)
        {
            Part workPart = theSession.Parts.Work;

            try
            {
                Expression exp = workPart.Expressions.GetAttributeExpression(workPart, attrName, type, attNumber);
                exp.SetName(expName);
                return(exp);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("ExpressionUtils:SetAttrExp:表达式" + expName + "               " + ex.Message);
                throw ex;
            }
        }
Пример #2
0
        public static NXObject CreatePullFace(Vector3d vec, double pull, params Face[] faces)
        {
            Session theSession = Session.GetSession();
            Part    workPart   = theSession.Parts.Work;

            NXOpen.Features.PullFace        nullNXOpen_Features_PullFace = null;
            NXOpen.Features.PullFaceBuilder pullFaceBuilder1;
            pullFaceBuilder1 = workPart.Features.CreatePullFaceBuilder(nullNXOpen_Features_PullFace);

            pullFaceBuilder1.Motion.DistanceAngle.OrientXpress.AxisOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Axis.Passive;

            pullFaceBuilder1.Motion.DistanceAngle.OrientXpress.PlaneOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Plane.Passive;

            pullFaceBuilder1.Motion.AlongCurveAngle.AlongCurve.IsPercentUsed = true;

            NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);

            NXOpen.Direction direction1;
            direction1 = workPart.Directions.CreateDirection(origin1, vec, NXOpen.SmartObject.UpdateOption.WithinModeling);

            pullFaceBuilder1.Motion.DistanceVector = direction1;

            NXOpen.FaceDumbRule faceDumbRule;
            faceDumbRule = workPart.ScRuleFactory.CreateRuleFaceDumb(faces);

            NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
            rules1[0] = faceDumbRule;
            pullFaceBuilder1.FaceToPull.ReplaceRules(rules1, false);

            pullFaceBuilder1.Motion.DistanceValue.RightHandSide = pull.ToString();

            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = pullFaceBuilder1.Commit();
                return(nXObject1);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("PullFaceUtils:CreatePullFace:      " + ex.Message);
                return(null);
            }
            finally
            {
                pullFaceBuilder1.Destroy();
            }
        }
Пример #3
0
        /// <summary>
        /// 创建装配明细表
        /// </summary>
        /// <param name="templatePath">模板地址</param>
        /// <param name="origin"></param>
        public static void CreatePlist(string templatePath, double[] origin)
        {
            Tag partsList = Tag.Null;
            Tag row       = Tag.Null;

            try
            {
                theUFSession.Plist.CreateFromTemplate(templatePath, origin, out partsList);
                theUFSession.Tabnot.AskNthRow(partsList, 0, out row);
                theUFSession.Tabnot.RemoveRow(row);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("DrawingUtils.CreatePlist" + ex.Message);
                throw ex;
            }
        }
Пример #4
0
        public static Point CreatePoint(Point3d point)
        {
            Tag pointTag = Tag.Null;

            try
            {
                theUFSession.Curve.CreatePoint(new double[3] {
                    point.X, point.Y, point.Z
                }, out pointTag);
                return(NXObjectManager.Get(pointTag) as Point);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("PointUtils:CreatePoint  创建点错误");
                throw ex;
            }
        }
Пример #5
0
        /// <summary>
        /// 阵列几何特征
        /// </summary>
        /// <param name="obj">阵列对象</param>
        /// <param name="xNCopies">x方向个数</param>
        /// <param name="xPitchDistance">x方向尺寸</param>
        /// <param name="yNCopies">Y方向个数</param>
        /// <param name="yPitchDistance">Y方向尺寸</param>
        /// <returns></returns>
        public static PatternGeometry CreatePattern(string xNCopies, string xPitchDistance, string yNCopies, string yPitchDistance, Matrix4 mat = null, params DisplayableObject[] obj)
        {
            Part workPart = theSession.Parts.Work;

            if (mat == null)
            {
                mat = new Matrix4();
                mat.Identity();
                mat.TransformToCsys(workPart.WCS.CoordinateSystem, ref mat);
            }
            NXOpen.Features.PatternGeometry        nullNXOpen_Features_PatternGeometry = null;
            NXOpen.Features.PatternGeometryBuilder patternGeometryBuilder1;
            patternGeometryBuilder1 = workPart.Features.CreatePatternGeometryBuilder(nullNXOpen_Features_PatternGeometry);
            Direction xDirection;
            Direction yDirection;
            Vector3d  x      = mat.GetXAxis();
            Vector3d  y      = mat.GetYAxis();
            Point3d   origin = mat.GetCenter();
            bool      added1 = patternGeometryBuilder1.GeometryToPattern.Add(obj); //设置要阵列的对象

            patternGeometryBuilder1.PatternService.RectangularDefinition.UseYDirectionToggle = true;

            patternGeometryBuilder1.ReferencePoint.Point = workPart.Points.CreatePoint(origin);                   //指定参考点

            xDirection = workPart.Directions.CreateDirection(origin, x, SmartObject.UpdateOption.WithinModeling); //方向
            yDirection = workPart.Directions.CreateDirection(origin, y, SmartObject.UpdateOption.WithinModeling); //方向
            patternGeometryBuilder1.PatternService.RectangularDefinition.XDirection = xDirection;
            patternGeometryBuilder1.PatternService.RectangularDefinition.YDirection = yDirection;
            patternGeometryBuilder1.PatternService.RectangularDefinition.XSpacing.NCopies.RightHandSide       = xNCopies;       //要阵列的个数(包括本身)
            patternGeometryBuilder1.PatternService.RectangularDefinition.XSpacing.PitchDistance.RightHandSide = xPitchDistance; //设置节距
            patternGeometryBuilder1.PatternService.RectangularDefinition.YSpacing.NCopies.RightHandSide       = yNCopies;       //要阵列的个数(包括本身)
            patternGeometryBuilder1.PatternService.RectangularDefinition.YSpacing.PitchDistance.RightHandSide = yPitchDistance; //设置节距
            try
            {
                return(patternGeometryBuilder1.CommitFeature() as PatternGeometry);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("PatternUtils:CreatePattern:      " + ex.Message);
                throw ex;
            }
            finally
            {
                patternGeometryBuilder1.Destroy();
            }
        }
Пример #6
0
        /// <summary>
        /// 链接到工作部件中(关联)
        /// </summary>
        /// <param name="seleObj">要链接的face</param>
        /// <returns></returns>
        public static NXOpen.Features.Feature WaveFace(params Face[] seleObj)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.Feature         nullNXOpen_Features_Feature = null;
            NXOpen.Features.WaveLinkBuilder waveLinkBuilder1;
            waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullNXOpen_Features_Feature);
            NXOpen.Features.ExtractFaceBuilder extractFaceBuilder1;
            extractFaceBuilder1             = waveLinkBuilder1.ExtractFaceBuilder;
            waveLinkBuilder1.Type           = NXOpen.Features.WaveLinkBuilder.Types.FaceLink;
            extractFaceBuilder1.FaceOption  = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.SingleFace;
            extractFaceBuilder1.ParentPart  = NXOpen.Features.ExtractFaceBuilder.ParentPartType.OtherPart;
            extractFaceBuilder1.Associative = true;

            extractFaceBuilder1.MakePositionIndependent = false;

            extractFaceBuilder1.FixAtCurrentTimestamp = false;

            extractFaceBuilder1.HideOriginal = false;

            extractFaceBuilder1.DeleteHoles = false;

            extractFaceBuilder1.InheritDisplayProperties = false;

            NXOpen.SelectDisplayableObjectList selectDisplayableObjectList1;
            selectDisplayableObjectList1    = extractFaceBuilder1.ObjectToExtract;
            extractFaceBuilder1.Associative = false;

            bool added1;

            added1 = selectDisplayableObjectList1.Add(seleObj);
            try
            {
                return(waveLinkBuilder1.CommitFeature());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:WaveFace:" + ex.Message);
                return(null);
            }
            finally
            {
                waveLinkBuilder1.Destroy();
            }
        }
Пример #7
0
        /// <summary>
        ///  创建修剪特征
        /// </summary>
        /// <param name="planeFace"></param>
        /// <param name="isFlip"></param>
        /// <param name="isok"></param>
        /// <param name="bodys"></param>
        /// <returns></returns>
        public static NXOpen.Features.TrimBody2 CreateTrimBodyFeature(Face planeFace, bool isFlip, out bool isok, params Body[] bodys)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.TrimBody2        nullNXOpen_Features_TrimBody2 = null;
            NXOpen.Features.TrimBody2Builder trimBody2Builder1             = workPart.Features.CreateTrimBody2Builder(nullNXOpen_Features_TrimBody2);
            List <TaggedObject> tgs = new List <TaggedObject>();

            foreach (Body body in bodys)
            {
                tgs.Add(body);
            }
            SelectionRuleFactory fac = new SelectionRuleFactory(tgs);

            NXOpen.Plane plane1 = null;
            try
            {
                plane1 = PlaneUtils.CreatePlaneOfFace(planeFace, isFlip);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("Basic.TrimBody:CreateTrimBodyFeature:" + ex.Message);
                throw ex;
            }
            trimBody2Builder1.BooleanTool.FacePlaneTool.ToolPlane = plane1;
            trimBody2Builder1.BooleanTool.ToolOption = NXOpen.GeometricUtilities.BooleanToolBuilder.BooleanToolType.NewPlane;
            NXOpen.ScCollector scCollector1 = workPart.ScCollectors.CreateCollector();
            scCollector1.ReplaceRules(fac.CreateSelectionRule().ToArray(), false);
            trimBody2Builder1.TargetBodyCollector = scCollector1;

            try
            {
                isok = true;
                return(trimBody2Builder1.CommitFeature() as NXOpen.Features.TrimBody2);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.TrimBody:CreateTrimBodyFeature:" + ex.Message);
                throw ex;
            }
            finally
            {
                trimBody2Builder1.Destroy();
            }
        }
Пример #8
0
        /// <summary>
        /// 新建装配档文件
        /// </summary>
        /// <param name="partName">装配Part名字</param>
        /// <param name="partPath">Part档地址</param>
        /// <returns></returns>
        public static NXObject CreateNew(string partName, string partPath)
        {
            Part    workPart = theSession.Parts.Work;
            FileNew fileNew1 = theSession.Parts.FileNew();

            fileNew1.TemplateFileName         = "molex-plain-1-mm-template.prt";
            fileNew1.UseBlankTemplate         = false;
            fileNew1.ApplicationName          = "ModelTemplate";
            fileNew1.Units                    = NXOpen.Part.Units.Millimeters;
            fileNew1.RelationType             = "";
            fileNew1.UsesMasterModel          = "No";
            fileNew1.TemplateType             = NXOpen.FileNewTemplateType.Item;
            fileNew1.TemplatePresentationName = "Molex";
            fileNew1.ItemType                 = "";
            fileNew1.Specialization           = "";
            fileNew1.SetCanCreateAltrep(false);
            fileNew1.NewFileName       = string.Concat(partPath);
            fileNew1.MasterFileName    = "";
            fileNew1.MakeDisplayedPart = false;
            NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;
            createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder();
            createNewComponentBuilder1.ReferenceSet     = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;
            createNewComponentBuilder1.NewComponentName = partName;
            createNewComponentBuilder1.ComponentOrigin  = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Wcs;
            createNewComponentBuilder1.NewFile          = fileNew1;
            bool validate = createNewComponentBuilder1.Validate();

            try
            {
                NXObject nXObject1 = createNewComponentBuilder1.Commit();
                return(nXObject1);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:CreateNew:" + ex.Message);
                return(null);
            }
            finally
            {
                createNewComponentBuilder1.Destroy();
                Session.UndoMarkId markId = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible);
                theSession.DeleteUndoMark(markId, "");
            }
        }
        /// <summary>
        /// 创建圆柱特征
        /// </summary>
        /// <param name="zAxis">轴</param>
        /// <param name="centerPt">中心点</param>
        /// <param name="offset"></param>
        /// <param name="toolingBoxFeature"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static ToolingBox CreateToolingCylinder(Vector3d zAxis, Point3d centerPt, double[] offset, ToolingBox toolingBoxFeature = null, params TaggedObject[] objs)
        {
            Part workPart = theSession.Parts.Work;
            SelectionRuleFactory rules = new SelectionRuleFactory(objs.ToList());
            //ToolingBox nullToolingBox = null;
            ToolingBoxBuilder toolingBoxBuilder = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(toolingBoxFeature);

            toolingBoxBuilder.Type = ToolingBoxBuilder.Types.BoundedCylinder;
            Direction dir = workPart.Directions.CreateDirection(centerPt, zAxis, SmartObject.UpdateOption.WithinModeling);

            toolingBoxBuilder.AxisVector            = dir;
            toolingBoxBuilder.RadialOffset.Value    = offset[2];
            toolingBoxBuilder.OffsetPositiveZ.Value = offset[0];
            toolingBoxBuilder.OffsetNegativeZ.Value = offset[1];
            // toolingBoxBuilder.SingleOffset = false;
            ScCollector scCollector = toolingBoxBuilder.BoundedObject;

            scCollector.ReplaceRules(rules.CreateSelectionRule().ToArray(), false);
            toolingBoxBuilder.CalculateBoxSize();

            NXObject[] selections   = new NXObject[1];
            NXObject[] deselections = new NXObject[1];
            selections[0] = (NXObject)objs[0];
            toolingBoxBuilder.SetSelectedOccurrences(selections, deselections);
            toolingBoxBuilder.CalculateBoxSize();

            NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start ToolingBox");
            try
            {
                return(toolingBoxBuilder.CommitFeature() as ToolingBox);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.ToolingFeature.CreateToolingBox:错误:" + ex.Message);
                return(null);
            }
            finally
            {
                toolingBoxBuilder.Destroy();
                theSession.UpdateManager.DoUpdate(markId);
                theSession.DeleteUndoMark(markId, "End ToolingBox");
            }
        }
Пример #10
0
        /// <summary>
        ///更新
        /// </summary>
        public static void UpdateObject(NXOpen.Session.UndoMarkId markId, string name)
        {
            Part workPart = theSession.Parts.Work;

            theSession.Preferences.Modeling.UpdatePending = false;
            try
            {
                theSession.UpdateManager.DoUpdate(markId);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("DeleteObject.UpdateObject:更新失败!" + ex.Message);
                throw ex;
            }
            finally
            {
                theSession.DeleteUndoMark(markId, name);
            }
        }
Пример #11
0
        /// <summary>
        /// 设置属性表达式
        /// </summary>
        /// <param name="expName"></param>
        /// <param name="attrName"></param>
        /// <param name="type"></param>
        public static Expression SetAttrExp(string expName, string attrName, NXObject.AttributeType type)
        {
            Part workPart = theSession.Parts.Work;

            try
            {
                Expression exp = workPart.Expressions.GetAttributeExpression(workPart, attrName, type, -1);
                if (!expName.Equals(attrName, StringComparison.CurrentCultureIgnoreCase))
                {
                    exp.SetName(expName);
                }
                return(exp);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("ExpressionUtils:SetAttrExp:表达式" + expName + "               " + ex.Message);
                throw ex;
            }
        }
Пример #12
0
        /// <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();
            }
        }
Пример #13
0
        public static bool AddShetch(Tag shetchTag, params NXObject[] addObj)
        {
            List <Tag> temp = new List <Tag>();

            foreach (NXObject obj in addObj)
            {
                temp.Add(obj.Tag);
            }
            try
            {
                theUFSession.Sket.AddObjects(shetchTag, addObj.Length, temp.ToArray());
                return(true);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("SketchUtils:AddShetch:" + ex.Message);
                return(false);
            }
        }
Пример #14
0
        /// <summary>
        /// 干涉面
        /// </summary>
        /// <param name="body1"></param>
        /// <param name="body2"></param>
        /// <returns></returns>
        public static void SetInterferenceOutFace(Body body1, Body body2, out List <Face> faces, out List <Body> bodys)
        {
            faces = new List <Face>();
            bodys = new List <Body>();
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.GeometricAnalysis.SimpleInterference simpleInterference1;
            simpleInterference1 = workPart.AnalysisManager.CreateSimpleInterferenceObject();
            simpleInterference1.InterferenceType     = NXOpen.GeometricAnalysis.SimpleInterference.InterferenceMethod.InterferingFaces;
            simpleInterference1.FaceInterferenceType = NXOpen.GeometricAnalysis.SimpleInterference.FaceInterferenceMethod.AllPairs;
            simpleInterference1.FirstBody.Value      = body1;
            simpleInterference1.SecondBody.Value     = body2;
            NXOpen.GeometricAnalysis.SimpleInterference.Result result1;
            result1 = simpleInterference1.PerformCheck();
            try
            {
                NXObject[] objs = simpleInterference1.GetInterferenceResults();
                foreach (NXObject obj in objs)
                {
                    faces.Add(obj as Face);
                }

                simpleInterference1.InterferenceType = NXOpen.GeometricAnalysis.SimpleInterference.InterferenceMethod.InterferenceSolid;
                NXOpen.GeometricAnalysis.SimpleInterference.Result result2 = simpleInterference1.PerformCheck();
                if (result2 == NXOpen.GeometricAnalysis.SimpleInterference.Result.InterferenceExists)
                {
                    NXObject[] by = simpleInterference1.GetInterferenceResults();
                    foreach (NXObject obj in by)
                    {
                        bodys.Add(obj as Body);
                    }
                }
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("Basic.AnalysisUtils.SetInterferenceOutFace:错误:" + ex.Message);
                throw ex;
            }
            finally
            {
                simpleInterference1.Destroy();
            }
        }
Пример #15
0
        /// <summary>
        /// 设置显示部件
        /// </summary>
        /// <param name="part"></param>
        public static void SetPartDisplay(Part part)
        {
            Part workPart    = theSession.Parts.Work;
            Part displayPart = theSession.Parts.Display;

            NXOpen.PartLoadStatus            partLoadStatus1;
            NXOpen.PartCollection.SdpsStatus status1;
            try
            {
                status1     = theSession.Parts.SetDisplay(part as Part, false, true, out partLoadStatus1);
                workPart    = theSession.Parts.Work;
                displayPart = theSession.Parts.Display;
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("PartUtils.SetPartDisplay:" + ex.Message);
                throw ex;
            }
        }
Пример #16
0
        /// <summary>
        /// 以面中心点和向量创建平面
        /// </summary>
        /// <param name="planeFace"></param>
        /// <param name="flip">设置是否翻转方向</param>
        /// <returns></returns>
        public static NXOpen.Plane CreatePlaneOfFace(Face face, bool flip)
        {
            Part     workPart = theSession.Parts.Work;
            Point3d  originPt;
            Vector3d normal;

            FaceUtils.AskFaceOriginAndNormal(face, out originPt, out normal);
            try
            {
                NXOpen.Plane plane1 = workPart.Planes.CreatePlane(originPt, normal, NXOpen.SmartObject.UpdateOption.WithinModeling);
                plane1.SetFlip(flip);
                return(plane1);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("Basic.TrimBody:CreateTrimBodyFeature:" + ex.Message);
                throw ex;
            }
        }
Пример #17
0
        /// <summary>
        ///偏置面
        /// </summary>
        /// <param name="side"></param>
        /// <param name="isok"></param>
        /// <param name="faces"></param>
        /// <returns></returns>
        public static NXObject Offset(double side, out bool isok, params Face[] faces)
        {
            isok = true;

            Session theSession = Session.GetSession();
            Part    workPart   = theSession.Parts.Work;

            Session.UndoMarkId mark = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Offset");
            NXOpen.Features.AdmOffsetRegion        nullNXOpen_Features_AdmOffsetRegion = null;
            NXOpen.Features.AdmOffsetRegionBuilder admOffsetRegionBuilder1;
            admOffsetRegionBuilder1 = workPart.Features.CreateAdmOffsetRegionBuilder(nullNXOpen_Features_AdmOffsetRegion);
            NXOpen.FaceDumbRule faceDumbRule;
            faceDumbRule = workPart.ScRuleFactory.CreateRuleFaceDumb(faces);

            NXOpen.SelectionIntentRule[] rules = new NXOpen.SelectionIntentRule[1];
            rules[0] = faceDumbRule;
            admOffsetRegionBuilder1.FaceToOffset.FaceCollector.ReplaceRules(rules, false);
            admOffsetRegionBuilder1.Distance.Value = side;
            NXOpen.NXObject nXObject1 = null;
            try
            {
                nXObject1 = admOffsetRegionBuilder1.Commit();

                return(nXObject1);
            }
            catch (NXException ex)
            {
                isok = false;
                LogMgr.WriteLog("OffsetRegion:Offset:" + ex.Message);

                return(null);
            }
            finally
            {
                admOffsetRegionBuilder1.Destroy();
                if (!isok)
                {
                    theSession.UndoToMark(mark, "Offset");
                }
                theSession.DeleteUndoMark(mark, "Offset");
            }
        }
Пример #18
0
        /// <summary>
        ///更新
        /// </summary>
        public static void UpdateObject()
        {
            Part workPart = theSession.Parts.Work;

            theSession.Preferences.Modeling.UpdatePending = false;
            NXOpen.Session.UndoMarkId markId;
            markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "NX update");
            try
            {
                theSession.UpdateManager.DoUpdate(markId);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("DeleteObject.UpdateObject:更新失败!" + ex.Message);
            }
            finally
            {
                theSession.DeleteUndoMark(markId, "NX update");
            }
        }
Пример #19
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="nxObject"></param>
        /// <returns></returns>
        public static bool Delete(params NXObject[] nxObject)
        {
            Session.UndoMarkId mark = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete");
            int dt = theSession.UpdateManager.AddToDeleteList(nxObject);

            try
            {
                int nErrs = theSession.UpdateManager.DoUpdate(mark);
                return(dt != 0);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("DeleteObject.UpdateObject: 删除失败!" + ex.Message);
                return(false);
            }
            finally
            {
                theSession.DeleteUndoMark(mark, null);
            }
        }
Пример #20
0
 /// <summary>
 /// 通过父获得partComp
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="part"></param>
 /// <returns></returns>
 public static List <NXOpen.Assemblies.Component> GetPartComp(Part parent, Part part)
 {
     Tag[] elePartOccsTag;
     NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession();
     try
     {
         List <NXOpen.Assemblies.Component> ct = new List <NXOpen.Assemblies.Component>();
         theUFSession.Assem.AskOccsOfPart(parent.Tag, part.Tag, out elePartOccsTag);
         foreach (Tag tg in elePartOccsTag)
         {
             ct.Add(NXOpen.Utilities.NXObjectManager.Get(tg) as NXOpen.Assemblies.Component);
         }
         return(ct);
     }
     catch (NXException ex)
     {
         LogMgr.WriteLog("AssmbliesUtils:GetPartComp:         " + ex.Message);
         throw ex;
     }
 }
Пример #21
0
        /// <summary>
        /// 设置层
        /// </summary>
        /// <param name="fitAll"></param>
        /// <param name="layers"></param>
        public static void SetLayerSelectable(bool fitAll, params int[] layers)
        {
            Part workPart = Session.GetSession().Parts.Work;
            List <NXOpen.Layer.StateInfo> stateArrays = new List <NXOpen.Layer.StateInfo>();

            try
            {
                foreach (int k in layers)
                {
                    stateArrays.Add(new NXOpen.Layer.StateInfo(k, NXOpen.Layer.State.Selectable));
                }
                workPart.Layers.ChangeStates(stateArrays.ToArray(), fitAll);
            }

            catch (NXException ex)
            {
                LogMgr.WriteLog("LayerUtils:SetLayer           错误!" + ex.Message);
                throw ex;
            }
        }
Пример #22
0
        /// <summary>
        /// 删除表达式
        /// </summary>
        /// <param name="expName"></param>
        public static void DeteteExp(string expName)
        {
            Part workPart = theSession.Parts.Work;

            theSession.Preferences.Modeling.UpdatePending = false;

            try
            {
                Expression exp = workPart.Expressions.FindObject(expName);
                if (exp == null)
                {
                    return;
                }
                workPart.Expressions.Delete(exp);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("ExpressionUtils:DeteteExp:表达式" + expName + "                 " + ex.Message);
            }
        }
Пример #23
0
        public static void SetDimensionPrecision(Dimension dim, int count)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Annotations.LinearDimensionBuilder linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(dim);
            linearDimensionBuilder1.Style.DimensionStyle.DimensionValuePrecision = count;
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = linearDimensionBuilder1.Commit();
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("DrawingUtils:SetDimensionPrecision" + ex.Message);
            }
            finally
            {
                linearDimensionBuilder1.Destroy();
            }
        }
Пример #24
0
        /// <summary>
        /// 创建尺寸约束
        /// </summary>
        /// <param name="line1"></param>
        /// <param name="line2"></param>
        /// <param name="dimOrigin"></param>
        /// <param name="method"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Expression CreateDimForLine(Line line1, Line line2, double[] dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod method, InferSnapType.SnapType type)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Annotations.Dimension        nullNXOpen_Annotations_Dimension = null;
            NXOpen.SketchLinearDimensionBuilder sketchLinearDimensionBuilder1;
            sketchLinearDimensionBuilder1 = workPart.Sketches.CreateLinearDimensionBuilder(nullNXOpen_Annotations_Dimension);
            sketchLinearDimensionBuilder1.Origin.SetInferRelativeToGeometry(true);                                                      //如果未应用其他关联性,则在提交时推断关联几何关系
            sketchLinearDimensionBuilder1.Measurement.Method       = method;                                                            //测量方向
            sketchLinearDimensionBuilder1.Driving.DrivingMethod    = NXOpen.Annotations.DrivingValueBuilder.DrivingValueMethod.Driving; //驱动方法
            sketchLinearDimensionBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane;           //平面类型
            NXOpen.Direction nullNXOpen_Direction = null;
            sketchLinearDimensionBuilder1.Measurement.Direction = nullNXOpen_Direction;                                                 //测量方向
            NXOpen.View nullNXOpen_View = null;
            sketchLinearDimensionBuilder1.Measurement.DirectionView = nullNXOpen_View;                                                  //测量视图
            sketchLinearDimensionBuilder1.Style.DimensionStyle.NarrowDisplayType = NXOpen.Annotations.NarrowDisplayOption.None;         //设置窄尺寸样式
            NXOpen.Point3d point2_3 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            sketchLinearDimensionBuilder1.SecondAssociativity.SetValue(NXOpen.InferSnapType.SnapType.Mid, line2, workPart.ModelingViews.WorkView, line2.EndPoint, null, nullNXOpen_View, point2_3);

            NXOpen.Point3d point2_4 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            sketchLinearDimensionBuilder1.FirstAssociativity.SetValue(type, line1, workPart.ModelingViews.WorkView, line1.EndPoint, null, nullNXOpen_View, point2_4);
            NXOpen.Point3d point3 = new NXOpen.Point3d(dimOrigin[0], dimOrigin[1], dimOrigin[2]);
            sketchLinearDimensionBuilder1.Origin.Origin.SetValue(null, nullNXOpen_View, point3);

            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = sketchLinearDimensionBuilder1.Commit();
                Expression exp = sketchLinearDimensionBuilder1.Driving.ExpressionValue;
                return(exp);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("SketchUtils:CreateDimForLine:" + ex.Message);
                throw ex;
            }
            finally
            {
                sketchLinearDimensionBuilder1.Destroy();
            }
        }
Пример #25
0
 /// <summary>
 /// 打开 部件
 /// </summary>
 /// <param name="path">地址</param>
 /// <returns></returns>
 public static Part OpenPartFile(string path)
 {
     if (!File.Exists(path))
     {
         return(null);
     }
     NXOpen.Session        theSession = NXOpen.Session.GetSession();
     NXOpen.BasePart       basePart1;
     NXOpen.PartLoadStatus partLoadStatus1;
     try
     {
         basePart1 = theSession.Parts.OpenBaseDisplay(path, out partLoadStatus1);
         partLoadStatus1.Dispose();
         return(basePart1 as Part);
     }
     catch (NXException ex)
     {
         LogMgr.WriteLog("PartUtils.OpenPartFile" + ex.Message);
         throw ex;
     }
 }
Пример #26
0
        /// <summary>
        /// 加载部件
        /// </summary>
        /// <param name="part">部件下面</param>
        /// <param name="partPath">部件地址</param>
        /// <param name="partName">部件名字</param>
        /// <param name="csys">加载坐标</param>
        /// <param name="basePoint">装配位置点</param>
        /// <returns>Component</returns>
        public static NXOpen.Assemblies.Component PartLoad(Part part, string partPath, string partName, Matrix4 matr, Point3d basePoint)
        {
            //  Part workPart = theSession.Parts.Work;

            NXOpen.PartLoadStatus       partLoadStatus1 = null;
            NXOpen.Assemblies.Component component1;
            try
            {
                component1 = part.ComponentAssembly.AddComponent(partPath, "None", partName, basePoint, matr.GetMatrix3(), -1, out partLoadStatus1, true);
                return(component1);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:PartLoad:" + ex.Message);
                return(null);
            }
            finally
            {
                partLoadStatus1.Dispose();
            }
        }
Пример #27
0
 /// <summary>
 /// 删除部件
 /// </summary>
 /// <param name="comp">部件</param>
 public static void DeleteComponent(params NXOpen.Assemblies.Component[] comp)
 {
     theSession.UpdateManager.ClearErrorList();
     NXOpen.Session.UndoMarkId markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Delete");
     try
     {
         int nErrs1;
         nErrs1 = theSession.UpdateManager.AddToDeleteList(comp);
         bool notifyOnDelete2;
         notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete;
     }
     catch (Exception ex)
     {
         LogMgr.WriteLog("AssmbliesUtils:DeleteComponent:" + ex.Message);
     }
     finally
     {
         int nErrs2;
         nErrs2 = theSession.UpdateManager.DoUpdate(markId2);
     }
 }
Пример #28
0
        /// <summary>
        /// 添加尺寸注释
        /// </summary>
        /// <param name="dim"></param>
        /// <param name="lineName"></param>
        public static void AppendedTextDim(Dimension dim, params string[] lineName)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Annotations.AppendedTextEditorBuilder appendedTextEditorBuilder1;
            appendedTextEditorBuilder1 = workPart.Dimensions.CreateAppendedTextEditorBuilder(dim);
            appendedTextEditorBuilder1.AppendedTextBuilder.SetBelow(lineName);
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = appendedTextEditorBuilder1.Commit();
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("DrawingUtils:AppendedTextDim" + ex.Message);
            }
            finally
            {
                appendedTextEditorBuilder1.Destroy();
            }
        }
Пример #29
0
        /// <summary>
        /// 隐藏组件
        /// </summary>
        /// <param name="baseView"></param>
        /// <param name="comp"></param>

        /*   public static void HideComponent(NXOpen.Drawings.DraftingView baseView, params NXOpen.Assemblies.Component[] comp)
         * {
         *     Part workPart = Session.GetSession().Parts.Work;
         *     NXOpen.Assemblies.HideComponentBuilder hideComponentBuilder1;
         *     hideComponentBuilder1 = workPart.AssemblyManager.CreateHideComponentBuilder();
         *     bool added1;
         *     added1 = hideComponentBuilder1.Components.Add(comp);
         *     bool added2;
         *     added2 = hideComponentBuilder1.Views.Add(baseView);
         *     try
         *     {
         *         NXOpen.NXObject nXObject1;
         *         nXObject1 = hideComponentBuilder1.Commit();
         *     }
         *     catch (Exception ex)
         *     {
         *         LogMgr.WriteLog("DrawingUtils:HideComponent" + ex.Message);
         *     }
         *     finally
         *     {
         *         hideComponentBuilder1.Destroy();
         *     }
         * }*/
        public static void HideComponent(NXOpen.Drawings.DraftingView baseView, params NXOpen.Assemblies.Component[] hiddenComp)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Drawings.BaseViewBuilder baseViewBuilder1;
            baseViewBuilder1 = workPart.DraftingViews.CreateBaseViewBuilder(baseView as BaseView);
            baseViewBuilder1.HiddenObjects.Objects.Add(hiddenComp);
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = baseViewBuilder1.Commit();
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("DrawingUtils:HideComponent" + ex.Message);
            }
            finally
            {
                baseViewBuilder1.Destroy();
            }
        }
Пример #30
0
        /// <summary>
        /// 移动到层
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="obj"></param>
        public static void MoveDisplayableObject(int layer, params NXObject[] obj)
        {
            Part workPart = Session.GetSession().Parts.Work;
            List <DisplayableObject> dis = new List <DisplayableObject>();

            foreach (NXObject nx in obj)
            {
                if (!(nx is Edge || nx is Face))
                {
                    dis.Add(nx as DisplayableObject);
                }
            }
            try
            {
                workPart.Layers.MoveDisplayableObjects(layer, dis.ToArray());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("LayerUtils.MoveDisplayableObject            " + ex.Message);
            }
        }