예제 #1
0
        internal static Snap.Position[] PointSet(Snap.NX.ICurve icurve, int pointCount)
        {
            Globals.UndoMarkId markId  = Globals.SetUndoMark(Globals.MarkVisibility.Invisible, "Snap_PositionArray_EqualParameter999");
            PointSetBuilder    builder = Globals.WorkPart.NXOpenPart.Features.CreatePointSetBuilder(null);

            builder.Type          = PointSetBuilder.Types.CurvePoints;
            builder.CurvePointsBy = PointSetBuilder.CurvePointsType.EqualArcLength;
            builder.Associative   = false;
            builder.NumberOfPointsExpression.RightHandSide = pointCount.ToString();
            builder.StartPercentage.RightHandSide          = "0";
            builder.EndPercentage.RightHandSide            = "100";
            SelectionIntentRule[] rules = Snap.NX.Section.CreateSelectionIntentRule(new Snap.NX.ICurve[] { icurve });
            NXOpen.NXObject       nXOpenTaggedObject = (NXOpen.NXObject)icurve.NXOpenTaggedObject;
            builder.SingleCurveOrEdgeCollector.AddToSection(rules, nXOpenTaggedObject, null, null, (Point3d)icurve.StartPoint, NXOpen.Section.Mode.Create, false);
            builder.Commit();
            NXOpen.NXObject[] committedObjects = builder.GetCommittedObjects();
            builder.Destroy();
            Snap.Position[] positionArray = new Snap.Position[committedObjects.Length];
            for (int i = 0; i < positionArray.Length; i++)
            {
                TaggedObject  obj3  = committedObjects[i];
                Snap.NX.Point point = (NXOpen.Point)obj3;
                positionArray[i] = point.Position;
            }
            Globals.UndoToMark(markId, "Snap_PositionArray_EqualParameter999");
            Globals.DeleteUndoMark(markId, "Snap_PositionArray_EqualParameter999");
            return(positionArray);
        }
예제 #2
0
        private static NXOpen.NXObject[] Members(Snap.NX.Component comp)
        {
            var uFSession = NXOpen.UF.UFSession.GetUFSession();
            Tag @null     = Tag.Null;

            NXOpen.NXObject nxopenTaggedObject = null;
            var             list = new List <NXOpen.NXObject>();

            do
            {
                @null = uFSession.Assem.CycleEntsInPartOcc(comp.NXOpenTag, @null);
                if (@null != Tag.Null)
                {
                    try
                    {
                        nxopenTaggedObject = GetObjectFromTag(@null);
                        if (nxopenTaggedObject != null)
                        {
                            list.Add(nxopenTaggedObject);
                        }
                    }
                    catch
                    {
                    }
                }
            }while (@null != Tag.Null);
            return(list.ToArray());
        }
예제 #3
0
파일: Note.cs 프로젝트: suifengsigan/TEST_1
        internal static Snap.NX.Note CreateNote(string[] text, Position origin, Snap.Orientation matrix, TextStyle textStyle)
        {
            PmiNoteBuilder builder = Globals.WorkPart.NXOpenPart.Annotations.CreatePmiNoteBuilder(null);

            builder.Style.LetteringStyle.GeneralTextColor     = Snap.Color.NXColor(textStyle.Color);
            builder.Style.LetteringStyle.GeneralTextFont      = textStyle.FontIndex;
            builder.Style.LetteringStyle.GeneralTextLineWidth = (LineWidth)(textStyle.StrokeWidth + 1);
            double num2 = textStyle.FontSize / 72.0;
            double num3 = num2 * Globals.InchesPerUnit;

            builder.Style.LetteringStyle.GeneralTextSize             = num3;
            builder.Style.LetteringStyle.GeneralTextCharSpaceFactor  = textStyle.CharSpaceFactor;
            builder.Style.LetteringStyle.GeneralTextAspectRatio      = textStyle.AspectRatio;
            builder.Style.LetteringStyle.GeneralTextLineSpaceFactor  = textStyle.LineSpaceFactor;
            builder.Style.LetteringStyle.HorizontalTextJustification = (NXOpen.Annotations.TextJustification)textStyle.HorizontalTextJustification;
            builder.Style.LetteringStyle.Angle = textStyle.LineAngle;
            builder.VerticalText = textStyle.IsVertical;
            builder.Text.SetEditorText(text);
            builder.Origin.Anchor            = (NXOpen.Annotations.OriginBuilder.AlignmentPosition)(textStyle.AlignmentPosition - 1);
            builder.Origin.OriginPoint       = (Point3d)origin;
            builder.Origin.Plane.PlaneMethod = PlaneBuilder.PlaneMethodType.UserDefined;
            Xform xform = Globals.NXOpenWorkPart.Xforms.CreateXform((Point3d)origin, (Matrix3x3)matrix, SmartObject.UpdateOption.DontUpdate, 1.0);

            builder.Origin.Plane.UserDefinedPlane = xform;
            NXOpen.NXObject obj2 = builder.Commit();
            builder.Destroy();
            return(new Snap.NX.Note((PmiNote)obj2));
        }
        //------------------------------------------------------------------------------
        //This method shows the dialog on the screen
        //------------------------------------------------------------------------------
        public NXOpen.UIStyler.DialogResponse Show()
        {
            try
            {
                //CHECK WORKING OBJECT
                Logger.Write("--- WORKING OBJECT CHECK ---");

                NXOpen.NXObject workObj = theSession.Parts.BaseWork;
                if (workObj.GetType().ToString() != "NXOpen.CAE.SimPart")
                {
                    Logger.Write(workObj.GetType().ToString() + "  --> EXPECTED A SIM OBJECT TO BE THE WORKING OBJECT:  ABORT");
                    Logger.Show();
                }
                else
                {
                    // SHOW GUI
                    theDialog.Show();
                }
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(0);
        }
예제 #5
0
 public static void CopyToLayer(int newLayer, params Snap.NX.NXObject[] nxobjectArray)
 {
     NXOpen.NXObject[] objectArray = new NXOpen.NXObject[nxobjectArray.Length];
     for (int i = 0; i < nxobjectArray.Length; i++)
     {
         objectArray[i] = (NXOpen.NXObject)nxobjectArray[i].NXOpenTaggedObject;
     }
     Globals.NXOpenWorkPart.Layers.CopyObjects(newLayer, objectArray);
 }
예제 #6
0
        /// <summary>
        /// 移动部件并复制部件
        /// </summary>
        /// <param name="compObj"></param>
        /// <param name="endPt"></param>
        /// <param name="mat"></param>
        /// <returns></returns>
        public static NXOpen.Assemblies.Component MoveCompCopyPart(NXOpen.Assemblies.Component compObj, Vector3d endPt, Matrix4 mat)
        {
            Part workPart = theSession.Parts.Work;

            Matrix4 invers = mat.GetInversMatrix();

            invers.ApplyVec(ref endPt);

            NXOpen.Positioning.ComponentPositioner componentPositioner1;
            componentPositioner1 = workPart.ComponentAssembly.Positioner;                                                                                    //组件定位
            componentPositioner1.ClearNetwork();                                                                                                             //删除定位器
            NXOpen.Assemblies.Arrangement arrangement1 = (NXOpen.Assemblies.Arrangement)workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"); //布局
            componentPositioner1.PrimaryArrangement = arrangement1;                                                                                          //主要布局
            componentPositioner1.BeginMoveComponent();                                                                                                       //开始移动组件
            bool allowInterpartPositioning1;

            allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning;                       //首选项的部件间的定位
            NXOpen.Positioning.Network network1;
            network1 = componentPositioner1.EstablishNetwork();                                                        //建立
            NXOpen.Positioning.ComponentNetwork componentNetwork1 = (NXOpen.Positioning.ComponentNetwork)network1;
            componentNetwork1.MoveObjectsState = true;                                                                 //移动对象状态
            NXOpen.Assemblies.Component nullNXOpen_Assemblies_Component = null;
            componentNetwork1.DisplayComponent        = nullNXOpen_Assemblies_Component;                               //显示组件
            componentNetwork1.NetworkArrangementsMode = NXOpen.Positioning.ComponentNetwork.ArrangementsMode.Existing; //现有安排模式
            componentNetwork1.RemoveAllConstraints();                                                                  //删除约束
            NXOpen.NXObject[] movableObjects1 = new NXOpen.NXObject[1];
            movableObjects1[0] = compObj;
            NXOpen.Assemblies.Component[] components1 = new NXOpen.Assemblies.Component[1];
            components1[0] = compObj;
            NXOpen.Assemblies.Component[] newComponents1 = workPart.ComponentAssembly.CopyComponents(components1);

            componentNetwork1.SetMovingGroup(newComponents1); //设置移动组件
            componentNetwork1.Solve();                        //解除约束
            bool loaded1;

            loaded1 = componentNetwork1.IsReferencedGeometryLoaded(); //参考几何加载
            componentNetwork1.BeginDrag();                            //操作即将开始

            NXOpen.Vector3d translation1 = new NXOpen.Vector3d(endPt.X, endPt.Y, endPt.Z);
            componentNetwork1.DragByTranslation(translation1); //移动
            componentNetwork1.EndDrag();                       //操作结束
            componentNetwork1.ResetDisplay();                  //返回到模型上
            componentNetwork1.ApplyToModel();                  //应该到当前模型
            componentNetwork1.Solve();                         //解除约束
            componentPositioner1.ClearNetwork();               //清空
            int nErrs1;

            nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1); //更新

            componentPositioner1.ClearNetwork();
            componentPositioner1.DeleteNonPersistentConstraints();
            componentPositioner1.EndMoveComponent();

            NXOpen.Assemblies.Arrangement nullNXOpen_Assemblies_Arrangement = null;
            componentPositioner1.PrimaryArrangement = nullNXOpen_Assemblies_Arrangement;
            return(newComponents1[0]);
        }
