Пример #1
0
        /// <summary>
        /// 布尔操作
        /// </summary>
        /// <param name="targetBody">目标体</param>
        /// <param name="toolBody">工具体</param>
        /// <param name="copyTools">复制工具</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static NXOpen.Features.BooleanFeature CreateBooleanFeature(Body targetBody, bool copyTargets, bool copyTools, NXOpen.Features.Feature.BooleanType type, params Body[] toolBody)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.BooleanFeature nullNXOpen_Features_BooleanFeature = null;
            NXOpen.Features.BooleanBuilder booleanBuilder1 = workPart.Features.CreateBooleanBuilderUsingCollector(nullNXOpen_Features_BooleanFeature);
            booleanBuilder1.CopyTargets = copyTargets;
            booleanBuilder1.CopyTools   = copyTools;
            booleanBuilder1.Operation   = type;

            bool added1 = booleanBuilder1.Targets.Add(targetBody);

            NXOpen.ScCollector scCollector = workPart.ScCollectors.CreateCollector();
            ISelectionRule     rule        = new SelectionBodyRule(toolBody.ToList());

            SelectionIntentRule[] rules = { rule.CreateSelectionRule() };
            scCollector.ReplaceRules(rules, false);
            booleanBuilder1.ToolBodyCollector = scCollector;
            try
            {
                NXOpen.Features.Feature boolFeature = booleanBuilder1.CommitFeature();
                return(boolFeature as NXOpen.Features.BooleanFeature);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("Basic.BooleanUtils.CreateBooleanFeature:错误:" + ex.Message);
                throw ex;
            }
            finally
            {
                booleanBuilder1.Destroy();
            }
        }
Пример #2
0
        /// <summary>
        /// 设置连接体
        /// </summary>
        public void WaveBodys()
        {
            Part      workPart     = Session.GetSession().Parts.Work;
            UFSession theUFSession = UFSession.GetUFSession();

            if (workPart.Tag != this.PartTag.Tag)
            {
                NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, this.PartTag);
                PartUtils.SetPartWork(ct);
            }
            foreach (Part part in Session.GetSession().Parts)
            {
                string type = AttributeUtils.GetAttrForString(part, "PartType");
                if (type.Equals("Workpiece"))
                {
                    Body[] bodys = part.Bodies.ToArray();
                    NXOpen.Features.Feature feat = AssmbliesUtils.WaveAssociativeBodys(bodys);
                    Body[] waveBodys             = ((NXOpen.Features.BodyFeature)feat).GetBodies();
                    foreach (Body body in waveBodys)
                    {
                        body.Layer = 2;
                        theUFSession.Layer.SetStatus(2, 2);
                    }
                    break;
                }
            }
            PartUtils.SetPartWork(null);
        }
Пример #3
0
        public void AlterMove(ElectrodeModel model)
        {
            List <Body> bodys = new List <Body>();

            NXOpen.Features.Feature moveFeature    = null;
            NXOpen.Features.Feature patternFeature = null;
            NXOpen.Features.Feature linkedFeature  = null;
            foreach (NXOpen.Features.Feature ft in model.PartTag.Features.ToArray())
            {
                if (ft.FeatureType.Equals("MOVE_OBJECT", StringComparison.CurrentCultureIgnoreCase))
                {
                    moveFeature = ft;
                }
                if (ft.FeatureType.Equals("Pattern Geometry", StringComparison.CurrentCultureIgnoreCase))
                {
                    patternFeature = ft;
                }
                if (ft.FeatureType.Equals("LINKED_BODY", StringComparison.CurrentCultureIgnoreCase))
                {
                    linkedFeature = ft;
                }
            }
            bodys.AddRange(((NXOpen.Features.BodyFeature)linkedFeature).GetBodies());
            bodys.AddRange(((NXOpen.Features.PatternGeometry)patternFeature).GetAssociatedBodies());

            MoveObject.CreateMoveObjToXYZ("moveX", "moveY", "moveZ", moveFeature as NXOpen.Features.MoveObject, bodys.ToArray());
        }
Пример #4
0
        public static Point CreatePointFeature(Point3d point)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.Feature             nullNXOpen_Features_Feature = null;
            NXOpen.Features.PointFeatureBuilder pointFeatureBuilder1;
            pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullNXOpen_Features_Feature);
            Point pt = workPart.Points.CreatePoint(point);

            pointFeatureBuilder1.Point = pt;

            try
            {
                NXOpen.Features.Feature pf = pointFeatureBuilder1.CommitFeature();
                return(pf.GetEntities()[0] as Point);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("PointUtils:CreatePointFeature  创建点错误");
                throw ex;
            }
            finally
            {
                pointFeatureBuilder1.Destroy();
            }
        }
Пример #5
0
        /// <summary>
        /// 干涉面
        /// </summary>
        public void GetInterferenceOfFace()
        {
            List <Tag>  outFace       = new List <Tag>();
            Body        eleBody       = GetOccsInBods(this.eleModel.PartTag)[0];
            Body        workpieceBody = GetOccsInBods(this.workpiece)[0];
            List <Face> faces         = AnalysisUtils.SetInterferenceOutFace(eleBody, workpieceBody);

            for (int i = 0; i < (faces.Count) / 2 - 1; i++)
            {
                FaceData data1 = FaceUtils.AskFaceData(faces[i * 2]);
                FaceData data2 = FaceUtils.AskFaceData(faces[i * 2 + 1]);
                if (data1.Equals(data2))
                {
                    Tag face3;
                    NXOpen.Features.Feature feat1 = AssmbliesUtils.WaveFace(faces[i * 2]);
                    NXOpen.Features.Feature feat2 = AssmbliesUtils.WaveFace(faces[i * 2 + 1]);
                    Body[] bodys1 = (feat1 as NXOpen.Features.BodyFeature).GetBodies();
                    Body[] bodys2 = (feat2 as NXOpen.Features.BodyFeature).GetBodies();

                    Tag bodyTag1 = Intersect(bodys1[0], bodys2[0]);
                    if (bodyTag1 != Tag.Null)
                    {
                        outFace.Add(bodyTag1);
                    }
                }
            }
            SewSolidBody(outFace);
        }
