示例#1
0
文件: Helper.cs 项目: 15831944/TEST_1
        public static Snap.Position?GetElecMidPosition(Snap.NX.Part workPart, Snap.NX.Body body)
        {
            Snap.Position?result = null;
            var           point  = GetElecMidPointInPart(workPart, body);

            if (point == null)
            {
                var name = GetStringAttribute(body, SnapEx.EactConstString.EACT_ELECT_GROUP);
                if (!string.IsNullOrEmpty(name))
                {
                    if (body.NXOpenBody.OwningComponent != null && body.OwningComponent.Prototype != null)
                    {
                        var           part     = body.OwningComponent.Prototype;
                        Snap.NX.Point oldPoint = GetElecMidPointInPart(part, body);
                        if (oldPoint != null)
                        {
                            var           oldPosition = new Snap.Position(oldPoint.X, oldPoint.Y, oldPoint.Z);
                            var           vCom        = Snap.Vector.Unit(body.OwningComponent.Orientation.AxisZ);
                            var           v2          = new Snap.Vector(oldPosition);
                            Snap.Position newPosition = body.OwningComponent.Position - (vCom + v2);
                            result = newPosition;
                        }
                    }
                }
            }
            else
            {
                result = point.Position;
            }

            return(result);
        }
示例#2
0
        public virtual void Trim(double lowerParam, double upperParam)
        {
            Snap.NX.Part     workPart  = Globals.WorkPart;
            TrimCurve        trimCurve = null;
            TrimCurveBuilder builder   = workPart.NXOpenPart.Features.CreateTrimCurveBuilder(trimCurve);

            builder.InteresectionMethod          = TrimCurveBuilder.InteresectionMethods.UserDefined;
            builder.InteresectionDirectionOption = TrimCurveBuilder.InteresectionDirectionOptions.RelativeToWcs;
            builder.CurvesToTrim.AllowSelfIntersection(true);
            builder.CurvesToTrim.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);
            builder.CurveOptions.Associative      = false;
            builder.CurveOptions.InputCurveOption = CurveOptions.InputCurve.Replace;
            builder.CurveExtensionType            = TrimCurveBuilder.CurveExtensionTypes.Natural;
            Snap.NX.Point   point    = Create.Point(this.Position(lowerParam));
            Snap.NX.Point   point2   = Create.Point(this.Position(upperParam));
            Snap.NX.Section section  = Snap.NX.Section.CreateSection(new Snap.NX.Point[] { point });
            Snap.NX.Section section2 = Snap.NX.Section.CreateSection(new Snap.NX.Point[] { point2 });
            builder.CurveList.Add(base.NXOpenTaggedObject, null, (Point3d)this.StartPoint);
            SelectionIntentRule[] rules = Snap.NX.Section.CreateSelectionIntentRule(new Snap.NX.ICurve[] { this });
            builder.CurvesToTrim.AddToSection(rules, (NXOpen.NXObject) this, null, null, (Point3d)this.StartPoint, NXOpen.Section.Mode.Create, false);
            builder.FirstBoundingObject.Add(section.NXOpenSection);
            builder.SecondBoundingObject.Add(section2.NXOpenSection);
            builder.Commit();
            builder.Destroy();
            section.NXOpenSection.Destroy();
            section2.NXOpenSection.Destroy();
            Snap.NX.NXObject.Delete(new Snap.NX.NXObject[] { point });
            Snap.NX.NXObject.Delete(new Snap.NX.NXObject[] { point2 });
        }