예제 #7
0
        public void NXRootFile(Session nxSession, NewNXfile fileDir)
        {
            NXOpen.FileNew nxRootCompFile = nxSession.Parts.FileNew();
            fileDir.NXfile(nxRootCompFile, fileDir.rootDir());
            NXOpen.NXObject nXObject_RootComp = nxRootCompFile.Commit();
            nxRootCompFile.MakeDisplayedPart = true;
            Part nxRootAssem = nxSession.Parts.Work;

            nxRootCompFile.Destroy();
        }
예제 #8
0
 private static NXOpen.NXObject GetObjectFromTag(Tag tag)
 {
     NXOpen.NXObject obj2 = null;
     try
     {
         obj2 = NXOpen.Utilities.NXObjectManager.Get(tag) as NXOpen.NXObject;
     }
     catch
     {
     }
     return(obj2);
 }
예제 #9
0
 internal static NXOpen.NXObject GetObjectFromTag(Tag tag)
 {
     NXOpen.NXObject obj2 = null;
     try
     {
         obj2 = NXObjectManager.Get(tag) as NXOpen.NXObject;
     }
     catch
     {
     }
     return(obj2);
 }
예제 #10
0
        internal static Snap.NX.NXObject CreateNXObject(TaggedObject nxopenTaggedObject)
        {
            Snap.NX.NXObject obj2         = null;
            NXOpen.NXObject  nxopenObject = nxopenTaggedObject as NXOpen.NXObject;
            if (nxopenObject != null)
            {
                obj2 = new Snap.NX.NXObject(nxopenObject);
                NXOpen.Curve nxopenCurve = nxopenObject as NXOpen.Curve;
                if (nxopenCurve != null)
                {
                    obj2 = Snap.NX.Curve.CreateCurve(nxopenCurve);
                }
                switch (GetTypeFromTag(nxopenObject.Tag))
                {
                case ObjectTypes.Type.Point:
                    obj2 = new Snap.NX.Point((NXOpen.Point)nxopenObject);
                    break;

                case ObjectTypes.Type.DatumPlane:
                    obj2 = new Snap.NX.DatumPlane((DatumPlaneFeature)nxopenObject);
                    break;

                case ObjectTypes.Type.DatumAxis:
                    obj2 = new Snap.NX.DatumAxis((DatumAxisFeature)nxopenObject);
                    break;

                case ObjectTypes.Type.CoordinateSystem:
                    obj2 = new Snap.NX.CoordinateSystem((NXOpen.CoordinateSystem)nxopenObject);
                    break;

                case ObjectTypes.Type.Body:
                    obj2 = new Snap.NX.Body((NXOpen.Body)nxopenObject);
                    break;

                case ObjectTypes.Type.Face:
                    obj2 = Snap.NX.Face.CreateFace((NXOpen.Face)nxopenObject);
                    break;

                case ObjectTypes.Type.Edge:
                    obj2 = Snap.NX.Edge.CreateEdge((NXOpen.Edge)nxopenObject);
                    break;

                case ObjectTypes.Type.Feature:
                    obj2 = Snap.NX.Feature.CreateFeature((NXOpen.Features.Feature)nxopenObject);
                    break;

                case ObjectTypes.Type.Component:
                    return(new Snap.NX.Component((NXOpen.Assemblies.Component)nxopenObject));
                }
            }
            return(obj2);
        }
예제 #11
0
 public static void Delete(params Snap.NX.NXObject[] nxObjects)
 {
     NXOpen.NXObject[] objects = new NXOpen.NXObject[nxObjects.Length];
     for (int i = 0; i < nxObjects.Length; i++)
     {
         objects[i] = (NXOpen.NXObject)nxObjects[i].NXOpenTaggedObject;
     }
     Globals.UndoMarkId markId = Globals.SetUndoMark(Globals.MarkVisibility.Visible, "Snap_DeleteNXObjects999");
     Globals.Session.UpdateManager.ClearErrorList();
     Globals.Session.UpdateManager.AddToDeleteList(objects);
     Globals.Session.UpdateManager.DoUpdate((Session.UndoMarkId)markId);
     Globals.DeleteUndoMark(markId, "Snap_DeleteNXObjects999");
 }
예제 #12
0
 public static Snap.NX.NXObject Wrap(Tag nxopenNXObjectTag)
 {
     if (nxopenNXObjectTag == Tag.Null)
     {
         throw new ArgumentException("Input tag is NXOpen.Tag.Null");
     }
     NXOpen.NXObject objectFromTag = GetObjectFromTag(nxopenNXObjectTag);
     if (objectFromTag == null)
     {
         throw new ArgumentException("Input tag doesn't belong to an NXOpen.NXObject object");
     }
     return(objectFromTag);
 }