Пример #6
0
    public DatumAxis DatumAxisCreation(Part workPart, Point3d first3d, Point3d second3d)
    {
        //Tworzenie "buildera dla osi Y".
        NXOpen.Features.Feature          nullFeatures_Feature = null;
        NXOpen.Features.DatumAxisBuilder datumAxisBuilder;
        datumAxisBuilder = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature);

        datumAxisBuilder.IsAssociative      = true;
        datumAxisBuilder.Type               = NXOpen.Features.DatumAxisBuilder.Types.TwoPoints;
        datumAxisBuilder.ResizedEndDistance = 0.0;

        Point first  = workPart.Points.CreatePoint(first3d);
        Point second = workPart.Points.CreatePoint(second3d);

        datumAxisBuilder.Point1 = first;
        datumAxisBuilder.Point2 = second;

        NXObject vector = datumAxisBuilder.Commit();

        string    journalName = vector.JournalIdentifier.ToString();
        DatumAxis datumAxis   = (DatumAxis)workPart.Datums.FindObject(journalName);

        datumAxisBuilder.Destroy();

        return(datumAxis);
    }
Пример #7
0
    public NXOpen.Features.DatumCsys CsysCreation(Part workPart, Point3d pointOrigin3d, Point3d pointAxis13d, Point3d pointAxis23d)
    {
        NXOpen.Features.Feature          nullFeatures_Feature = null;
        NXOpen.Features.DatumCsysBuilder datumCsysBuilder;
        datumCsysBuilder = workPart.Features.CreateDatumCsysBuilder(nullFeatures_Feature);

        Point pointOrigin = workPart.Points.CreatePoint(pointOrigin3d);
        Point pointAxis2  = workPart.Points.CreatePoint(pointAxis13d);
        Point pointAxis1  = workPart.Points.CreatePoint(pointAxis23d);

        Xform xform1;

        xform1 = workPart.Xforms.CreateXform(pointOrigin, pointAxis1, pointAxis2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

        CartesianCoordinateSystem cartesianCoordinateSystem;

        cartesianCoordinateSystem = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        datumCsysBuilder.Csys = cartesianCoordinateSystem;
        datumCsysBuilder.ComponentsCreation = true;
        datumCsysBuilder.FixedSizeDatum     = true;
        datumCsysBuilder.DisplayScaleFactor = 1.25;

        NXObject cSys = datumCsysBuilder.Commit();

        string journalName = cSys.JournalIdentifier.ToString();

        NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)workPart.Features.FindObject(journalName);

        datumCsysBuilder.Destroy();

        return(datumCsys);
    }
Пример #8
0
        public static NXOpen.Features.Sew SewFeature(Body body1, params Body[] body2s)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Features.Feature    nullNXOpen_Features_Feature = null;
            NXOpen.Features.SewBuilder sewBuilder1;
            sewBuilder1 = workPart.Features.CreateSewBuilder(nullNXOpen_Features_Feature);
            sewBuilder1.OutputMultipleSheets = true;
            bool added1;

            added1 = sewBuilder1.TargetBodies.Add(body1);
            bool added2;

            added2 = sewBuilder1.ToolBodies.Add(body2s);
            try
            {
                return(sewBuilder1.CommitFeature() as NXOpen.Features.Sew);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("SewUtils.SewFeature       " + ex.Message);
                return(null);
            }
            finally
            {
                sewBuilder1.Destroy();
            }
        }
Пример #9
0
 /// <summary>
 /// 创建part档
 /// </summary>
 /// <returns></returns>
 private NXOpen.Assemblies.Component CreateElePart()
 {
     NXOpen.Assemblies.Component eleComp = elePart.Create();
     if (eleComp != null)
     {
         PartUtils.SetPartWork(eleComp);
         NXOpen.Features.Feature feat = AssmbliesUtils.WaveBodys(this.head.ConditionModel.Bodys.ToArray());
         this.waveBodys = (feat as NXOpen.Features.BodyFeature).GetBodies();
     }
     return(eleComp);
 }