示例#3
0
        public virtual Snap.NX.Curve[] Divide(params double[] parameters)
        {
            Snap.NX.Curve      curve    = this.Copy();
            Snap.NX.Part       workPart = Globals.WorkPart;
            DivideCurveBuilder builder  = workPart.NXOpenPart.BaseFeatures.CreateDivideCurveBuilder(null);

            builder.Type = DivideCurveBuilder.Types.ByBoundingObjects;
            BoundingObjectBuilder[] builderArray = new BoundingObjectBuilder[parameters.Length];
            Snap.NX.Point[]         nxObjects    = new Snap.NX.Point[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                builderArray[i] = workPart.NXOpenPart.CreateBoundingObjectBuilder();
                builderArray[i].BoundingPlane        = null;
                builderArray[i].BoundingObjectMethod = BoundingObjectBuilder.Method.ProjectPoint;
                nxObjects[i] = Create.Point(curve.Position(parameters[i]));
                builderArray[i].BoundingProjectPoint = (NXOpen.Point)nxObjects[i];
                builder.BoundingObjects.Append(builderArray[i]);
            }
            View workView = workPart.NXOpenPart.ModelingViews.WorkView;

            builder.DividingCurve.SetValue((NXOpen.Curve)curve, workView, (Point3d)curve.StartPoint);
            builder.Commit();
            NXOpen.NXObject[] committedObjects = builder.GetCommittedObjects();
            builder.Destroy();
            Snap.NX.Curve[] curveArray = new Snap.NX.Curve[committedObjects.Length];
            for (int j = 0; j < curveArray.Length; j++)
            {
                curveArray[j] = CreateCurve((NXOpen.Curve)committedObjects[j]);
            }
            Snap.NX.NXObject.Delete(nxObjects);
            return(curveArray);
        }
示例#4
0
        internal static Snap.Position[] PointSet(Snap.NX.ICurve icurve, int pointCount)
        {
            Globals.UndoMarkId markId  = Globals.SetUndoMark(Globals.MarkVisibility.Invisible, "Snap_PositionArray_EqualParameter999");
            PointSetBuilder    builder = Globals.WorkPart.NXOpenPart.Features.CreatePointSetBuilder(null);

            builder.Type          = PointSetBuilder.Types.CurvePoints;
            builder.CurvePointsBy = PointSetBuilder.CurvePointsType.EqualArcLength;
            builder.Associative   = false;
            builder.NumberOfPointsExpression.RightHandSide = pointCount.ToString();
            builder.StartPercentage.RightHandSide          = "0";
            builder.EndPercentage.RightHandSide            = "100";
            SelectionIntentRule[] rules = Snap.NX.Section.CreateSelectionIntentRule(new Snap.NX.ICurve[] { icurve });
            NXOpen.NXObject       nXOpenTaggedObject = (NXOpen.NXObject)icurve.NXOpenTaggedObject;
            builder.SingleCurveOrEdgeCollector.AddToSection(rules, nXOpenTaggedObject, null, null, (Point3d)icurve.StartPoint, NXOpen.Section.Mode.Create, false);
            builder.Commit();
            NXOpen.NXObject[] committedObjects = builder.GetCommittedObjects();
            builder.Destroy();
            Snap.Position[] positionArray = new Snap.Position[committedObjects.Length];
            for (int i = 0; i < positionArray.Length; i++)
            {
                TaggedObject  obj3  = committedObjects[i];
                Snap.NX.Point point = (NXOpen.Point)obj3;
                positionArray[i] = point.Position;
            }
            Globals.UndoToMark(markId, "Snap_PositionArray_EqualParameter999");
            Globals.DeleteUndoMark(markId, "Snap_PositionArray_EqualParameter999");
            return(positionArray);
        }
示例#5
0
 public static Snap.NX.Point[] Copy(Transform xform, params Snap.NX.Point[] original)
 {
     Snap.NX.Point[] pointArray = new Snap.NX.Point[original.Length];
     for (int i = 0; i < original.Length; i++)
     {
         pointArray[i] = original[i].Copy(xform);
     }
     return(pointArray);
 }
示例#6
0
 internal static Snap.NX.Sphere CreateSphere(Snap.NX.Point center, Snap.Number diameter)
 {
     NXOpen.Features.SphereBuilder featureBuilder = Globals.WorkPart.NXOpenPart.Features.CreateSphereBuilder(null);
     featureBuilder.Diameter.RightHandSide = diameter.ToString();
     featureBuilder.CenterPoint            = center.NXOpenPoint;
     featureBuilder.BooleanOption.Type     = BooleanOperation.BooleanType.Create;
     NXOpen.Features.Sphere sphere = (NXOpen.Features.Sphere)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.Sphere(sphere));
 }
