Ejemplo n.º 1
0
 public CreatePlate(TSG.Point point)
 {
     TSM.Part bPlate = CreateConturePlate(point);
     bPlate.Insert();
 }
Ejemplo n.º 2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            ModelObjectSelector mos = new ModelObjectSelector();

            TSM.ModelObjectEnumerator moe = mos.GetSelectedObjects();

            moe.SelectInstances = false;

            while (moe.MoveNext())
            {
                if (moe.Current is TSM.Part)
                {
                    TSM.Part part = moe.Current as TSM.Part;

                    // this method needs to be called to properly fill all the properties of the part
                    part.Select();

                    double partLength = 0.0;
                    double partHeight = 0.0;
                    double partWidth  = 0.0;
                    part.GetReportProperty("LENGTH", ref partLength);
                    part.GetReportProperty("HEIGHT", ref partHeight);
                    part.GetReportProperty("WIDTH", ref partWidth);

                    TSM.ModelObjectEnumerator MyAllBooleans = part.GetBooleans();
                    TSM.ModelObjectEnumerator MyAllBolts    = part.GetBolts();
                    TSM.ModelObject           MyFather      = part.GetFatherComponent();


                    TSG.CoordinateSystem coordinateSystem = part.GetCoordinateSystem();
                    TSM.WorkPlaneHandler planeHandler     = model.GetWorkPlaneHandler();

                    // before we create a new plane we need to store the old one
                    TSM.TransformationPlane original  = planeHandler.GetCurrentTransformationPlane();
                    TSM.TransformationPlane partPlane = new TSM.TransformationPlane(coordinateSystem);
                    planeHandler.SetCurrentTransformationPlane(partPlane);

                    //this.DrawCoordinateSystem();

                    TSG.Point p1 = new TSG.Point(0, partHeight / 2, 0);
                    TSG.Point p2 = new TSG.Point(partLength, partHeight / 2, 0);
                    TSG.Point p3 = new TSG.Point(partLength, -partHeight / 2, 0);
                    TSG.Point p4 = new TSG.Point(0, -partHeight / 2, 0);

                    TSM.ContourPlate CP            = new TSM.ContourPlate();
                    TSM.ContourPoint conturePoint1 = new TSM.ContourPoint(p1, null);
                    TSM.ContourPoint conturePoint2 = new TSM.ContourPoint(p2, null);
                    TSM.ContourPoint conturePoint3 = new TSM.ContourPoint(p3, null);
                    TSM.ContourPoint conturePoint4 = new TSM.ContourPoint(p4, null);

                    CP.AddContourPoint(conturePoint1);
                    CP.AddContourPoint(conturePoint2);
                    CP.AddContourPoint(conturePoint3);
                    CP.AddContourPoint(conturePoint4);
                    CP.Name   = "NEM";
                    CP.Finish = "xxx";
                    CP.Profile.ProfileString   = "PL" + partWidth;
                    CP.Material.MaterialString = "S235";
                    CP.Class = "1";

                    CP.Insert();

                    while (MyAllBooleans.MoveNext())
                    {
                        try
                        {
                            TSM.BooleanPart partBooleans = MyAllBooleans.Current as TSM.BooleanPart;

                            TSM.Part partBool = partBooleans.OperativePart as TSM.Part;
                            partBool.Class = TSM.BooleanPart.BooleanOperativeClassName;
                            partBool.Insert();

                            TSM.BooleanPart myboolpart = new TSM.BooleanPart();
                            myboolpart.Father = CP;
                            myboolpart.SetOperativePart(partBool);
                            myboolpart.Insert();
                            partBool.Delete();
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }


                    while (MyAllBolts.MoveNext())
                    {
                        try
                        {
                            if (MyAllBolts.Current is TSM.BoltGroup)
                            {
                                TSM.BoltGroup b = MyAllBolts.Current as TSM.BoltGroup;

                                TSM.Part toBolted = b.PartToBeBolted as TSM.Part;
                                TSM.Part toBolt   = b.PartToBoltTo as TSM.Part;
                                if (toBolted.Identifier.ID == toBolt.Identifier.ID)
                                {
                                    b.PartToBeBolted = CP;
                                    b.PartToBoltTo   = CP;
                                }
                                else if (toBolted.Identifier.ID == part.Identifier.ID)
                                {
                                    b.PartToBoltTo.GetBolts();
                                    b.PartToBeBolted = CP;
                                }
                                else
                                {
                                    b.PartToBoltTo = CP;
                                    b.PartToBeBolted.GetBolts();
                                }
                                b.Insert();
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }

                    if (MyFather != null)
                    {
                        TSM.ModelObjectEnumerator elementOfComponenet = MyFather.GetChildren();
                        while (elementOfComponenet.MoveNext())
                        {
                            TSM.Part element = elementOfComponenet.Current as TSM.Part;
                            try
                            {
                                if (element is TSM.Part)
                                {
                                    if (element.Identifier.ID == part.Identifier.ID)
                                    {
                                        element = CP;

                                        element.Modify();
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }



                    part.Delete();
                    planeHandler.SetCurrentTransformationPlane(original);
                }
            }

            this.model.CommitChanges();
        }