Пример #10
0
        /// <summary>
        /// 链接到工作部件中(非关联)
        /// </summary>
        /// <param name="seleObj">要链接的体</param>
        /// <returns></returns>
        public static NXOpen.Features.Feature WaveBodys(params NXObject[] seleObj)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.Feature            nullNXOpen_Features_Feature = null;
            NXOpen.Features.WaveLinkBuilder    waveLinkBuilder1            = workPart.BaseFeatures.CreateWaveLinkBuilder(nullNXOpen_Features_Feature);
            NXOpen.Features.ExtractFaceBuilder extractFaceBuilder1;
            extractFaceBuilder1                         = waveLinkBuilder1.ExtractFaceBuilder;
            extractFaceBuilder1.FaceOption              = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain;
            waveLinkBuilder1.Type                       = NXOpen.Features.WaveLinkBuilder.Types.BodyLink;
            extractFaceBuilder1.FaceOption              = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain;
            extractFaceBuilder1.AngleTolerance          = 45.0;
            extractFaceBuilder1.ParentPart              = NXOpen.Features.ExtractFaceBuilder.ParentPartType.OtherPart;
            extractFaceBuilder1.Associative             = false; //关联
            extractFaceBuilder1.MakePositionIndependent = false;
            extractFaceBuilder1.FixAtCurrentTimestamp   = false;

            extractFaceBuilder1.HideOriginal = false;

            extractFaceBuilder1.InheritDisplayProperties = false;

            NXOpen.ScCollector scCollector1;
            scCollector1 = extractFaceBuilder1.ExtractBodyCollector;

            extractFaceBuilder1.CopyThreads = false; //是否复制

            extractFaceBuilder1.FeatureOption = NXOpen.Features.ExtractFaceBuilder.FeatureOptionType.OneFeatureForAllBodies;
            Body[] seleBody = new Body[seleObj.Length];
            for (int i = 0; i < seleObj.Length; i++)
            {
                seleBody[i] = (Body)seleObj[i];
            }

            BodyDumbRule bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(seleBody, true);

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
            rules1[0] = bodyDumbRule1;
            scCollector1.ReplaceRules(rules1, false);
            try
            {
                return(waveLinkBuilder1.CommitFeature());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:WaveBodys:" + ex.Message);
                return(null);
            }
            finally
            {
                extractFaceBuilder1.Destroy();
            }
        }
Пример #11
0
        //public static NXOpen.GeometricUtilities.BoundingObjectBuilder CreateBoundingObjectBuilder(this NXOpen.Part obj)
        //{
        //    IntPtr ptr;
        //    JAM.StartCall("solid_modeling");
        //    int status = JA_PART_create_bounding_object_builder(obj.Tag, out ptr);
        //    if (status != 0)
        //    {
        //        throw NXException.Create(status);
        //    }
        //    return (NXOpen.GeometricUtilities.BoundingObjectBuilder)NXObjectManager.Get(JAM.Lookup(ptr));
        //}
        public static NXOpen.Section[] GetSections(this NXOpen.Features.Feature obj)
        {
            int num;

            JAM.StartCall("solid_modeling", "cam_base");
            IntPtr zero   = IntPtr.Zero;
            int    status = JA_FEATURE_get_sections(obj.Tag, out num, out zero);

            if (status != 0)
            {
                throw NXException.Create(status);
            }
            return((NXOpen.Section[])JAM.ToObjectArray(typeof(NXOpen.Section), num, zero));
        }
Пример #12
0
    public Body Revolve(Part workPart, Axis axisRotation, Sketch sketch, Line lineSketch, Point3d point3dSketch, double degStart, double degEnd)
    {
        //RevolveBulidier
        NXOpen.Features.Feature        nullFeature1    = null;
        NXOpen.Features.RevolveBuilder revolveBuilder1 = workPart.Features.CreateRevolveBuilder(nullFeature1);

        //Section
        Section section1 = workPart.Sections.CreateSection(0.02, 0.02, 0.02);

        revolveBuilder1.Section    = section1;
        revolveBuilder1.Axis       = axisRotation;
        revolveBuilder1.Tolerance  = 0.02;
        section1.DistanceTolerance = 0.02;
        section1.ChainingTolerance = 0.02;

        //Line assignment
        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)sketch.Feature;
        features1[0] = sketchFeature1;

        CurveFeatureRule curveFeatureRule1;

        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        NXObject nullNXObject = null;

        //Selection
        section1.AddToSection(rules1, lineSketch, nullNXObject, nullNXObject, point3dSketch, NXOpen.Section.Mode.Create, false);

        revolveBuilder1.Axis = axisRotation;

        //Sheet Body selection
        revolveBuilder1.FeatureOptions.BodyType = NXOpen.GeometricUtilities.FeatureOptions.BodyStyle.Sheet;
        revolveBuilder1.Section = section1;

        //Ustawienia
        revolveBuilder1.Limits.StartExtend.Value.RightHandSide = degStart.ToString();
        revolveBuilder1.Limits.EndExtend.Value.RightHandSide   = degEnd.ToString();
        revolveBuilder1.ParentFeatureInternal = false;

        NXObject feature_revolve1 = revolveBuilder1.CommitFeature();

        NXOpen.Features.BodyFeature bodyFeature1 = (NXOpen.Features.BodyFeature)feature_revolve1;
        Body[] body = bodyFeature1.GetBodies();
        return(body[0]);
    }