예제 #13
0
파일: Part.cs 프로젝트: suifengsigan/TEST_1
        internal static Snap.NX.Part CreatePart(string pathName, Templates templateType, Units unitType)
        {
            NXOpen.Part workPart    = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Part displayPart = (NXOpen.Part)Globals.DisplayPart;
            FileNew     new2        = Globals.Session.Parts.FileNew();

            for (int i = 0; i < TemplatesInfo.Length; i++)
            {
                if (templateType == ((Templates)TemplatesInfo[i].Key))
                {
                    if (unitType == Units.Inches)
                    {
                        new2.TemplateFileName = TemplatesInfo[i].Value[0];
                    }
                    else
                    {
                        new2.TemplateFileName = TemplatesInfo[i].Value[1];
                    }
                    new2.Application = TemplatesInfo[i].Key;
                    if (new2.TemplateFileName == "Blank")
                    {
                        new2.UseBlankTemplate = true;
                    }
                    else
                    {
                        new2.UseBlankTemplate = false;
                    }
                    break;
                }
            }
            if (unitType == Units.MilliMeters)
            {
                new2.Units = NXOpen.Part.Units.Millimeters;
            }
            else
            {
                new2.Units = NXOpen.Part.Units.Inches;
            }
            new2.NewFileName       = pathName;
            new2.MasterFileName    = "";
            new2.MakeDisplayedPart = true;
            NXOpen.NXObject obj2 = new2.Commit();
            new2.Destroy();
            if (workPart != null)
            {
                Globals.WorkPart    = workPart;
                Globals.DisplayPart = displayPart;
            }
            return((NXOpen.Part)obj2);
        }
        //------------------------------------------------------------------------------
        //Callback Name: update_cb
        //------------------------------------------------------------------------------
        public int update_cb(NXOpen.BlockStyler.UIBlock block)
        {
            try
            {
                if (block == LB_SelObjs)
                {
                    //---------Enter your code here-----------
                    button_Verify.Enable  = LB_SelObjs.GetSelectedItems().Length > 0 ? true : false;
                    button_Verify.Tooltip = button_Verify.Enable ? "" : "Select at least one object to verify";
                }
                else if (block == button_Verify)
                {
                    //---------Enter your code here-----------
                    foreach (int objIndex in LB_SelObjs.GetSelectedItems())
                    {
                        // Get selected object
                        NXOpen.NXObject targObj = theSession.Parts.ToArray()[objIndex];
                        lw.WriteFullline(Environment.NewLine +
                                         targObj.Name.ToUpper());

                        // Check if CAD object
                        if (targObj.GetType().ToString() != "NXOpen.Part")
                        {
                            lw.WriteFullline("   -> Skipped:  not a CAD object, but of type = " + targObj.GetType().ToString());
                            continue;
                        }

                        NXOpen.Part targCAD = (NXOpen.Part)targObj;

                        // Check if target CAD object is a Sheet Metal object
                        if (DetectSheetMetal(targCAD))
                        {
                            lw.WriteFullline("   -> SHEETMETAL");
                        }
                        else
                        {
                            lw.WriteFullline("   -> normal CAD");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(0);
        }
예제 #15
0
        internal static Snap.NX.DatumPlane CreateDatumPlane(Position position, Vector direction)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.DatumPlaneBuilder featureBuilder = workPart.Features.CreateDatumPlaneBuilder(null);
            NXOpen.Plane plane = featureBuilder.GetPlane();
            plane.SetMethod(PlaneTypes.MethodType.PointDir);
            Direction direction2 = Globals.NXOpenWorkPart.Directions.CreateDirection((Point3d)position, (Vector3d)direction, SmartObject.UpdateOption.WithinModeling);

            NXOpen.NXObject[] geom = new NXOpen.NXObject[] { workPart.Points.CreatePoint((Point3d)position), direction2 };
            plane.SetGeometry(geom);
            plane.Evaluate();
            DatumPlaneFeature datumPlaneFeature = (DatumPlaneFeature)Snap.NX.Feature.CommitFeature(featureBuilder);

            featureBuilder.Destroy();
            return(new Snap.NX.DatumPlane(datumPlaneFeature));
        }
예제 #16
0
        internal static Snap.NX.DatumPlane CreateDatumPlane(Snap.NX.ICurve curve, Snap.Number arcLength)
        {
            NXOpen.Features.DatumPlaneBuilder featureBuilder = Globals.WorkPart.NXOpenPart.Features.CreateDatumPlaneBuilder(null);
            NXOpen.Plane plane = featureBuilder.GetPlane();
            plane.SetMethod(PlaneTypes.MethodType.Frenet);
            NXOpen.NXObject[] geom = new NXOpen.NXObject[] { (NXOpen.NXObject)curve.NXOpenICurve };
            plane.SetGeometry(geom);
            plane.SetFrenetSubtype(PlaneTypes.FrenetSubtype.Tangent);
            plane.SetPercent(true);
            plane.SetExpression(arcLength.ToString());
            plane.Evaluate();
            DatumPlaneFeature datumPlaneFeature = (DatumPlaneFeature)Snap.NX.Feature.CommitFeature(featureBuilder);

            featureBuilder.Destroy();
            return(new Snap.NX.DatumPlane(datumPlaneFeature));
        }
예제 #17
0
        /// <summary>
        /// 移动对象
        /// </summary>
        public static void MoveObject(NXOpen.NXObject obj, Snap.Position point, Snap.Vector normal, double distance)
        {
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            NXOpen.Features.MoveObjectBuilder moveObjectBuilder1;
            moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(null);
            moveObjectBuilder1.ObjectToMoveObject.Add(obj);
            moveObjectBuilder1.TransformMotion.DistanceVector      = workPart.Directions.CreateDirection(point, normal, SmartObject.UpdateOption.WithinModeling);
            moveObjectBuilder1.TransformMotion.DistanceValue.Value = distance;
            moveObjectBuilder1.MoveObjectResult       = NXOpen.Features.MoveObjectBuilder.MoveObjectResultOptions.MoveOriginal;
            moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Distance;
            moveObjectBuilder1.Commit();
            moveObjectBuilder1.Destroy();
        }
예제 #18
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");
            }
        }
예제 #19
0
        public Snap.NX.Spline[] Divide()
        {
            Snap.NX.Spline     spline   = this.Copy();
            Snap.NX.Part       workPart = Globals.WorkPart;
            DivideCurveBuilder builder  = workPart.NXOpenPart.BaseFeatures.CreateDivideCurveBuilder(null);

            builder.Type            = DivideCurveBuilder.Types.AtKnotpoints;
            builder.KnotPointMethod = DivideCurveBuilder.KnotPointOption.AllKnotpoints;
            builder.DividingCurve.SetValue(spline.NXOpenCurve, workPart.NXOpenPart.Views.WorkView, (Point3d)spline.StartPoint);
            builder.Commit();
            NXOpen.NXObject[] committedObjects = builder.GetCommittedObjects();
            builder.Destroy();
            Snap.NX.Spline[] splineArray = new Snap.NX.Spline[committedObjects.Length];
            for (int i = 0; i < committedObjects.Length; i++)
            {
                NXOpen.NXObject obj1 = committedObjects[i];
                splineArray[i] = (NXOpen.Spline)committedObjects[i];
            }
            return(splineArray);
        }
예제 #20
0
        public Snap.NX.Spline ToSpline()
        {
            JoinCurvesBuilder builder = Globals.WorkPart.NXOpenPart.Features.CreateJoinCurvesBuilder(null);

            builder.DistanceTolerance         = Globals.DistanceTolerance;
            builder.AngleTolerance            = Globals.AngleTolerance;
            builder.Section.DistanceTolerance = Globals.DistanceTolerance;
            builder.Section.AngleTolerance    = Globals.AngleTolerance;
            builder.Section.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            builder.Section.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
            builder.CurveOptions.Associative      = false;
            builder.OutputCurveType               = JoinCurvesBuilder.OutputCurve.General;
            builder.CurveOptions.InputCurveOption = CurveOptions.InputCurve.Retain;
            SelectionIntentRule[] rules = Snap.NX.Section.CreateSelectionIntentRule(new Snap.NX.ICurve[] { this });
            builder.Section.AddToSection(rules, (NXOpen.NXObject) this, null, null, (Point3d)Snap.Position.Origin, NXOpen.Section.Mode.Create, false);
            builder.Commit();
            NXOpen.NXObject obj2 = builder.GetCommittedObjects()[0];
            builder.Destroy();
            return(new Snap.NX.Spline((NXOpen.Spline)obj2));
        }
예제 #21
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");
            }
        }
예제 #22
0
        // <summary>
        /// 按x,y,z 移动工件
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="moveX"></param>
        /// <param name="moveY"></param>
        /// <param name="moveZ"></param>
        /// <returns></returns>
        public static NXObject CreateMoveObjToXYZ(string moveX, string moveY, string moveZ, NXOpen.Features.MoveObject moveFeater = null, params NXObject[] objs)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Features.MoveObjectBuilder moveObjectBuilder1;
            moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(moveFeater);

            moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.DeltaXyz; //增量xyz
            moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurve.IsPercentUsed = true;
            moveObjectBuilder1.TransformMotion.DeltaEnum = NXOpen.GeometricUtilities.ModlMotion.Delta.ReferenceAcsWorkPart;

            moveObjectBuilder1.TransformMotion.DeltaXc.RightHandSide = moveX; //x增量

            moveObjectBuilder1.TransformMotion.DeltaYc.RightHandSide = moveY; //y增量

            moveObjectBuilder1.TransformMotion.DeltaZc.RightHandSide = moveZ; //增量
            moveObjectBuilder1.MoveParents = false;
            moveObjectBuilder1.Associative = true;
            bool added1;

            added1 = moveObjectBuilder1.ObjectToMoveObject.Add(objs);
            NXOpen.NXObject nXObject1 = null;
            try
            {
                nXObject1 = moveObjectBuilder1.Commit();
                return(nXObject1);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("MoveObject:CreateMoveObjToXYZ:      " + ex.Message);
                throw ex;
            }
            finally
            {
                moveObjectBuilder1.Destroy();
            }
        }
