Ejemplo n.º 1
0
    void Perform(bool isPreview = false)
    {
        tempObjs.ForEach(u => {
            Snap.NX.NXObject snapU = u;
            snapU.Delete();
        });
        tempObjs.Clear();
        var bodies = bodySelect0.GetSelectedObjects().ToList();
        var plane  = plane0.GetSelectedObjects().FirstOrDefault() as NXOpen.Plane;

        if (bodies.Count > 0 && plane != null)
        {
            int order = GetMaxOrder();
            if (bodies.Count == 1)
            {
                int tempInt;
                if (int.TryParse(stringElecName.Value.Split('-').LastOrDefault(), out tempInt))
                {
                    order = tempInt - 1;
                }
            }
            bodies.ForEach(u =>
            {
                order++;
                tempObjs.Add(GeomcopyElec(isPreview, u as NXOpen.Body, plane, order));
            });
        }

        if (isPreview)
        {
            SnapEx.Create.DisplayModification(tempObjs);
        }
    }
Ejemplo n.º 2
0
        public static List <Snap.NX.Body> BodiesByName(this Snap.NX.Part part, string name)
        {
            var ufSession = NXOpen.UF.UFSession.GetUFSession();

            NXOpen.Tag tempTag = NXOpen.Tag.Null;
            var        list    = new List <Snap.NX.Body>();

            do
            {
                ufSession.Obj.CycleByNameAndType(part.NXOpenTag, name, NXOpen.UF.UFConstants.UF_solid_type, true, ref tempTag);
                if (tempTag != NXOpen.Tag.Null)
                {
                    try
                    {
                        Snap.NX.NXObject nxopenTaggedObject = GetObjectFromTag(tempTag);
                        if (nxopenTaggedObject != null && nxopenTaggedObject.ObjectType == Snap.NX.ObjectTypes.Type.Body)
                        {
                            list.Add(Snap.NX.Body.Wrap(tempTag));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("BodiesByName:" + ex.Message);
                    }
                    var dd = Snap.NX.NXObject.Wrap(tempTag);
                }
            }while (tempTag != NXOpen.Tag.Null);
            return(list);
        }
Ejemplo n.º 3
0
 internal Snap.NX.NXObject[] GetSelectedObjects()
 {
     TaggedObject[] objArray = (TaggedObject[])PropertyAccess.GetPropertyValue(this, Snap.UI.Block.PropertyType.ObjectArray, "SelectedObjects");
     if (((objArray == null) || (objArray.Length == 0)) || ((objArray.Length == 1) && (objArray[0] == null)))
     {
         return(new Snap.NX.NXObject[0]);
     }
     Snap.NX.NXObject[] objArray2 = new Snap.NX.NXObject[objArray.Length];
     for (int i = 0; i < objArray2.Length; i++)
     {
         objArray2[i] = Snap.NX.NXObject.CreateNXObject(objArray[i]);
     }
     return(objArray2);
 }
Ejemplo n.º 4
0
    void Perform(bool isPreview = false)
    {
        tempObjs.ForEach(u =>
        {
            Snap.NX.NXObject snapU = u;
            snapU.Delete();
        });
        tempObjs.Clear();
        if (!togglePreview.Value && isPreview)
        {
            return;
        }
        var bodies = bodySelect0.SelectedObjects.ToList();
        var plane  = plane0.SpecifiedPlane;

        if (bodies.Count > 0 && plane != null)
        {
            //int order = GetMaxOrder();
            //if (bodies.Count == 1)
            //{
            //    int tempInt;
            //    if (int.TryParse(stringElecName.Value.Split('-').LastOrDefault(), out tempInt))
            //    {
            //        order = tempInt - 1;
            //    }
            //}
            bodies.ForEach(u =>
            {
                //order++;
                tempObjs.Add(GeomcopyElec(isPreview, Snap.NX.Body.Wrap(u.NXOpenTag).NXOpenBody, plane.NXOpenDisplayableObject as NXOpen.Plane
                                          //, order
                                          ));
            });

            GeomcopyJiaju(isPreview, plane.NXOpenDisplayableObject as NXOpen.Plane);
        }

        if (isPreview)
        {
            SnapEx.Create.DisplayModification(tempObjs);
        }
    }
Ejemplo n.º 5
0
 internal virtual int OnFilter(General block, Snap.NX.NXObject selectedObject)
 {
     return(1);
 }
Ejemplo n.º 6
0
            public Snap.UI.Selection.Result Show()
            {
                Snap.UI.Response response;
                TaggedObject[]   objArray;
                NXOpen.Selection selectionManager = UI.GetUI().SelectionManager;
                Point3d          cursor           = new Point3d();

                NXOpen.Selection.SelectionAction clearAndEnableSpecific = NXOpen.Selection.SelectionAction.ClearAndEnableSpecific;
                string cue   = this.Cue;
                string title = this.Title;

                NXOpen.Selection.SelectionScope scope = (NXOpen.Selection.SelectionScope) this.Scope;
                bool includeFeatures = this.IncludeFeatures;
                bool keepHighlighted = this.KeepHighlighted;

                if (!this.AllowMultiple)
                {
                    TaggedObject obj2;
                    string       str3;
                    NXOpen.Selection.MaskTriple[] maskTripleArray = null;
                    if (includeFeatures)
                    {
                        maskTripleArray = new NXOpen.Selection.MaskTriple[this.MaskTripleArray.Length + 1];
                        for (int j = 0; j < this.MaskTripleArray.Length; j++)
                        {
                            maskTripleArray[j] = this.MaskTripleArray[j];
                        }
                        maskTripleArray[this.MaskTripleArray.Length].Type             = 0xcd;
                        maskTripleArray[this.MaskTripleArray.Length].Subtype          = 0;
                        maskTripleArray[this.MaskTripleArray.Length].SolidBodySubtype = 0;
                        if (maskTripleArray == null)
                        {
                            response = (Snap.UI.Response)selectionManager.SelectTaggedObject(cue, title, scope, includeFeatures, keepHighlighted, out obj2, out cursor);
                        }
                        else
                        {
                            response = (Snap.UI.Response)selectionManager.SelectTaggedObject(cue, title, scope, clearAndEnableSpecific, includeFeatures, keepHighlighted, maskTripleArray, out obj2, out cursor);
                        }
                    }
                    else
                    {
                        maskTripleArray = this.MaskTripleArray;
                        if (maskTripleArray == null)
                        {
                            response = (Snap.UI.Response)selectionManager.SelectTaggedObject(cue, title, scope, includeFeatures, keepHighlighted, out obj2, out cursor);
                        }
                        else
                        {
                            response = (Snap.UI.Response)selectionManager.SelectTaggedObject(cue, title, scope, clearAndEnableSpecific, includeFeatures, keepHighlighted, maskTripleArray, out obj2, out cursor);
                        }
                    }
                    if (obj2 == null)
                    {
                        return(new Snap.UI.Selection.Result(null, response, null));
                    }
                    Snap.NX.NXObject   obj3      = Snap.NX.NXObject.CreateNXObject(obj2);
                    Snap.NX.NXObject[] objArray2 = new Snap.NX.NXObject[] { obj3 };
                    UFSession          uFSession = Globals.UFSession;
                    UI.GetUI();
                    uFSession.Ui.AskLastPickedView(out str3);
                    return(new Snap.UI.Selection.Result(objArray2, response, GetCursorRay(str3, cursor)));
                }
                NXOpen.Selection.MaskTriple[] maskArray = null;
                if (includeFeatures)
                {
                    maskArray = new NXOpen.Selection.MaskTriple[this.MaskTripleArray.Length + 1];
                    for (int k = 0; k < this.MaskTripleArray.Length; k++)
                    {
                        maskArray[k] = this.MaskTripleArray[k];
                    }
                    maskArray[this.MaskTripleArray.Length].Type             = 0xcd;
                    maskArray[this.MaskTripleArray.Length].Subtype          = 0;
                    maskArray[this.MaskTripleArray.Length].SolidBodySubtype = 0;
                    if (maskArray == null)
                    {
                        response = (Snap.UI.Response)selectionManager.SelectTaggedObjects(cue, title, scope, includeFeatures, keepHighlighted, out objArray);
                    }
                    else
                    {
                        response = (Snap.UI.Response)selectionManager.SelectTaggedObjects(cue, title, scope, clearAndEnableSpecific, includeFeatures, keepHighlighted, maskArray, out objArray);
                    }
                }
                else
                {
                    maskArray = this.MaskTripleArray;
                    if (maskArray == null)
                    {
                        response = (Snap.UI.Response)selectionManager.SelectTaggedObjects(cue, title, scope, includeFeatures, keepHighlighted, out objArray);
                    }
                    else
                    {
                        response = (Snap.UI.Response)selectionManager.SelectTaggedObjects(cue, title, scope, clearAndEnableSpecific, includeFeatures, keepHighlighted, maskArray, out objArray);
                    }
                }
                if (objArray == null)
                {
                    return(new Snap.UI.Selection.Result(null, response, null));
                }
                Snap.NX.NXObject[] objects = new Snap.NX.NXObject[objArray.Length];
                for (int i = 0; i < objects.Length; i++)
                {
                    objects[i] = Snap.NX.NXObject.CreateNXObject(objArray[i]);
                }
                return(new Snap.UI.Selection.Result(objects, response, null));
            }
Ejemplo n.º 7
0
    void Perform(bool isHighlighted = false)
    {
        var workPart  = theSession.Parts.Work;
        var body      = selection0.SelectedObjects.FirstOrDefault() as Snap.NX.Body;
        var jiajuBody = selectionJiaju.SelectedObjects.FirstOrDefault() as Snap.NX.Body;

        tempObjs.ForEach(u => {
            Snap.NX.NXObject snapU = u;
            snapU.Delete();
        });
        tempObjs.Clear();

        if (body != null)
        {
            Snap.NX.Body snapBody = body;
            //电极原点
            var tempElecOrigin = SnapEx.Helper.GetElecMidPosition(workPart, body);
            if (tempElecOrigin == null)
            {
                theUI.NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, "该电极未发现基准点!");
                return;
            }
            var elecOrgin = (Snap.Position)tempElecOrigin;


            if (isHighlighted)
            {
                SnapEx.Create.DisplayModification(tempObjs);
            }

            bool isPatter = false;
            if (enum01.SelectedItem == "平移")
            {
                isPatter = toggleMovePatter.Value;
            }
            else
            {
                isPatter = toggleRotationPatter.Value;
            }
            int sum = 0;

            if (isPatter)
            {
                sum = (int)(expressionPatterSum.Value < 0?0:expressionPatterSum.Value);
            }

            double distance = expressionPatterDistance.Value;
            var    vector   = Snap.Vector.Unit(vectorPatter.Direction);

            if (body.NXOpenBody.OwningComponent != null && snapBody.Prototype != null)
            {
                var snapComponent = snapBody.OwningComponent;;
                NXOpen.Assemblies.Component component = snapComponent;


                var transForm = GetTransform(elecOrgin);

                for (int i = 0; i < sum + 1; i++)
                {
                    Snap.NX.Component newComponent = workPart.ComponentAssembly.CopyComponents(new List <NXOpen.Assemblies.Component> {
                        component
                    }.ToArray()).First();
                    newComponent.Prototype.Bodies.First().SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now);
                    tempObjs.Add(newComponent);

                    //平移旋转
                    var       trans  = transForm.Matrix;
                    Matrix3x3 matrix = new Matrix3x3();
                    matrix.Xx = trans[0]; matrix.Xy = trans[4]; matrix.Xz = trans[8];
                    matrix.Yx = trans[1]; matrix.Yy = trans[5]; matrix.Yz = trans[9];
                    matrix.Zx = trans[2]; matrix.Zy = trans[6]; matrix.Zz = trans[10];
                    workPart.ComponentAssembly.MoveComponent(newComponent, new Vector3d(trans[3], trans[7], trans[11]), matrix);

                    if (i != 0)
                    {
                        workPart.ComponentAssembly.MoveComponent(newComponent, (distance * i) * vector, new Snap.Orientation());
                    }
                }
            }
            else
            {
                NXOpen.Point point = null;
                if (!isHighlighted)
                {
                    var tempPoint = SnapEx.Helper.GetElecMidPointInPart(Snap.Globals.WorkPart, snapBody);
                    if (tempPoint != null)
                    {
                        point = tempPoint;
                    }
                }
                for (int i = 0; i < sum + 1; i++)
                {
                    var newBody = snapBody.Copy();
                    var guid    = Guid.NewGuid().ToString();
                    newBody.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid);
                    newBody.SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now);
                    tempObjs.Add(newBody);
                    var transForm = GetTransform(elecOrgin);
                    if (i != 0)
                    {
                        transForm = Snap.Geom.Transform.Composition(transForm, Snap.Geom.Transform.CreateTranslation((distance * i) * vector));
                    }

                    newBody.Move(transForm);
                    if (point != null)
                    {
                        Snap.NX.Point newPoint = Snap.NX.Point.Wrap(point.Tag).Copy();
                        newPoint.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid);
                        newPoint.Move(transForm);
                    }
                }
            }

            if (toggleJiaju.Value && jiajuBody != null)
            {
                for (int i = 0; i < sum + 1; i++)
                {
                    Snap.NX.Body snapJiajuBody = jiajuBody;
                    var          newJiajuBody  = snapJiajuBody.Copy();
                    var          guid          = Guid.NewGuid().ToString();
                    newJiajuBody.Layer = body.Layer;
                    newJiajuBody.SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now);
                    tempObjs.Add(newJiajuBody);
                    elecOrgin = new Snap.Position((snapBody.Box.MaxX + snapBody.Box.MinX) / 2, (snapBody.Box.MaxY + snapBody.Box.MinY) / 2, snapBody.Box.MinZ);
                    var transForm = GetTransform(elecOrgin);
                    if (i != 0)
                    {
                        transForm = Snap.Geom.Transform.Composition(transForm, Snap.Geom.Transform.CreateTranslation((distance * i) * vector));
                    }

                    newJiajuBody.Move(transForm);
                }
            }


            if (isHighlighted)
            {
                SnapEx.Create.DisplayModification(tempObjs);
            }
        }
    }