Пример #13
0
        /// <summary>
        /// 布尔操作
        /// </summary>
        /// <param name="targetBody">目标体</param>
        /// <param name="toolBody">工具体</param>
        /// <param name="copyTools">复制工具</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static NXOpen.Features.BooleanFeature CreateBooleanFeature(Body targetBody, Body toolBody, bool copyTools, NXOpen.Features.Feature.BooleanType type)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.BooleanFeature nullNXOpen_Features_BooleanFeature = null;
            NXOpen.Features.BooleanBuilder booleanBuilder1 = workPart.Features.CreateBooleanBuilderUsingCollector(nullNXOpen_Features_BooleanFeature);
            //ScCollector scCollector1 = booleanBuilder1.ToolBodyCollector;
            //  NXOpen.GeometricUtilities.BooleanRegionSelect booleanRegionSelect1 = booleanBuilder1.BooleanRegionSelect;
            booleanBuilder1.CopyTools = copyTools;
            booleanBuilder1.Operation = type;

            bool added1 = booleanBuilder1.Targets.Add(targetBody);

            //NXOpen.TaggedObject[] targets1 = new NXOpen.TaggedObject[1];
            //targets1[0] = targetBody;
            //booleanRegionSelect1.AssignTargets(targets1);

            NXOpen.ScCollector   scCollector = workPart.ScCollectors.CreateCollector();
            TaggedObject[]       obj         = { toolBody };
            SelectionRuleFactory fac         = new SelectionRuleFactory(obj.ToList());

            //Body[] bodies1 = { toolBody };
            //BodyDumbRule bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, true);
            //SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
            //rules1[0] = bodyDumbRule1;
            scCollector.ReplaceRules(fac.CreateSelectionRule().ToArray(), false);

            booleanBuilder1.ToolBodyCollector = scCollector;

            //NXOpen.TaggedObject[] targets2 = new NXOpen.TaggedObject[1];
            //targets2[0] = toolBody;
            //booleanRegionSelect1.AssignTargets(targets2);

            try
            {
                NXOpen.Features.Feature boolFeature = booleanBuilder1.CommitFeature();
                return(boolFeature as NXOpen.Features.BooleanFeature);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.BooleanUtils.CreateBooleanFeature:错误:" + ex.Message);
                return(null);
            }
            finally
            {
                booleanBuilder1.Destroy();
            }
        }
Пример #14
0
        /// <summary>
        /// 链接到工作部件中(关联)
        /// </summary>
        /// <param name="seleObj">要链接的face</param>
        /// <returns></returns>
        public static NXOpen.Features.Feature WaveFace(params Face[] seleObj)
        {
            Part workPart = theSession.Parts.Work;

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

            extractFaceBuilder1.MakePositionIndependent = false;

            extractFaceBuilder1.FixAtCurrentTimestamp = false;

            extractFaceBuilder1.HideOriginal = false;

            extractFaceBuilder1.DeleteHoles = false;

            extractFaceBuilder1.InheritDisplayProperties = false;

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

            bool added1;

            added1 = selectDisplayableObjectList1.Add(seleObj);
            try
            {
                return(waveLinkBuilder1.CommitFeature());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:WaveFace:" + ex.Message);
                return(null);
            }
            finally
            {
                waveLinkBuilder1.Destroy();
            }
        }
Пример #15
0
    public DatumPlane DatumPlaneCreation(Part workPart, Point3d point3d, DatumAxis axis)
    {
        NXOpen.Features.Feature nullFeatures_Feature = null;

        NXOpen.Features.DatumPlaneBuilder datumPlaneBuilder1;
        datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_Feature);

        Plane plane1;

        plane1 = datumPlaneBuilder1.GetPlane();

        plane1.SetMethod(NXOpen.PlaneTypes.MethodType.PointDir);

        Point point = workPart.Points.CreatePoint(point3d);

        NXObject[] geom1 = new NXObject[2];
        geom1[0] = point;
        geom1[1] = axis;
        plane1.SetGeometry(geom1);

        plane1.SetAlternate(NXOpen.PlaneTypes.AlternateType.One);

        plane1.Evaluate();

        bool flip1;

        flip1 = plane1.Flip;

        NXOpen.Features.Feature feature1;
        feature1 = datumPlaneBuilder1.CommitFeature();

        NXOpen.Features.DatumPlaneFeature datumPlaneFeature1 = (NXOpen.Features.DatumPlaneFeature)feature1;
        DatumPlane datumPlane1;

        datumPlane1 = datumPlaneFeature1.DatumPlane;

        datumPlane1.SetReverseSection(false);

        datumPlaneBuilder1.Destroy();

        return(datumPlane1);
    }
Пример #16
0
    public NXOpen.Features.DatumCsys CsysCreation(Part workPart, Point pointOrigin, DatumAxis Axis1, DatumAxis Axis2)
    {
        NXOpen.Features.Feature          nullFeatures_Feature = null;
        NXOpen.Features.DatumCsysBuilder datumCsysBuilder;
        datumCsysBuilder = workPart.Features.CreateDatumCsysBuilder(nullFeatures_Feature);

        Sense sense1 = new Sense();
        Sense sense2 = new Sense();

        Direction direction1;

        direction1 = workPart.Directions.CreateDirection(Axis1, sense1, SmartObject.UpdateOption.WithinModeling);

        Direction direction2;

        direction2 = workPart.Directions.CreateDirection(Axis2, sense2, SmartObject.UpdateOption.WithinModeling);

        Xform xform1;

        xform1 = workPart.Xforms.CreateXform(pointOrigin, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

        CartesianCoordinateSystem cartesianCoordinateSystem;

        cartesianCoordinateSystem = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        datumCsysBuilder.Csys = cartesianCoordinateSystem;
        datumCsysBuilder.ComponentsCreation = true;
        datumCsysBuilder.FixedSizeDatum     = true;
        datumCsysBuilder.DisplayScaleFactor = 1.25;

        NXObject cSys = datumCsysBuilder.Commit();

        string journalName = cSys.JournalIdentifier.ToString();

        NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)workPart.Features.FindObject(journalName);

        datumCsysBuilder.Destroy();

        return(datumCsys);
    }
Пример #17
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");
            }
        }