예제 #23
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Starting NX Golden Cantilever Journal");

        //Declare Part Variables
        //Convert Strings to doubles from the args
        double heightA   = System.Convert.ToDouble(args[0]);
        double length    = System.Convert.ToDouble(args[1]);
        double thickness = System.Convert.ToDouble(args[2]);


        //Declare part name for the part file and the IGES file
        string part_name     = args[3];
        string part_name_prt = part_name + ".prt";
        string part_name_igs = part_name + ".igs";

        //Measurements need to be converted from m to mm
        //length = 1000 * length;
        //thickness = 1000 * thickness;
        //heightA = 1000 * heightA;
        double heightB = 1.618 * heightA;


        //Convert necessary values back to strings because I already
        //converted them to doubles and I'm too lazy to go back and change
        //this since it works.
        string length_string    = System.Convert.ToString(length);
        string thickness_string = System.Convert.ToString(thickness);
        string heightA_string   = System.Convert.ToString(heightA);
        string heightB_string   = System.Convert.ToString(heightB);

        NXOpen.Session theSession = NXOpen.Session.GetSession();
        // ----------------------------------------------
        //   Menu: File->New...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId1;
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.FileNew fileNew1;
        fileNew1 = theSession.Parts.FileNew();

        theSession.SetUndoMarkName(markId1, "New Dialog");

        NXOpen.Session.UndoMarkId markId2;
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        theSession.DeleteUndoMark(markId2, null);

        NXOpen.Session.UndoMarkId markId3;
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        fileNew1.TemplateFileName = "model-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 = "Model";

        fileNew1.ItemType = "";

        fileNew1.Specialization = "";

        fileNew1.SetCanCreateAltrep(false);

        fileNew1.NewFileName = part_name_prt;

        fileNew1.MasterFileName = "";

        fileNew1.MakeDisplayedPart = true;

        NXOpen.NXObject nXObject1;
        nXObject1 = fileNew1.Commit();

        NXOpen.Part workPart    = theSession.Parts.Work;
        NXOpen.Part displayPart = theSession.Parts.Display;
        theSession.DeleteUndoMark(markId3, null);

        fileNew1.Destroy();

        theSession.ApplicationSwitchImmediate("UG_APP_MODELING");

        NXOpen.Session.UndoMarkId markId4;
        markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Enter Gateway");

        NXOpen.Session.UndoMarkId markId5;
        markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Enter Modeling");

        // ----------------------------------------------
        //   Menu: Insert->Sketch...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId6;
        markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.Sketch nullNXOpen_Sketch = null;
        NXOpen.SketchInPlaceBuilder sketchInPlaceBuilder1;
        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullNXOpen_Sketch);

        NXOpen.Unit       unit1 = (NXOpen.Unit)workPart.UnitCollection.FindObject("MilliMeter");
        NXOpen.Expression expression1;
        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.Expression expression2;
        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.SketchAlongPathBuilder sketchAlongPathBuilder1;
        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullNXOpen_Sketch);

        sketchAlongPathBuilder1.PlaneLocation.Expression.RightHandSide = "0";

        theSession.SetUndoMarkName(markId6, "Create Sketch Dialog");

        NXOpen.DatumPlane datumPlane1 = (NXOpen.DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) YZ plane");
        NXOpen.Point3d    point1      = new NXOpen.Point3d(11.1863449593062, 6.4875984180345, 0.0);
        sketchInPlaceBuilder1.PlaneOrFace.SetValue(datumPlane1, workPart.ModelingViews.WorkView, point1);

        NXOpen.Features.DatumCsys datumCsys1 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(0)");
        NXOpen.Point point2 = (NXOpen.Point)datumCsys1.FindObject("POINT 1");
        sketchInPlaceBuilder1.SketchOrigin = point2;

        sketchInPlaceBuilder1.PlaneOrFace.Value = null;

        sketchInPlaceBuilder1.PlaneOrFace.Value = datumPlane1;

        NXOpen.DatumAxis datumAxis1 = (NXOpen.DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis");
        sketchInPlaceBuilder1.Axis.Value = datumAxis1;

        NXOpen.Session.UndoMarkId markId7;
        markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.DeleteUndoMark(markId7, null);

        NXOpen.Session.UndoMarkId markId8;
        markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.Preferences.Sketch.CreateInferredConstraints = true;

        theSession.Preferences.Sketch.ContinuousAutoDimensioning = true;

        theSession.Preferences.Sketch.DimensionLabel = NXOpen.Preferences.SketchPreferences.DimensionLabelType.Expression;

        theSession.Preferences.Sketch.TextSizeFixed = true;

        theSession.Preferences.Sketch.FixedTextSize = 3.0;

        theSession.Preferences.Sketch.ConstraintSymbolSize = 3.0;

        theSession.Preferences.Sketch.DisplayObjectColor = false;

        theSession.Preferences.Sketch.DisplayObjectName = true;

        NXOpen.NXObject nXObject2;
        nXObject2 = sketchInPlaceBuilder1.Commit();

        NXOpen.Sketch           sketch1 = (NXOpen.Sketch)nXObject2;
        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

        NXOpen.Session.UndoMarkId markId9;
        markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "update");

        int nErrs1;

        nErrs1 = theSession.UpdateManager.DoUpdate(markId9);

        sketch1.Activate(NXOpen.Sketch.ViewReorient.True);

        theSession.DeleteUndoMark(markId8, null);

        theSession.SetUndoMarkName(markId6, "Create Sketch");

        sketchInPlaceBuilder1.Destroy();

        sketchAlongPathBuilder1.Destroy();

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression2);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression1);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        // ----------------------------------------------
        //   Menu: Insert->Sketch Curve->Line...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId10;
        markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Profile short list");

        NXOpen.Session.UndoMarkId markId11;
        markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        NXOpen.Expression expression3;
        expression3 = workPart.Expressions.CreateSystemExpression(length_string);

        theSession.SetUndoMarkVisibility(markId11, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Point3d endPoint1   = new NXOpen.Point3d(length, 0.0, 0.0);
        NXOpen.Line    line1;
        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

        theSession.ActiveSketch.AddGeometry(line1, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_1 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_1.Geometry  = line1;
        geom1_1.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_1    = new NXOpen.Sketch.ConstraintGeometry();
        NXOpen.Features.DatumCsys        datumCsys2 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("SKETCH(1:1B)");
        NXOpen.Point point3 = (NXOpen.Point)datumCsys2.FindObject("POINT 1");
        geom2_1.Geometry  = point3;
        geom2_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2_1.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint1;
        sketchGeometricConstraint1 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1);

        NXOpen.Sketch.ConstraintGeometry geom1 = new NXOpen.Sketch.ConstraintGeometry();
        geom1.Geometry  = line1;
        geom1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom1.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint2;
        sketchGeometricConstraint2 = theSession.ActiveSketch.CreateHorizontalConstraint(geom1);

        NXOpen.Sketch.DimensionGeometry dimObject1_1 = new NXOpen.Sketch.DimensionGeometry();
        dimObject1_1.Geometry    = line1;
        dimObject1_1.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_1.AssocValue  = 0;
        dimObject1_1.HelpPoint.X = 0.0;
        dimObject1_1.HelpPoint.Y = 0.0;
        dimObject1_1.HelpPoint.Z = 0.0;
        NXOpen.NXObject nullNXOpen_NXObject = null;
        dimObject1_1.View = nullNXOpen_NXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_1 = new NXOpen.Sketch.DimensionGeometry();
        dimObject2_1.Geometry    = line1;
        dimObject2_1.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_1.AssocValue  = 0;
        dimObject2_1.HelpPoint.X = 0.0;
        dimObject2_1.HelpPoint.Y = 0.0;
        dimObject2_1.HelpPoint.Z = 0.0;
        dimObject2_1.View        = nullNXOpen_NXObject;
        NXOpen.Point3d dimOrigin1 = new NXOpen.Point3d(45.0, -9.0598069411704, 0.0);
        NXOpen.SketchDimensionalConstraint sketchDimensionalConstraint1;
        sketchDimensionalConstraint1 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_1, dimObject2_1, dimOrigin1, expression3, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        NXOpen.SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint1 = (NXOpen.SketchHelpedDimensionalConstraint)sketchDimensionalConstraint1;
        NXOpen.Annotations.Dimension             dimension1;
        dimension1 = sketchHelpedDimensionalConstraint1.AssociatedDimension;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId12;
        markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        NXOpen.Expression expression4;
        expression4 = workPart.Expressions.CreateSystemExpression(heightA_string);

        NXOpen.Expression expression5;
        expression5 = workPart.Expressions.CreateSystemExpression(length_string);

        workPart.Expressions.Edit(expression4, heightA_string);

        theSession.SetUndoMarkVisibility(markId12, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint2 = new NXOpen.Point3d(length, 0.0, 0.0);
        NXOpen.Point3d endPoint2   = new NXOpen.Point3d(length, heightA, 0.0);
        NXOpen.Line    line2;
        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

        theSession.ActiveSketch.AddGeometry(line2, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_2 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_2.Geometry  = line2;
        geom1_2.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_2 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_2.Geometry  = line1;
        geom2_2.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom2_2.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint3;
        sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2);

        NXOpen.Sketch.ConstraintGeometry geom2 = new NXOpen.Sketch.ConstraintGeometry();
        geom2.Geometry  = line2;
        geom2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint4;
        sketchGeometricConstraint4 = theSession.ActiveSketch.CreateVerticalConstraint(geom2);

        workPart.Expressions.Delete(expression5);

        NXOpen.Sketch.DimensionGeometry dimObject1_2 = new NXOpen.Sketch.DimensionGeometry();
        dimObject1_2.Geometry    = line2;
        dimObject1_2.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_2.AssocValue  = 0;
        dimObject1_2.HelpPoint.X = 0.0;
        dimObject1_2.HelpPoint.Y = 0.0;
        dimObject1_2.HelpPoint.Z = 0.0;
        dimObject1_2.View        = nullNXOpen_NXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_2 = new NXOpen.Sketch.DimensionGeometry();
        dimObject2_2.Geometry    = line2;
        dimObject2_2.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_2.AssocValue  = 0;
        dimObject2_2.HelpPoint.X = 0.0;
        dimObject2_2.HelpPoint.Y = 0.0;
        dimObject2_2.HelpPoint.Z = 0.0;
        dimObject2_2.View        = nullNXOpen_NXObject;
        NXOpen.Point3d dimOrigin2 = new NXOpen.Point3d(99.0598069411704, 15.0, 0.0);
        NXOpen.SketchDimensionalConstraint sketchDimensionalConstraint2;
        sketchDimensionalConstraint2 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_2, dimObject2_2, dimOrigin2, expression4, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        NXOpen.SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint2 = (NXOpen.SketchHelpedDimensionalConstraint)sketchDimensionalConstraint2;
        NXOpen.Annotations.Dimension             dimension2;
        dimension2 = sketchHelpedDimensionalConstraint2.AssociatedDimension;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId13;
        markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        NXOpen.Expression expression6;
        expression6 = workPart.Expressions.CreateSystemExpression(heightB_string);

        NXOpen.Expression expression7;
        expression7 = workPart.Expressions.CreateSystemExpression(length_string);

        theSession.SetUndoMarkVisibility(markId13, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint3 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Point3d endPoint3   = new NXOpen.Point3d(7.02873218749514e-014, heightB, 0.0);
        NXOpen.Line    line3;
        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

        theSession.ActiveSketch.AddGeometry(line3, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_3 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_3.Geometry  = line3;
        geom1_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_3 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_3.Geometry  = line1;
        geom2_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_3.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint5;
        sketchGeometricConstraint5 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_3, geom2_3);

        NXOpen.Sketch.ConstraintGeometry geom3 = new NXOpen.Sketch.ConstraintGeometry();
        geom3.Geometry  = line3;
        geom3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom3.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint6;
        sketchGeometricConstraint6 = theSession.ActiveSketch.CreateVerticalConstraint(geom3);

        workPart.Expressions.Delete(expression7);

        NXOpen.Sketch.DimensionGeometry dimObject1_3 = new NXOpen.Sketch.DimensionGeometry();
        dimObject1_3.Geometry    = line3;
        dimObject1_3.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_3.AssocValue  = 0;
        dimObject1_3.HelpPoint.X = 0.0;
        dimObject1_3.HelpPoint.Y = 0.0;
        dimObject1_3.HelpPoint.Z = 0.0;
        dimObject1_3.View        = nullNXOpen_NXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_3 = new NXOpen.Sketch.DimensionGeometry();
        dimObject2_3.Geometry    = line3;
        dimObject2_3.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_3.AssocValue  = 0;
        dimObject2_3.HelpPoint.X = 0.0;
        dimObject2_3.HelpPoint.Y = 0.0;
        dimObject2_3.HelpPoint.Z = 0.0;
        dimObject2_3.View        = nullNXOpen_NXObject;
        NXOpen.Point3d dimOrigin3 = new NXOpen.Point3d(9.05980694117043, heightA, 0.0);
        NXOpen.SketchDimensionalConstraint sketchDimensionalConstraint3;
        sketchDimensionalConstraint3 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_3, dimObject2_3, dimOrigin3, expression6, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        NXOpen.SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint3 = (NXOpen.SketchHelpedDimensionalConstraint)sketchDimensionalConstraint3;
        NXOpen.Annotations.Dimension             dimension3;
        dimension3 = sketchHelpedDimensionalConstraint3.AssociatedDimension;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId14;
        markId14 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        theSession.SetUndoMarkVisibility(markId14, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint4 = new NXOpen.Point3d(0.0, heightB, 0.0);
        NXOpen.Point3d endPoint4   = new NXOpen.Point3d(length, heightA, 0.0);
        //NXOpen.Point3d endPoint4 = new NXOpen.Point3d(90.0, 29.9999999999998, 0.0);
        NXOpen.Line line4;
        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

        theSession.ActiveSketch.AddGeometry(line4, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_4 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_4.Geometry  = line4;
        geom1_4.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_4 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_4.Geometry  = line3;
        geom2_4.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom2_4.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint7;
        sketchGeometricConstraint7 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_4, geom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1_5 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_5.Geometry  = line4;
        geom1_5.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_5.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_5 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_5.Geometry  = line2;
        geom2_5.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom2_5.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint8;
        sketchGeometricConstraint8 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_5, geom2_5);

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId15;
        markId15 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Deactivate Sketch");

        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

        // ----------------------------------------------
        //   Menu: Insert->Design Feature->Extrude...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId16;
        markId16 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.Features.Feature nullNXOpen_Features_Feature = null;

        if (!workPart.Preferences.Modeling.GetHistoryMode())
        {
            throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
        }

        NXOpen.Features.ExtrudeBuilder extrudeBuilder1;
        extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature);

        NXOpen.Section section1;
        section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5);

        extrudeBuilder1.Section = section1;

        extrudeBuilder1.AllowSelfIntersectingSection(true);

        NXOpen.Unit unit2;
        unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units;

        NXOpen.Expression expression8;
        expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2);

        extrudeBuilder1.DistanceTolerance = 0.01;

        extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

        NXOpen.Body[] targetBodies1   = new NXOpen.Body[1];
        NXOpen.Body   nullNXOpen_Body = null;
        targetBodies1[0] = nullNXOpen_Body;
        extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1);

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = "25";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = thickness_string;

        extrudeBuilder1.Draft.FrontDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Draft.BackDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        NXOpen.GeometricUtilities.SmartVolumeProfileBuilder smartVolumeProfileBuilder1;
        smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile;

        smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = false;

        smartVolumeProfileBuilder1.CloseProfileRule = NXOpen.GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci;

        theSession.SetUndoMarkName(markId16, "Extrude Dialog");

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

        section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

        NXOpen.Session.UndoMarkId markId17;
        markId17 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");

        NXOpen.Session.UndoMarkId markId18;
        markId18 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);

        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)feature1;
        features1[0] = sketchFeature1;
        NXOpen.CurveFeatureRule curveFeatureRule1;
        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(53.8762063337749, 42.0412645554082, 0.0);
        section1.AddToSection(rules1, line4, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

        theSession.DeleteUndoMark(markId18, null);

        NXOpen.Direction direction1;
        direction1 = workPart.Directions.CreateDirection(sketch1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling);

        extrudeBuilder1.Direction = direction1;

        theSession.DeleteUndoMark(markId17, null);

        NXOpen.Session.UndoMarkId markId19;
        markId19 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        theSession.DeleteUndoMark(markId19, null);

        NXOpen.Session.UndoMarkId markId20;
        markId20 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        extrudeBuilder1.ParentFeatureInternal = false;

        NXOpen.Features.Feature feature2;
        feature2 = extrudeBuilder1.CommitFeature();

        theSession.DeleteUndoMark(markId20, null);

        theSession.SetUndoMarkName(markId16, "Extrude");

        NXOpen.Expression expression9  = extrudeBuilder1.Limits.StartExtend.Value;
        NXOpen.Expression expression10 = extrudeBuilder1.Limits.EndExtend.Value;
        extrudeBuilder1.Destroy();

        workPart.Expressions.Delete(expression8);

        // ----------------------------------------------
        //   Menu: File->Save
        // ----------------------------------------------
        NXOpen.PartSaveStatus partSaveStatus1;
        partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

        partSaveStatus1.Dispose();
        // ----------------------------------------------
        //   Menu: File->Export->IGES...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId21;
        markId21 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.IgesCreator igesCreator1;
        igesCreator1 = theSession.DexManager.CreateIgesCreator();

        igesCreator1.ExportModelData = true;

        igesCreator1.ExportDrawings = true;

        igesCreator1.MapTabCylToBSurf = true;

        igesCreator1.BcurveTol = 0.0508;

        igesCreator1.IdenticalPointResolution = 0.001;

        igesCreator1.MaxThreeDMdlSpace = 10000.0;

        igesCreator1.ObjectTypes.Curves = true;

        igesCreator1.ObjectTypes.Surfaces = true;

        igesCreator1.ObjectTypes.Annotations = true;

        igesCreator1.ObjectTypes.Structures = true;

        igesCreator1.ObjectTypes.Solids = true;

        igesCreator1.OutputFile = part_name_igs;

        igesCreator1.SettingsFile = "C:\\Program Files\\Siemens\\NX 10.0\\iges\\igesexport.def";

        igesCreator1.MaxLineThickness = 2.0;

        igesCreator1.SysDefmaxThreeDMdlSpace = true;

        igesCreator1.SysDefidenticalPointResolution = true;

        igesCreator1.InputFile = part_name_prt;

        igesCreator1.OutputFile = part_name_igs;

        theSession.SetUndoMarkName(markId21, "Export to IGES Options Dialog");

        igesCreator1.OutputFile = part_name_igs;

        NXOpen.Session.UndoMarkId markId22;
        markId22 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export to IGES Options");

        theSession.DeleteUndoMark(markId22, null);

        NXOpen.Session.UndoMarkId markId23;
        markId23 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export to IGES Options");

        igesCreator1.FileSaveFlag = false;

        igesCreator1.LayerMask = "1-256";

        igesCreator1.DrawingList = "";

        igesCreator1.ViewList = "Top,Front,Right,Back,Bottom,Left,Isometric,Trimetric,User Defined";

        NXOpen.NXObject nXObject3;
        nXObject3 = igesCreator1.Commit();

        theSession.DeleteUndoMark(markId23, null);

        theSession.SetUndoMarkName(markId21, "Export to IGES Options");

        igesCreator1.Destroy();

        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------

        Console.WriteLine("Finishing NX Golden Cantilever Journal");
    }