示例#7
0
        internal static Snap.NX.NXObject CreateNXObject(TaggedObject nxopenTaggedObject)
        {
            Snap.NX.NXObject obj2         = null;
            NXOpen.NXObject  nxopenObject = nxopenTaggedObject as NXOpen.NXObject;
            if (nxopenObject != null)
            {
                obj2 = new Snap.NX.NXObject(nxopenObject);
                NXOpen.Curve nxopenCurve = nxopenObject as NXOpen.Curve;
                if (nxopenCurve != null)
                {
                    obj2 = Snap.NX.Curve.CreateCurve(nxopenCurve);
                }
                switch (GetTypeFromTag(nxopenObject.Tag))
                {
                case ObjectTypes.Type.Point:
                    obj2 = new Snap.NX.Point((NXOpen.Point)nxopenObject);
                    break;

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

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

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

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

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

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

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

                case ObjectTypes.Type.Component:
                    return(new Snap.NX.Component((NXOpen.Assemblies.Component)nxopenObject));
                }
            }
            return(obj2);
        }
示例#8
0
 internal static Snap.NX.OffsetCurve CreateOffsetLine(Snap.NX.ICurve icurve, Snap.NX.Point point, string distance, bool reverseDirection)
 {
     NXOpen.Features.OffsetCurveBuilder featureBuilder = Globals.WorkPart.NXOpenPart.Features.CreateOffsetCurveBuilder(null);
     featureBuilder.Type = NXOpen.Features.OffsetCurveBuilder.Types.Distance;
     featureBuilder.InputCurvesOptions.InputCurveOption = CurveOptions.InputCurve.Retain;
     featureBuilder.Tolerance = Globals.DistanceTolerance;
     featureBuilder.OffsetDistance.RightHandSide = distance;
     featureBuilder.ReverseDirection             = reverseDirection;
     featureBuilder.PointOnOffsetPlane           = (NXOpen.Point)point;
     ((Snap.NX.Section)featureBuilder.CurvesToOffset).AddICurve(new Snap.NX.ICurve[] { icurve });
     NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.CurvesToOffset.CleanMappingData();
     featureBuilder.Destroy();
     return(feature as NXOpen.Features.OffsetCurve);
 }
示例#9
0
文件: Helper.cs 项目: 15831944/TEST_1
        public static Snap.NX.Point GetElecMidPoint(Snap.NX.Part workPart, Snap.NX.Body body)
        {
            var point = GetElecMidPointInPart(workPart, body);

            if (point == null)
            {
                var name = GetStringAttribute(body, SnapEx.EactConstString.EACT_ELECT_GROUP);
                if (!string.IsNullOrEmpty(name))
                {
                    if (body.NXOpenBody.OwningComponent != null && body.OwningComponent.Prototype != null)
                    {
                        var           part     = body.OwningComponent.Prototype;
                        Snap.NX.Point oldPoint = GetElecMidPointInPart(part, body);
                        if (oldPoint != null)
                        {
                            SnapEx.Create.ExtractObject(new List <NXOpen.NXObject> {
                                oldPoint
                            }, workPart.FullPath, false, false);
                            oldPoint = GetElecMidPointInPart(workPart, body);
                            if (oldPoint != null)
                            {
                                var           oldPosition = new Snap.Position(oldPoint.X, oldPoint.Y, oldPoint.Z);
                                var           vCom        = Snap.Vector.Unit(body.OwningComponent.Orientation.AxisZ);
                                var           v2          = new Snap.Vector(oldPosition);
                                Snap.Position newPosition = body.OwningComponent.Position - (vCom + v2);
                                oldPoint.X = newPosition.X;
                                oldPoint.Y = newPosition.Y;
                                oldPoint.Z = newPosition.Z;
                                point      = oldPoint;
                            }
                        }
                    }
                }
            }
            else
            {
                point = point.Copy();
            }

            return(point);
        }