Пример #18
0
    public NXObject shank(Point point1, Point point2)
    {
        Part     workPart = theSession.Parts.Work;
        NXObject shanker;

        NXOpen.Features.Feature          nullFeatures_Feature = null;
        NXOpen.Features.DatumAxisBuilder abuilder;
        abuilder = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature);
        abuilder.ArcLength.Expression.RightHandSide = "0";
        abuilder.Type          = NXOpen.Features.DatumAxisBuilder.Types.TwoPoints;
        abuilder.IsAssociative = true;
        Xform nullXform = null;
        Point pt1       = workPart.Points.CreatePoint(point1, nullXform, NXOpen.SmartObject.UpdateOption.WithinModeling);
        Point pt2       = workPart.Points.CreatePoint(point2, nullXform, NXOpen.SmartObject.UpdateOption.WithinModeling);

        abuilder.Point1 = pt1;
        abuilder.Point2 = pt2;
        shanker         = abuilder.Commit();
        abuilder.Destroy();

        return(shanker);
    }
Пример #19
0
        /// <summary>
        /// 创建基准座
        /// </summary>
        private void CreateSeat(double zHeigth, bool zDatum)
        {
            List <Body> bodys = new List <Body>();

            bodys.AddRange(elePart.Model.PartTag.Bodies.ToArray());
            ElectrodeSketchBuilder builder = new ElectrodeSketchBuilder(eleInfo.Preparation[0], eleInfo.Preparation[1], -zHeigth);

            builder.CreateEleSketch();
            NXOpen.Features.Feature ext1 = ExtrudedUtils.CreateExtruded(new Vector3d(0, 0, -1), "0", "2", null, builder.LeiLine);
            NXOpen.Features.Feature ext2 = ExtrudedUtils.CreateExtruded(new Vector3d(0, 0, -1), "2", "20", null, builder.WaiLine);
            if (zDatum)
            {
                NXOpen.Features.Feature ext3 = ExtrudedUtils.CreateExtruded(new Vector3d(0, 0, 1), "0", zHeigth.ToString(), null, builder.Center);
                Body extBody3 = (ext3 as NXOpen.Features.BodyFeature).GetBodies()[0];
                MoveObject.CreateMoveObjToXYZ("moveBoxX", "moveBoxY", "moveBoxZ", null, extBody3);
                bodys.Add(extBody3);
            }
            Body extBody1 = (ext1 as NXOpen.Features.BodyFeature).GetBodies()[0];
            Body extBody2 = (ext2 as NXOpen.Features.BodyFeature).GetBodies()[0];

            CreateChamfer(extBody1.Tag);
            CreateUnite(bodys.ToArray(), extBody1.Tag, extBody2.Tag);
        }
Пример #20
0
        public static NXObject CreatePointFeature(Point point)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.Feature             nullNXOpen_Features_Feature = null;
            NXOpen.Features.PointFeatureBuilder pointFeatureBuilder1;
            pointFeatureBuilder1       = workPart.BaseFeatures.CreatePointFeatureBuilder(nullNXOpen_Features_Feature);
            pointFeatureBuilder1.Point = point;
            NXOpen.NXObject nXObject1;
            try
            {
                nXObject1 = pointFeatureBuilder1.Commit();
                return(nXObject1);
            }
            catch
            {
                LogMgr.WriteLog("CycPointUtils:CreatePointFeature  创建点错误");
            }
            finally
            {
                pointFeatureBuilder1.Destroy();
            }
            return(null);
        }
Пример #21
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");
    }