예제 #24
0
파일: ano.cs 프로젝트: sadgood/410proj
    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    public int update_cb(NXOpen.BlockStyler.UIBlock block)
    {
        try
        {
            if (block == enum0)
            {
                Part   workPart  = theSession.Parts.Work;
                Layout layout1   = (Layout)workPart.Layouts.FindObject("L1");//此处写死了。。。。。TAG ERROR
                int    sel       = enum0.GetProperties().GetEnum("Value");
                string addnewstr = enum0.GetProperties().GetEnumAsString("Value");
                if (addnewstr != "添加新视图")
                {
                    layout1.ReplaceView(workPart.ModelingViews.WorkView, aaa[sel], true);
                }
                else
                {
                    newviewname.GetProperties().SetLogical("Show", true);

                    //string newviewname = null;
                    ////add.Show_add();
                    //add theadd = new add();
                    //theadd.Show();
                    //newviewname = theaddnew.string0.GetProperties().GetString("Value");
                }

                //---------Enter your code here-----------
            }
            else if (block == ifcro)
            {
                if (ifcro.GetProperties().GetLogical("Value"))
                {
                    cro.GetProperties().SetLogical("Enable", true);
                }
                else if (!ifcro.GetProperties().GetLogical("Value"))
                {
                    cro.GetProperties().SetLogical("Enable", false);
                }


                //---------Enter your code here-----------
            }
            else if (block == cro)
            {
                //---------Enter your code here-----------
            }
            else if (block == realanno)
            {
                //---------Enter your code here-----------
            }
            else if (block == iflabel)
            {
                if (iflabel.GetProperties().GetLogical("Value"))
                {
                    selection01.GetProperties().SetLogical("Enable", true);
                }
                else if (!iflabel.GetProperties().GetLogical("Value"))
                {
                    selection01.GetProperties().SetLogical("Enable", false);
                }
                //---------Enter your code here-----------
            }
            else if (block == selection01)
            {
                //---------Enter your code here-----------
            }
            else if (block == point0)
            {
                NXOpen.TaggedObject[]    guanlian    = null;
                NXOpen.DisplayableObject guanlianobj = null;
                if (ifcro.GetProperties().GetLogical("Value") == true)
                {
                    guanlian = cro.GetProperties().GetTaggedObjectVector("SelectedObjects");
                    if (guanlian.Length == 0)
                    {
                        theUI.NXMessageBox.Show("未选择关联对象", NXMessageBox.DialogType.Warning, "请选择关联对象");

                        return(1);
                    }
                    guanlianobj = Tag2NXObject <DisplayableObject>(guanlian[0].Tag);//这个是关联对象
                }

                string[] zhushiwenzi = null;
                zhushiwenzi = realanno.GetProperties().GetStrings("Value");//这个是注释文字
                // int ps = zhushiwenzi[0].Length;
                //if (zhushiwenzi == null)
                //{

                //    theUI.NXMessageBox.Show("警告", NXMessageBox.DialogType.Error, "注释文字不能为空");
                //}
                NXOpen.TaggedObject[] zhiyin    = null;
                NXOpen.NXObject       zhiyinobj = null;

                if (iflabel.GetProperties().GetLogical("Value") == true)
                {
                    zhiyin = selection01.GetProperties().GetTaggedObjectVector("SelectedObjects");
                    if (zhiyin.Length == 0)
                    {
                        theUI.NXMessageBox.Show("未选择Label放置点", NXMessageBox.DialogType.Warning, "请选择Label放置点");
                        return(1);
                    }
                    zhiyinobj = Tag2NXObject <NXObject>(zhiyin[0].Tag);//指引线
                }
                NXOpen.TaggedObject[] placept = null;
                placept = point0.GetProperties().GetTaggedObjectVector("SelectedObjects");
                Point   placeptobj   = Tag2NXObject <Point>(placept[0].Tag);//注释最后的放置点
                Point3d placeptobj3d = placeptobj.Coordinates;
                //---------Enter our code here-----------
                SetSBF();
                thenotefun.function_note(zhushiwenzi, guanlianobj, zhiyinobj, placeptobj3d);
            }
            else if (block == dic)
            {
                //---------Enter your code here-----------
            }
            else if (block == newviewname)
            {
                Part workPart = theSession.Parts.Work;
                viewname = newviewname.GetProperties().GetString("Value");
                workPart.Views.SaveAs(workPart.ModelingViews.WorkView, viewname, true, false);
                refreshenum();

                //enum0.GetProperties().SetEnumAsString("Value", viewname);//TAG undone
                //enum0.GetProperties().get
                //---------Enter your code here-----------
            }
            else if (block == str)
            {
                //---------Enter your code here-----------
            }
            else if (block == button0)   //这个就是添加按钮,在这里调用
            {
                string[] diction = null; //这个有”添加至CAPP助手“中得到的字符串
                diction = dic.GetProperties().GetStrings("Value");
                if (diction == null)
                {
                    theUI.NXMessageBox.Show("警告", NXMessageBox.DialogType.Error, "添加文字不能为空");
                }
                string strvalue = str.GetProperties().GetEnumAsString("Value");

                thenotefun.Xmlforcapp(strvalue, diction[0]);

                StopProcess("CAPP助手");
                OpenFile(ApplicationPath + folderpath + cappass);
                //switch (strvalue)
                //{
                //    case "加工前准备":

                //        break;
                //    case "工作内容":


                //        break;
                //    case "技术条件":

                //        break;
                //    case "附注":

                //        break;
                //    case "特种工艺术语":

                //        break;
                //    case "检验工序":

                //        break;
                //    case "常用符号":

                //        break;


                //}
                //---------Enter your code here-----------
            }
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return(0);
    }
예제 #25
0
        public virtual Snap.NX.NXObject Copy(Transform xform)
        {
            Snap.NX.NXObject obj3;
            UFSession        uFSession = Globals.UFSession;
            int num = 1;

            Tag[] objects = new Tag[] { this.NXOpenTag };
            int   num2    = 2;
            int   num3    = 0;
            int   num4    = 2;

            Tag[] copies = new Tag[num];
            int   status = 0;

            try
            {
                Tag tag;
                uFSession.Trns.TransformObjects(xform.Matrix, objects, ref num, ref num2, ref num3, ref num4, copies, out tag, out status);
                switch (status)
                {
                case 3:
                    throw NXException.Create(0xa4c2d);

                case 4:
                    throw new ArgumentException("The matrix does not preserve angles");

                case 5:
                    throw NXException.Create(0xa3948);

                case 6:
                    throw NXException.Create(0xa3938);

                case 7:
                    throw NXException.Create(0xa3939);

                case 8:
                    throw NXException.Create(0x25);

                case 9:
                    throw NXException.Create(0xa3946);

                case 10:
                    throw NXException.Create(0xa3947);

                case 11:
                    throw NXException.Create(0xa1222);
                }
                if ((status == 0) && (copies[0] == Tag.Null))
                {
                    throw NXException.Create(0xa4c2d);
                }
                Snap.NX.NXObject[] objArray = new Snap.NX.NXObject[num];
                for (int i = 0; i < num; i++)
                {
                    NXOpen.NXObject objectFromTag = GetObjectFromTag(copies[i]);
                    objArray[i] = CreateNXObject(objectFromTag);
                }
                obj3 = objArray[0];
            }
            catch (NXException exception)
            {
                if (this.ObjectType == ObjectTypes.Type.Edge)
                {
                    throw new ArgumentException("The object is an edge. Edges cannot be copied", exception);
                }
                if (this.ObjectType == ObjectTypes.Type.Face)
                {
                    throw new ArgumentException("The object is a face. Faces cannot be copied", exception);
                }
                if (((this.ObjectType == ObjectTypes.Type.Feature) || (this.ObjectType == ObjectTypes.Type.DatumPlane)) || (this.ObjectType == ObjectTypes.Type.DatumAxis))
                {
                    throw new ArgumentException("A feature cannot be copied unless all of its ancestors are copied too", exception);
                }
                if (this.ObjectType == ObjectTypes.Type.CoordinateSystem)
                {
                    throw new ArgumentException("A transform that does not preserve angles cannot be applied to a coordinate system");
                }
                throw exception;
            }
            return(obj3);
        }
예제 #26
0
 public NXObject(NXOpen.NXObject nxopenObject)
 {
     this.NXOpenTaggedObject = nxopenObject;
 }
예제 #27
0
        public void ToNXFile(Session nxSession)
        {
            NXOpen.Part nxSubAssem;
            var         newFile = new NewNXfile();
            var         fileDir = new NewNXfile();

            for (int i = 0; i < compCount; i++)
            {
                nxRootAssem = nxSession.Parts.Work;
                if (compName[i] == "Default SubAssembly")
                {
                    continue;
                }
                NXOpen.FileNew compFile = nxSession.Parts.FileNew();
                newFile.NXfile(compFile, fileDir.subassemdir(compName[i]));
                compFile.MakeDisplayedPart = false;
                NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;
                createNewComponentBuilder1 = nxRootAssem.AssemblyManager.CreateNewComponentBuilder();
                createNewComponentBuilder1.NewComponentName = compName[i];
                createNewComponentBuilder1.ReferenceSet     = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;
                createNewComponentBuilder1.ReferenceSetName = "Entire Part";
                createNewComponentBuilder1.NewFile          = compFile;
                NXOpen.NXObject nXObject_SubAssem = createNewComponentBuilder1.Commit();
                createNewComponentBuilder1.Destroy();
                nxSubAssem = (NXOpen.Part)nxSession.Parts.FindObject(compName[i]);
                NXObject[] nxGeom = new NXObject[partCount];
                for (int j = 0; j < partCount; j++)
                {
                    NXOpen.BasePart       basePart1;
                    NXOpen.PartLoadStatus partLoadStatus, partLoadStatus2;
                    basePart1 = nxSession.Parts.OpenBase(fileDir.partdir(partFileName[j]), out partLoadStatus);
                    partLoadStatus.Dispose();
                    basepoint1      = new NXOpen.Point3d(0.0, 0.0, 0.0);
                    orientation1    = new NXOpen.Matrix3x3();
                    orientation1.Xx = 1.0;
                    orientation1.Xy = 0.0;
                    orientation1.Xz = 0.0;
                    orientation1.Yx = 0.0;
                    orientation1.Yy = 1.0;
                    orientation1.Yz = 0.0;
                    orientation1.Zx = 0.0;
                    orientation1.Zy = 0.0;
                    orientation1.Zz = 1.0;
                    NXOpen.Assemblies.Component component1;
                    component1 = nxRootAssem.ComponentAssembly.AddComponent(fileDir.partdir(partFileName[j]), "MODEL", "A1-1", basepoint1, orientation1, -1, out partLoadStatus2, true);
                    partLoadStatus2.Dispose();
                    NXOpen.Assemblies.Component[] origComponents1 = new NXOpen.Assemblies.Component[1];
                    origComponents1[0] = component1;
                    NXOpen.Assemblies.Component   component2 = (NXOpen.Assemblies.Component)nXObject_SubAssem;
                    NXOpen.Assemblies.Component[] newComponents1;
                    NXOpen.ErrorList errorList1;
                    nxSubAssem.ComponentAssembly.RestructureComponents(origComponents1, component2, true, out newComponents1, out errorList1);
                    errorList1.Dispose();
                    nxGeom[i] = origComponents1[0];
                    string reef = nxGeom[i].OwningComponent.DisplayName;
                    Console.WriteLine("*************************" + reef);
                }
                /*Working Information with Hardcoded information;*/
                ComponentPositioner[]         tempcomponentPositioner1 = new ComponentPositioner[2];
                ComponentConstraint[]         tempcomponentConstraint1 = new ComponentConstraint[2];
                ComponentPositioner[]         componentPositioner1     = new ComponentPositioner[2];
                ComponentPositioner[]         componentPositioner2     = new ComponentPositioner[2];
                ComponentConstraint[]         componentConstraint1     = new ComponentConstraint[2];
                ComponentConstraint[]         componentConstraint2     = new ComponentConstraint[2];
                NXOpen.Assemblies.Component[] component01 = new Component[2];
                NXOpen.Assemblies.Component[] component02 = new Component[2];
                for (int m = 0; m < 2; m++)
                {
                    component01[m] = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[m] + " 1");
                    //NXOpen.Assemblies.Component component02 = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[0] + " 1");
                }

                /*
                 * tempcomponentPositioner1[0] = nxSubAssem.ComponentAssembly.Positioner;
                 * tempcomponentPositioner1[0].BeginAssemblyConstraints();
                 * Constraint tempconstraint1;
                 * tempconstraint1 = tempcomponentPositioner1[0].CreateConstraint(true);
                 * tempcomponentConstraint1[0] = (NXOpen.Positioning.ComponentConstraint)tempconstraint1;
                 * tempcomponentConstraint1[0].ConstraintType = NXOpen.Positioning.Constraint.Type.Concentric;
                 * Edge edge1 = (NXOpen.Edge)component01[0].FindObject(EdgeNames[0]);
                 * ConstraintReference ConsRef1 = tempcomponentConstraint1[0].CreateConstraintReference(component01[0],edge1,false,false,false);
                 * Edge edge2 = (NXOpen.Edge)component01[1].FindObject(EdgeNames[1]);
                 * ConstraintReference ConsRef2 = tempcomponentConstraint1[0].CreateConstraintReference(component01[1], edge2, false, false, false);
                 */


                for (int k = 0; k < 2; k++)
                {
                    if (constNamesTemp[k].Contains("Coaxial"))
                    {
                        componentPositioner1[k] = nxSubAssem.ComponentAssembly.Positioner;
                        componentPositioner1[k].BeginAssemblyConstraints();
                        Constraint constraint1;
                        constraint1             = componentPositioner1[k].CreateConstraint(true);
                        componentConstraint1[k] = (NXOpen.Positioning.ComponentConstraint)constraint1;
                        //componentConstraint1[k].ConstraintAlignment = NXOpen.Positioning.Constraint.Alignment.ContraAlign;
                        componentConstraint1[k].ConstraintType = NXOpen.Positioning.Constraint.Type.Fit;
                        NXOpen.Face face1 = (NXOpen.Face)component01[0].FindObject(ConstNames1[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference1;
                        constraintReference1 = componentConstraint1[k].CreateConstraintReference(component01[0], face1, false, false, false);
                        component01[1]       = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[1] + " 1");
                        NXOpen.Face face2 = (NXOpen.Face)component01[1].FindObject(ConstNames2[k]);
                        //Face face3 = (NXOpen.Face)component01[1].FindObject(ConstNames2[1]);
                        NXOpen.Positioning.ConstraintReference constraintReference2;
                        constraintReference2 = componentConstraint1[k].CreateConstraintReference(component01[1], face2, false, false, false);
                    }
                    else
                    {
                        componentPositioner2[k] = nxSubAssem.ComponentAssembly.Positioner;
                        componentPositioner2[k].BeginAssemblyConstraints();
                        Constraint constraint1;
                        constraint1             = componentPositioner2[k].CreateConstraint(true);
                        componentConstraint2[k] = (NXOpen.Positioning.ComponentConstraint)constraint1;
                        //componentConstraint2[k].ConstraintAlignment = NXOpen.Positioning.Constraint.Alignment.InferAlign;
                        componentConstraint2[k].ConstraintType = NXOpen.Positioning.Constraint.Type.Touch;
                        NXOpen.Face face1 = (NXOpen.Face)component01[0].FindObject(ConstNames1[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference3;
                        constraintReference3 = componentConstraint2[k].CreateConstraintReference(component01[0], face1, false, false, false);
                        component01[1]       = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[1] + " 1");
                        NXOpen.Face face2 = (NXOpen.Face)component01[1].FindObject(ConstNames2[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference4;
                        constraintReference4 = componentConstraint2[k].CreateConstraintReference(component01[1], face2, false, false, false);
                        constraintReference4.SetFixHint(true);
                    }
                }
                break;
            }
            PartSaveStatus fileSave;

            fileSave = nxRootAssem.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False);
        }
예제 #28
0
파일: ano.cs 프로젝트: sadgood/410proj
    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    public int update_cb(NXOpen.BlockStyler.UIBlock block)
    {
        try
        {
            if (block == enum0)
            {
                Part   workPart  = theSession.Parts.Work;
                Layout layout1   = (Layout)workPart.Layouts.FindObject("L1");//此处写死了。。。。。TAG ERROR
                int    sel       = enum0.GetProperties().GetEnum("Value");
                string addnewstr = enum0.GetProperties().GetEnumAsString("Value");
                if (addnewstr != "添加新视图")
                {
                    layout1.ReplaceView(workPart.ModelingViews.WorkView, aaa[sel], true);
                }
                else
                {
                    string newviewname = null;
                    addnew.Show_addnew();
                    addnew theaddnew = new addnew();
                    //newviewname = theaddnew.string0.GetProperties().GetString("Value");
                    //switch (theUI.NXMessageBox.Show("添加新视图", NXMessageBox.DialogType.Question, "是否添加新视图"))
                    //{
                    //    case 0:

                    //        break;
                    //    case 1:

                    //        break;

                    //}
                }

                //---------Enter your code here-----------
            }
            else if (block == ifcro)
            {
                if (ifcro.GetProperties().GetLogical("Value"))
                {
                    cro.GetProperties().SetLogical("Enable", true);
                }
                else if (!ifcro.GetProperties().GetLogical("Value"))
                {
                    cro.GetProperties().SetLogical("Enable", false);
                }


                //---------Enter your code here-----------
            }
            else if (block == cro)
            {
                //---------Enter your code here-----------
            }
            else if (block == realanno)
            {
                //---------Enter your code here-----------
            }
            else if (block == iflabel)
            {
                //---------Enter your code here-----------
            }
            else if (block == selection01)
            {
                if (iflabel.GetProperties().GetLogical("Value"))
                {
                    selection01.GetProperties().SetLogical("Enable", true);
                }
                else if (!iflabel.GetProperties().GetLogical("Value"))
                {
                    selection01.GetProperties().SetLogical("Enable", false);
                }
                //---------Enter your code here-----------
            }
            else if (block == point0)
            {
                NXOpen.TaggedObject[]    guanlian    = null;
                NXOpen.DisplayableObject guanlianobj = null;
                if (ifcro.GetProperties().GetLogical("Value") == true)
                {
                    guanlian    = cro.GetProperties().GetTaggedObjectVector("SelectedObjects");
                    guanlianobj = Tag2NXObject <DisplayableObject>(guanlian[0].Tag);//这个是关联对象
                }


                string[] zhushiwenzi = realanno.GetProperties().GetStrings("Value");//这个是注释文字

                NXOpen.TaggedObject[] zhiyin    = null;
                NXOpen.NXObject       zhiyinobj = null;

                if (iflabel.GetProperties().GetLogical("Value") == true)
                {
                    zhiyin = selection01.GetProperties().GetTaggedObjectVector("SelectedObjects");

                    zhiyinobj = Tag2NXObject <NXObject>(zhiyin[0].Tag);//指引线
                }
                NXOpen.TaggedObject[] placept = null;
                placept = point0.GetProperties().GetTaggedObjectVector("SelectedObjects");
                Point   placeptobj   = Tag2NXObject <Point>(placept[0].Tag);//注释最后的放置点
                Point3d placeptobj3d = placeptobj.Coordinates;
                //---------Enter our code here-----------

                thenotefun.function_note(zhushiwenzi, guanlianobj, zhiyinobj, placeptobj3d);
            }
            else if (block == dic)
            {
                //---------Enter your code here-----------
            }
            else if (block == str)
            {
                //---------Enter your code here-----------
            }
            else if (block == button0) //这个就是添加按钮,在这里调用
            {
                string diction = null; //这个有”添加至CAPP助手“中得到的字符串
                diction = dic.GetProperties().GetString("Value");
                string strvalue = str.GetProperties().GetEnumAsString("Value");
                switch (strvalue)
                {
                case "加工前准备":

                    break;

                case "工作内容":


                    break;

                case "技术条件":

                    break;

                case "附注":

                    break;

                case "特种工艺术语":

                    break;

                case "检验工序":

                    break;

                case "常用符号":

                    break;
                }
                //---------Enter your code here-----------
            }
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return(0);
    }
예제 #29
0
파일: Body.cs 프로젝트: suifengsigan/TEST_1
 internal Body(NXOpen.NXObject nxopenObject) : base(nxopenObject)
 {
     this.NXOpenBody = (NXOpen.Body)nxopenObject;
 }
예제 #30
0
 protected Curve(NXOpen.NXObject nxopenObject) : base(nxopenObject)
 {
     base.NXOpenTaggedObject = nxopenObject;
 }