示例#10
0
        public static void SetEactElectrode(Snap.NX.Body body, ref Snap.NX.Face topFace, ref Snap.NX.Face baseFace, ref Snap.NX.Point basePoint)
        {
            var faces = body.Faces.ToList();

            //清空相关属性
            if (body.IsHasAttr(EactElectrode.EACT_ELECT_GROUP))
            {
                body.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.EACT_ELECT_GROUP);
            }
            faces.ToList().ForEach(u => {
                if (u.IsHasAttr(EactElectrode.EACT_ELECT_GROUP))
                {
                    u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.EACT_ELECT_GROUP);
                }

                if (u.IsHasAttr(EactElectrode.BASE_BOT))
                {
                    u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.BASE_BOT);
                }

                if (u.IsHasAttr(EactElectrode.BASE_TOP))
                {
                    u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.BASE_TOP);
                }
            });

            if (topFace != null && baseFace != null && basePoint != null)//手动
            {
            }
            else//自动
            {
                Snap.Position basePos = new Snap.Position();
                GetEactElectrode(body, ref topFace, ref baseFace, ref basePoint, ref basePos);
                if (basePoint == null && baseFace != null)
                {
                    basePoint       = Snap.Create.Point(baseFace.GetCenterPoint());
                    basePoint.Layer = body.Layer;
                    basePoint.Color = System.Drawing.Color.Green;
                }
            }

            //赋属性
            if (topFace != null)
            {
                topFace.SetStringAttribute(EactElectrode.BASE_BOT, "1");
            }
            if (baseFace != null)
            {
                baseFace.SetStringAttribute(EactElectrode.BASE_TOP, "1");
            }
            if (basePoint != null)
            {
                var guid = Guid.NewGuid().ToString();
                body.SetStringAttribute(EactElectrode.EACT_ELECT_GROUP, guid);
                basePoint.SetStringAttribute(EactElectrode.EACT_ELECT_GROUP, guid);
            }

            if (topFace != null && baseFace != null && basePoint != null)
            {
                body.SetStringAttribute(ElectrodeInfo.EACT_SPECIALSHAPED, "1");
            }
        }
示例#11
0
        public static void GetEactElectrode(Snap.NX.Body body, ref Snap.NX.Face topFace, ref Snap.NX.Face baseFace, ref Snap.NX.Point basePoint, ref Snap.Position pos)
        {
            var faces  = body.Faces.ToList();
            var topDir = new Snap.Vector(0, 0, 1);

            //顶面
            topFace = faces.Where(u => u.IsHasAttr(EactElectrode.BASE_BOT) || u.MatchAttrValue(XKElectrode.ATTR_NAME_MARK, XKElectrode.BASE_BOT)).FirstOrDefault();
            if (topFace == null)
            {
                var topFaces = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).Where(u => SnapEx.Helper.Equals(topDir, u.GetFaceDirection()));
                topFace = topFaces.FirstOrDefault();
                if (topFaces.Count() > 1)
                {
                    topFace = topFaces.OrderByDescending(u => {
                        var uv = u.BoxUV;
                        return(Math.Abs(uv.MinU - uv.MaxU) * Math.Abs(uv.MaxV - uv.MinV));
                    }).FirstOrDefault();
                }
            }
            //基准面
            baseFace = faces.Where(u => u.IsHasAttr(EactElectrode.BASE_TOP) || u.MatchAttrValue(XKElectrode.ATTR_NAME_MARK, XKElectrode.BASE_TOP)).FirstOrDefault();
            if (baseFace == null)
            {
                var baseFaces = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).Where(u => SnapEx.Helper.Equals(-topDir, u.GetFaceDirection()));
                if (baseFaces.Count() == 0)
                {
                    baseFace = topFace;
                }
                else
                {
                    baseFace = baseFaces.OrderByDescending(u => {
                        var uv = u.BoxUV;
                        return(Math.Abs(uv.MinU - uv.MaxU) * Math.Abs(uv.MaxV - uv.MinV));
                    }).FirstOrDefault();
                }
            }

            if (topFace == null)
            {
                topFace = baseFace;
            }

            //基准点
            var basePoints = Snap.Globals.WorkPart.Points.Where(u => u.Layer == body.Layer).ToList().OrderBy(u => Snap.Compute.Distance(u.Position, body)).ToList();

            basePoint = basePoints.FirstOrDefault();
            var tempBasePoint = basePoints.FirstOrDefault(u => u.MatchAttrValue(XKElectrode.ATTR_NAME_MARK, body.Name) && u.MatchAttrValue(XKElectrode.DIM_PT, XKElectrode.DIM_PT));

            if (tempBasePoint != null)
            {
                basePoint = tempBasePoint;
            }

            if (basePoint == null && baseFace != null)
            {
                pos = baseFace.GetCenterPoint();
            }
            else if (basePoint != null)
            {
                pos = basePoint.Position;
            }
        }