Пример #22
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Starting NX Journal");

        //Declare Part Variables
        //Convert Strings to doubles from the args
        double length    = System.Convert.ToDouble(args[0]);
        double width     = System.Convert.ToDouble(args[1]);
        double height    = System.Convert.ToDouble(args[2]);
        string part_name = args[3];

        //Measurements need to be converted from m to mm
        length = 1000 * length;
        width  = 1000 * width;
        height = 1000 * height;


        //Convert necessary values to string.
        string length_string = System.Convert.ToString(length);
        string width_string  = System.Convert.ToString(width);
        string height_string = System.Convert.ToString(height);


        Session theSession = Session.GetSession();

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

        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.ApplicationName = "ModelTemplate";

        fileNew1.Units = NXOpen.Part.Units.Millimeters;

        fileNew1.RelationType = "";

        fileNew1.UsesMasterModel = "No";

        fileNew1.TemplateType = FileNewTemplateType.Item;

        fileNew1.NewFileName = part_name;

        fileNew1.MasterFileName = "";

        fileNew1.UseBlankTemplate = false;

        fileNew1.MakeDisplayedPart = true;

        NXObject nXObject1;

        nXObject1 = fileNew1.Commit();

        Part workPart    = theSession.Parts.Work;
        Part displayPart = theSession.Parts.Display;

        theSession.DeleteUndoMark(markId3, null);

        fileNew1.Destroy();

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

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

        Sketch nullSketch = null;
        SketchInPlaceBuilder sketchInPlaceBuilder1;

        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullSketch);

        Unit       unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
        Expression expression1;

        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        Expression expression2;

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

        SketchAlongPathBuilder sketchAlongPathBuilder1;

        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullSketch);

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

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

        DatumPlane datumPlane1 = (DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) XY plane");
        Point3d    point1      = new Point3d(26.3626531592029, 1.06581410364015e-014, 30.438226401797);

        sketchInPlaceBuilder1.PlaneOrFace.SetValue(datumPlane1, workPart.ModelingViews.WorkView, point1);

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

        sketchInPlaceBuilder1.SketchOrigin = point2;

        sketchInPlaceBuilder1.PlaneOrFace.Value = null;

        sketchInPlaceBuilder1.PlaneOrFace.Value = datumPlane1;

        sketchInPlaceBuilder1.ReversePlaneNormal = true;

        DatumAxis datumAxis1 = (DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis");

        sketchInPlaceBuilder1.Axis.Value = datumAxis1;

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

        theSession.DeleteUndoMark(markId6, null);

        NXOpen.Session.UndoMarkId markId7;
        markId7 = 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;

        NXObject nXObject2;

        nXObject2 = sketchInPlaceBuilder1.Commit();

        Sketch sketch1 = (Sketch)nXObject2;

        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

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

        int nErrs1;

        nErrs1 = theSession.UpdateManager.DoUpdate(markId8);

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

        theSession.DeleteUndoMark(markId7, null);

        theSession.SetUndoMarkName(markId5, "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->Rectangle...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId9;
        markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Profile short list");

        NXOpen.Session.UndoMarkId markId10;
        markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Rectangle");

        Expression expression3;

        expression3 = workPart.Expressions.CreateSystemExpression(width_string);

        theSession.SetUndoMarkVisibility(markId10, "Create Rectangle", NXOpen.Session.MarkVisibility.Visible);

        // ----------------------------------------------
        // Creating rectangle using By 2 Points method
        // ----------------------------------------------
        Point3d startPoint1 = new Point3d(0.0, 0.0, 0.0);
        Point3d endPoint1   = new Point3d(width, 0.0, 0.0);
        Line    line1;

        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

        Point3d startPoint2 = new Point3d(width, 0.0, 0.0);
        Point3d endPoint2   = new Point3d(width, 0.0, height);
        Line    line2;

        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

        Point3d startPoint3 = new Point3d(width, 0.0, height);
        Point3d endPoint3   = new Point3d(0.0, 0.0, height);
        Line    line3;

        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

        Point3d startPoint4 = new Point3d(0.0, 0.0, height);
        Point3d endPoint4   = new Point3d(0.0, 0.0, 0.0);
        Line    line4;

        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

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

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

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

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

        NXOpen.Sketch.ConstraintGeometry geom1_1;
        geom1_1.Geometry  = line1;
        geom1_1.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_1;
        geom2_1.Geometry  = line2;
        geom2_1.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint1;

        sketchGeometricConstraint1 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1);

        NXOpen.Sketch.ConstraintGeometry geom1_2;
        geom1_2.Geometry  = line2;
        geom1_2.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_2;
        geom2_2.Geometry  = line3;
        geom2_2.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_2.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint2;

        sketchGeometricConstraint2 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2);

        NXOpen.Sketch.ConstraintGeometry geom1_3;
        geom1_3.Geometry  = line3;
        geom1_3.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_3;
        geom2_3.Geometry  = line4;
        geom2_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_3.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint3;

        sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_3, geom2_3);

        NXOpen.Sketch.ConstraintGeometry geom1_4;
        geom1_4.Geometry  = line4;
        geom1_4.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_4;
        geom2_4.Geometry  = line1;
        geom2_4.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_4.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint4;

        sketchGeometricConstraint4 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_4, geom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1;
        geom1.Geometry  = line1;
        geom1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint5;

        sketchGeometricConstraint5 = theSession.ActiveSketch.CreateHorizontalConstraint(geom1);

        NXOpen.Sketch.ConstraintGeometry conGeom1_1;
        conGeom1_1.Geometry  = line1;
        conGeom1_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_1;
        conGeom2_1.Geometry  = line2;
        conGeom2_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint6;

        sketchGeometricConstraint6 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_1, conGeom2_1);

        NXOpen.Sketch.ConstraintGeometry conGeom1_2;
        conGeom1_2.Geometry  = line2;
        conGeom1_2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_2;
        conGeom2_2.Geometry  = line3;
        conGeom2_2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_2.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint7;

        sketchGeometricConstraint7 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_2, conGeom2_2);

        NXOpen.Sketch.ConstraintGeometry conGeom1_3;
        conGeom1_3.Geometry  = line3;
        conGeom1_3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_3;
        conGeom2_3.Geometry  = line4;
        conGeom2_3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_3.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint8;

        sketchGeometricConstraint8 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_3, conGeom2_3);

        NXOpen.Sketch.ConstraintGeometry conGeom1_4;
        conGeom1_4.Geometry  = line4;
        conGeom1_4.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_4;
        conGeom2_4.Geometry  = line1;
        conGeom2_4.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_4.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint9;

        sketchGeometricConstraint9 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_4, conGeom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1_5;
        geom1_5.Geometry  = line1;
        geom1_5.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_5.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_5;
        geom2_5.Geometry  = point2;
        geom2_5.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2_5.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint10;

        sketchGeometricConstraint10 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_5, geom2_5);

        NXOpen.Sketch.DimensionGeometry dimObject1_1;
        dimObject1_1.Geometry    = line3;
        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;
        NXObject nullNXObject = null;

        dimObject1_1.View = nullNXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_1;
        dimObject2_1.Geometry    = line3;
        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        = nullNXObject;
        Point3d dimOrigin1 = new Point3d(25.0, 0.0, 149.651881900218);
        SketchDimensionalConstraint sketchDimensionalConstraint1;

        sketchDimensionalConstraint1 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_1, dimObject2_1, dimOrigin1, expression3, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint1 = (SketchHelpedDimensionalConstraint)sketchDimensionalConstraint1;

        NXOpen.Annotations.Dimension dimension1;
        dimension1 = sketchHelpedDimensionalConstraint1.AssociatedDimension;

        NXOpen.Sketch.DimensionGeometry dimObject1_2;
        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        = nullNXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_2;
        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        = nullNXObject;
        Point3d    dimOrigin2     = new Point3d(74.651881900218, 0.0, 62.5);
        Expression nullExpression = null;
        SketchDimensionalConstraint sketchDimensionalConstraint2;

        sketchDimensionalConstraint2 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_2, dimObject2_2, dimOrigin2, nullExpression, NXOpen.Sketch.DimensionOption.CreateAsAutomatic);

        SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint2 = (SketchHelpedDimensionalConstraint)sketchDimensionalConstraint2;

        NXOpen.Annotations.Dimension dimension2;
        dimension2 = sketchHelpedDimensionalConstraint2.AssociatedDimension;

        Expression expression4;

        expression4 = sketchHelpedDimensionalConstraint2.AssociatedExpression;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        SmartObject[] geoms1 = new SmartObject[4];
        geoms1[0] = line1;
        geoms1[1] = line2;
        geoms1[2] = line3;
        geoms1[3] = line4;
        theSession.ActiveSketch.UpdateConstraintDisplay(geoms1);

        SmartObject[] geoms2 = new SmartObject[4];
        geoms2[0] = line1;
        geoms2[1] = line2;
        geoms2[2] = line3;
        geoms2[3] = line4;
        theSession.ActiveSketch.UpdateDimensionDisplay(geoms2);

        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

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

        NXOpen.Features.Feature nullFeatures_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(nullFeatures_Feature);

        Section section1;

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

        extrudeBuilder1.Section = section1;

        extrudeBuilder1.AllowSelfIntersectingSection(true);

        Unit unit2;

        unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units;

        Expression expression5;

        expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2);

        extrudeBuilder1.DistanceTolerance = 0.01;

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

        Body[] targetBodies1 = new Body[1];
        Body   nullBody      = null;

        targetBodies1[0] = nullBody;
        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 = length_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(markId11, "Extrude Dialog");

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

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

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

        NXOpen.Session.UndoMarkId markId13;
        markId13 = 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;
        CurveFeatureRule curveFeatureRule1;

        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        Point3d helpPoint1 = new Point3d(23.553389477581, 0.0, height);

        section1.AddToSection(rules1, line3, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

        theSession.DeleteUndoMark(markId13, null);

        Direction direction1;

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

        extrudeBuilder1.Direction = direction1;

        theSession.DeleteUndoMark(markId12, null);

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

        theSession.DeleteUndoMark(markId14, null);

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

        extrudeBuilder1.ParentFeatureInternal = false;

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

        theSession.DeleteUndoMark(markId15, null);

        theSession.SetUndoMarkName(markId11, "Extrude");

        Expression expression6 = extrudeBuilder1.Limits.StartExtend.Value;
        Expression expression7 = extrudeBuilder1.Limits.EndExtend.Value;

        extrudeBuilder1.Destroy();

        workPart.Expressions.Delete(expression5);

        // ----------------------------------------------
        //   Menu: Analysis->Measure Bodies...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId16;
        markId16 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        MeasureBodyBuilder measureBodyBuilder1;

        measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXObject);

        theSession.SetUndoMarkName(markId16, "Measure Bodies Dialog");

        Body[] bodies1 = new Body[1];
        Body   body1   = (Body)workPart.Bodies.FindObject("EXTRUDE(2)");

        bodies1[0] = body1;
        BodyDumbRule bodyDumbRule1;

        bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, true);

        SelectionIntentRule[] rules2 = new SelectionIntentRule[1];
        rules2[0] = bodyDumbRule1;
        measureBodyBuilder1.BodyCollector.ReplaceRules(rules2, false);

        NXOpen.Session.UndoMarkId markId17;
        markId17 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Bodies");

        theSession.DeleteUndoMark(markId17, null);

        NXOpen.Session.UndoMarkId markId18;
        markId18 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Bodies");

        theSession.DeleteUndoMark(markId18, null);

        theSession.SetUndoMarkName(markId16, "Measure Bodies");

        measureBodyBuilder1.Destroy();


        MeasureBodies measureBodies1 = workPart.MeasureManager.NewMassProperties(workPart.UnitCollection.ToArray(), 1.0, bodies1);
        //Console.WriteLine(measureBodies1.Volume);

        // ----------------------------------------------
        //   Menu: File->Save
        // ----------------------------------------------
        PartSaveStatus partSaveStatus1;

        partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

        partSaveStatus1.Dispose();
        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------


        Console.WriteLine("Finishing NX Journal. Part Saved.");

        //Write output file with dimensions of beam in current directory
        File.WriteAllText("Optimum_beam_dimensions.txt",
                          "Volume of Optimal Beam = " + ((measureBodies1.Volume) / 1000000000) + "m^3\r\nLength = 2m" +
                          "\r\nWidth = " + (width / 1000) + "m\r\nHeight = " + (height / 1000) + "m");
        Console.WriteLine("Beam dimensions written to file.");
    }
