コード例 #1
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);
                throw ex;
            }
            finally
            {
                waveLinkBuilder1.Destroy();
            }
        }
コード例 #2
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, "");
            }
        }
コード例 #3
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;
            }
        }
コード例 #4
0
        /// <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");
            }
        }
コード例 #5
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;
            }
        }
コード例 #6
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();
            }
        }
コード例 #7
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();
            }
        }
コード例 #8
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);
            }
        }
コード例 #9
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;
            }
        }
コード例 #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
ファイル: OffsetRegion.cs プロジェクト: ycchen10/MolexPlugIn
        /// <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");
            }
        }
コード例 #12
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;
            }
        }
コード例 #13
0
ファイル: DeleteObject.cs プロジェクト: ycchen10/MolexPlugIn
        /// <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);
            }
        }
コード例 #14
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;
     }
 }
コード例 #15
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);
            }
        }
コード例 #16
0
ファイル: DeleteObject.cs プロジェクト: ycchen10/MolexPlugIn
        /// <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");
            }
        }
コード例 #17
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();
            }
        }
コード例 #18
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();
            }
        }
コード例 #19
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();
            }
        }
コード例 #20
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);
            }
        }
コード例 #21
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);
     }
 }
コード例 #22
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();
            }
        }
コード例 #23
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;
     }
 }
コード例 #24
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();
            }
        }
コード例 #25
0
        /// <summary>
        /// 创建拉伸特征
        /// </summary>
        /// <param name="vec">向量</param>
        /// <param name="start">起始</param>
        /// <param name="end">终止</param>
        /// <param name="extrude">lastez</param>
        /// <param name="line">线</param>
        /// <returns></returns>
        public static NXOpen.Features.Feature CreateExtrude(Vector3d vec, string start, string end, NXOpen.Features.Feature extrude = null, params TaggedObject[] line)
        {
            Session theSession         = Session.GetSession();
            Part    workPart           = theSession.Parts.Work;
            SelectionRuleFactory rules = new SelectionRuleFactory(line.ToList());

            NXOpen.Features.Feature        nullNXOpen_Features_Feature = null;
            NXOpen.Features.ExtrudeBuilder extrudeBuilder1             = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature);
            NXOpen.Section section1 = workPart.Sections.CreateSection();
            extrudeBuilder1.Section = section1;
            extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = start;
            extrudeBuilder1.Limits.EndExtend.Value.RightHandSide   = end;

            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);


            NXOpen.NXObject nullNXOpen_NXObject = null;

            section1.AddToSection(rules.CreateSelectionRule().ToArray(), (NXObject)line[0], nullNXOpen_NXObject, nullNXOpen_NXObject, origin1, NXOpen.Section.Mode.Create, false);
            extrudeBuilder1.Direction = direction1;
            NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start Extruded");
            try
            {
                return(extrudeBuilder1.CommitFeature());
            }

            catch (NXException ex)
            {
                LogMgr.WriteLog("ExtrudedUtils:CreateExtruded:" + ex.Message);
                throw ex;
            }
            finally
            {
                extrudeBuilder1.Destroy();
                theSession.UpdateManager.DoUpdate(markId);
                theSession.DeleteUndoMark(markId, "End Extruded");
            }
        }
コード例 #26
0
        /// <summary>
        /// 更新表达式
        /// </summary>
        /// <param name="expName">表达式名</param>
        /// <param name="expNum">表达式值</param>
        public static bool UpdateExp(string expName, string expNum)
        {
            Part workPart = theSession.Parts.Work;

            theSession.Preferences.Modeling.UpdatePending = false;

            try
            {
                Expression exp = workPart.Expressions.FindObject(expName);
                if (exp == null)
                {
                    return(false);
                }
                workPart.Expressions.Edit(exp, expNum);  //编辑表达式
                return(true);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("ExpressionUtils:UpdateExp:表达式" + expName + "            " + ex.Message);
                return(false);
            }
        }
コード例 #27
0
        /// <summary>
        /// 更新视图
        /// </summary>
        public static void UpdateViews(NXOpen.Drawings.DrawingSheet sheet)
        {
            Part workPart = theSession.Parts.Work;
            List <NXOpen.Drawings.DraftingView> views = new List <DraftingView>();

            foreach (DraftingView dv in sheet.GetDraftingViews())
            {
                if (dv.IsOutOfDate)
                {
                    views.Add(dv);
                }
            }
            try
            {
                workPart.DraftingViews.UpdateViews(views.ToArray());
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("DrawingUtils:UpdateViews" + ex.Message);
                throw ex;
            }
        }
コード例 #28
0
        /// <summary>
        /// 设置加工体
        /// </summary>
        /// <param name="workpiece"></param>
        /// <param name="bodys"></param>
        public static void SetFeatureGeometry(string workpiece, params Body[] bodys)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.CAM.FeatureGeometry featureGeometry1 = (NXOpen.CAM.FeatureGeometry)workPart.CAMSetup.CAMGroupCollection.FindObject(workpiece);
            if (featureGeometry1 == null)
            {
                LogMgr.WriteLog("无法找到" + workpiece + "加工体");
            }
            NXOpen.CAM.MillGeomBuilder millGeomBuilder1;
            millGeomBuilder1 = workPart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(featureGeometry1);
            NXOpen.CAM.GeometrySetList geometrySetList1;
            geometrySetList1 = millGeomBuilder1.PartGeometry.GeometryList;
            NXOpen.TaggedObject taggedObject1;
            taggedObject1 = geometrySetList1.FindItem(0);
            NXOpen.CAM.GeometrySet geometrySet1 = (NXOpen.CAM.GeometrySet)taggedObject1;
            NXOpen.BodyDumbRule    bodyDumbRule1;
            bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodys, true);

            NXOpen.ScCollector scCollector1;
            scCollector1 = geometrySet1.ScCollector;

            NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
            rules1[0] = bodyDumbRule1;
            scCollector1.ReplaceRules(rules1, false);
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = millGeomBuilder1.Commit();
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("CAMUtils:SetFeatureGeometry:" + ex.Message);
            }
            finally
            {
                millGeomBuilder1.Destroy();
            }
        }
コード例 #29
0
ファイル: DeleteObject.cs プロジェクト: ycchen10/MolexPlugIn
        public static void DeleteParms(params NXObject[] obj)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Features.RemoveParametersBuilder removeParametersBuilder1;
            removeParametersBuilder1 = workPart.Features.CreateRemoveParametersBuilder();
            bool added1 = removeParametersBuilder1.Objects.Add(obj);

            try
            {
                NXObject nXObject1;
                nXObject1 = removeParametersBuilder1.Commit();
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("DeleteObject.DeleteParms:删除参数失败!" + ex.Message);
            }
            finally
            {
                removeParametersBuilder1.Destroy();
            }
        }
コード例 #30
0
        /// <summary>
        /// 获取bool属性
        /// </summary>
        /// <param name="objTag">需要获取属性的Tag值</param>
        /// <param name="title">属性标题</param>
        /// <returns>属性值</returns>
        public static bool GetAttrForBool(NXObject obj, string title)
        {
            bool value        = false;
            bool hasAttribute = false;

            try
            {
                theUFSession.Attr.GetBoolUserAttribute(obj.Tag, title, UFConstants.UF_ATTR_NOT_ARRAY, out value, out hasAttribute);
            }
            catch
            {
                //  LogMgr.WriteLog("获取" + title + "属性函数错误");
            }
            finally
            {
                if (!hasAttribute)
                {
                    LogMgr.WriteLog("未获取" + title + "属性");
                }
            }
            return(value);
        }