Пример #23
0
    public static void Main(string[] args)
    {
        NXOpen.Session theSession = NXOpen.Session.GetSession();
        // ----------------------------------------------
        //   Menu: File->New...
        // ----------------------------------------------

        //Variable Declaration
        double a = double.Parse(args[0]);
        double G = 1.618;
        double b = G * a;
        double L = 10;
        double t = double.Parse(args[1]);


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

        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 = "J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.prt";

        fileNew1.MasterFileName = "";

        fileNew1.MakeDisplayedPart = true;

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

        NXOpen.Part workPart    = theSession.Parts.Work;
        NXOpen.Part displayPart = theSession.Parts.Display;

        fileNew1.Destroy();

        theSession.ApplicationSwitchImmediate("UG_APP_MODELING");

        // ----------------------------------------------
        //   Menu: Insert->Sketch...
        // ----------------------------------------------

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

        NXOpen.DatumPlane datumPlane1 = (NXOpen.DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) YZ plane");
        NXOpen.Point3d    point1      = new NXOpen.Point3d(0, 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;

        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;

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

        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.Point3d startPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Point3d endPoint1   = new NXOpen.Point3d(0, b, 0.0);
        NXOpen.Line    line1;
        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

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

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        //

        NXOpen.Point3d startPoint2 = new NXOpen.Point3d(0.0, b, 0.0);
        NXOpen.Point3d endPoint2   = new NXOpen.Point3d(L, a, 0.0);
        NXOpen.Line    line2;
        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

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

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------

        NXOpen.Point3d startPoint3 = new NXOpen.Point3d(L, a, 0.0);
        NXOpen.Point3d endPoint3   = new NXOpen.Point3d(L, 0.0, 0.0);
        NXOpen.Line    line3;
        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

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

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Point3d startPoint4 = new NXOpen.Point3d(L, 0.0, 0.0);
        NXOpen.Point3d endPoint4   = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Line    line4;
        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

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

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

        // ----------------------------------------------
        //   Menu: Insert->Design Feature->Extrude...
        // ----------------------------------------------

        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 expression7;
        expression7 = 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 = t.ToString();

        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;

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

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

        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(0.0, 0.0, 0.0);
        section1.AddToSection(rules1, null, null, null, helpPoint1, NXOpen.Section.Mode.Create, false);

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

        extrudeBuilder1.Direction = direction1;

        extrudeBuilder1.ParentFeatureInternal = false;

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

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

        workPart.Expressions.Delete(expression7);

        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------
        // ----------------------------------------------
        //   Menu: File->Export->IGES...
        // ----------------------------------------------

        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.SettingsFile = "C:\\Program Files\\Siemens\\NX 10.0\\iges\\igesexport.def";

        igesCreator1.MaxLineThickness = 2.0;

        igesCreator1.SysDefmaxThreeDMdlSpace = true;

        igesCreator1.SysDefidenticalPointResolution = true;

        igesCreator1.InputFile = "J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.igs";

        igesCreator1.OutputFile = "J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.igs";

        igesCreator1.FileSaveFlag = false;

        igesCreator1.LayerMask = "1-256";

        igesCreator1.DrawingList = "";

        NXOpen.TaggedObject[] objects1 = new NXOpen.TaggedObject[0];
        igesCreator1.SetDrawingArray(objects1);

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

        igesCreator1.Destroy();

        while (!System.IO.File.Exists("J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.igs"))
        {
            System.Threading.Thread.Sleep(10);
        }
    }
Пример #24
0
    //------------------------------------------------------------------------------
    //Callback Name: apply_cb
    //------------------------------------------------------------------------------
    public int apply_cb()
    {
        int errorCode = 0;

        NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1 = null;

        try
        {
            Part workPart = theSession.Parts.Work;

            //Get the values from UI Blocks
            PropertyList blockHeightProps = blockHeight.GetProperties();
            double       theHeight        = blockHeightProps.GetDouble("Value");
            blockHeightProps.Dispose();
            blockHeightProps = null;

            PropertyList blockWidthProps = blockWidth.GetProperties();
            double       theWidth        = blockWidthProps.GetDouble("Value");
            blockWidthProps.Dispose();
            blockWidthProps = null;

            PropertyList blockLengthProps = blockLength.GetProperties();
            double       theLength        = blockLengthProps.GetDouble("Value");
            blockLengthProps.Dispose();
            blockLengthProps = null;

            PropertyList blockOriginProps = blockOrigin.GetProperties();
            Point3d      originPoint      = blockOriginProps.GetPoint("Point");
            blockOriginProps.Dispose();
            blockOriginProps = null;

            PropertyList blockColorProps = blockColor.GetProperties();
            int[]        color           = blockColorProps.GetIntegerVector("Value");
            blockColorProps.Dispose();
            blockColorProps = null;

            //Create the NX block
            NXOpen.Features.Feature nullFeatures_Feature = null;
            blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);

            blockFeatureBuilder1.SetOriginAndLengths(originPoint, theLength.ToString(), theHeight.ToString(), theWidth.ToString());

            NXOpen.Features.Feature feature1;
            feature1 = blockFeatureBuilder1.CommitFeature();


            // Get the body from Feature
            NXOpen.Features.BodyFeature bodyFeat = (NXOpen.Features.BodyFeature)feature1;
            Body[] bodies = new Body[1];
            bodies = bodyFeat.GetBodies();
            // Apply the color to feature body
            DisplayModification displayModification1 = theSession.DisplayManager.NewDisplayModification();
            displayModification1.ApplyToAllFaces = true;
            displayModification1.NewColor        = color[0];
            DisplayableObject[] objects1 = new DisplayableObject[1];
            objects1[0] = bodies[0];
            displayModification1.Apply(objects1);
            displayModification1.Dispose();
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            errorCode = 1;
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.Message);
        }
        finally
        {
            if (blockFeatureBuilder1 != null)
            {
                blockFeatureBuilder1.Destroy();
                blockFeatureBuilder1 = null;
            }
        }
        return(errorCode);
    }