Example #1
0
        internal PlatePolycut(AdvanceSteel.Nodes.SteelDbObject element,
                              double xOffset, double yOffset, int corner,
                              int cutShapeRectCircle,
                              List <Property> plateFeatureProperties)
        {
            lock (access_obj)
            {
                using (var ctx = new SteelServices.DocContext())
                {
                    List <Property> defaultData     = plateFeatureProperties.Where(x => x.Level == ".").ToList <Property>();
                    List <Property> postWriteDBData = plateFeatureProperties.Where(x => x.Level == "Z_PostWriteDB").ToList <Property>();

                    double length = 0;
                    double width  = 0;
                    double radius = 0;

                    if (defaultData.FirstOrDefault <Property>(x => x.Name == "Length") != null)
                    {
                        length = (double)defaultData.FirstOrDefault <Property>(x => x.Name == "Length").InternalValue;
                    }
                    if (defaultData.FirstOrDefault <Property>(x => x.Name == "Width") != null)
                    {
                        width = (double)defaultData.FirstOrDefault <Property>(x => x.Name == "Width").InternalValue;
                    }
                    if (defaultData.FirstOrDefault <Property>(x => x.Name == "Radius") != null)
                    {
                        radius = (double)defaultData.FirstOrDefault <Property>(x => x.Name == "Radius").InternalValue;
                    }

                    string existingFeatureHandle = SteelServices.ElementBinder.GetHandleFromTrace();

                    string           elementHandle = element.Handle;
                    FilerObject      obj           = Utils.GetObject(elementHandle);
                    PlateFeatContour plateFeat     = null;
                    if (obj != null && obj.IsKindOf(FilerObject.eObjectType.kPlate))
                    {
                        if (string.IsNullOrEmpty(existingFeatureHandle) || Utils.GetObject(existingFeatureHandle) == null)
                        {
                            Matrix2d m2d = new Matrix2d();
                            m2d.SetCoordSystem(new Point2d(xOffset, yOffset), new Vector2d(1, 0), new Vector2d(0, 1));
                            switch (cutShapeRectCircle)
                            {
                            case 0:
                                plateFeat = new PlateFeatContour(m2d, length, width);
                                break;

                            case 1:
                                plateFeat = new PlateFeatContour(m2d, radius);
                                break;
                            }

                            Vector2d offset;
                            switch (corner)
                            {
                            case 0: //Top Left
                                offset = new Vector2d(-1, 1);
                                break;

                            case 1: //Top Right
                                offset = new Vector2d(1, 1);
                                break;

                            case 2: //Bottom Right
                                offset = new Vector2d(1, -1);
                                break;

                            case 3: //Bottom left
                                offset = new Vector2d(-1, -1);
                                break;

                            default: //Anything else ignore
                                offset = new Vector2d(0, 0);
                                break;
                            }
                            plateFeat.Offset = offset;
                            AtomicElement atomic = obj as AtomicElement;

                            if (defaultData != null)
                            {
                                Utils.SetParameters(plateFeat, defaultData);
                            }

                            atomic.AddFeature(plateFeat);

                            if (postWriteDBData != null)
                            {
                                Utils.SetParameters(plateFeat, postWriteDBData);
                            }
                        }
                        else
                        {
                            plateFeat = Utils.GetObject(existingFeatureHandle) as PlateFeatContour;
                            if (plateFeat != null && plateFeat.IsKindOf(FilerObject.eObjectType.kPlateFeatContour))
                            {
                                Plate plate = obj as Plate;
                                plate.DelFeature(plateFeat);
                                plate.WriteToDb();

                                Matrix2d m2d = new Matrix2d();
                                m2d.SetCoordSystem(new Point2d(xOffset, yOffset), new Vector2d(1, 0), new Vector2d(0, 1));
                                switch (cutShapeRectCircle)
                                {
                                case 0:
                                    plateFeat = new PlateFeatContour(m2d, length, width);
                                    break;

                                case 1:
                                    plateFeat = new PlateFeatContour(m2d, radius);
                                    break;
                                }

                                Vector2d offset;
                                switch (corner)
                                {
                                case 0: //Top Left
                                    offset = new Vector2d(-1, 1);
                                    break;

                                case 1: //Top Right
                                    offset = new Vector2d(1, 1);
                                    break;

                                case 2: //Bottom Right
                                    offset = new Vector2d(1, -1);
                                    break;

                                case 3: //Bottom left
                                    offset = new Vector2d(-1, -1);
                                    break;

                                default: //Anything else ignore
                                    offset = new Vector2d(0, 0);
                                    break;
                                }
                                plateFeat.Offset = offset;
                                AtomicElement atomic = obj as AtomicElement;

                                if (defaultData != null)
                                {
                                    Utils.SetParameters(plateFeat, defaultData);
                                }

                                atomic.AddFeature(plateFeat);

                                if (postWriteDBData != null)
                                {
                                    Utils.SetParameters(plateFeat, postWriteDBData);
                                }
                            }
                            else
                            {
                                throw new System.Exception("Not a Plate Feature");
                            }
                        }
                    }
                    else
                    {
                        throw new System.Exception("No Input Element found");
                    }

                    Handle = plateFeat.Handle;
                    SteelServices.ElementBinder.CleanupAndSetElementForTrace(plateFeat);
                }
            }
        }
Example #2
0
        internal PlatePolycut(AdvanceSteel.Nodes.SteelDbObject element,
                              Polyline3d cutPolyline,
                              Autodesk.AdvanceSteel.Geometry.Vector3d normal,
                              Autodesk.AdvanceSteel.Geometry.Vector3d lengthVector,
                              List <Property> plateFeatureProperties)
        {
            lock (access_obj)
            {
                using (var ctx = new SteelServices.DocContext())
                {
                    List <Property> defaultData     = plateFeatureProperties.Where(x => x.Level == ".").ToList <Property>();
                    List <Property> postWriteDBData = plateFeatureProperties.Where(x => x.Level == "Z_PostWriteDB").ToList <Property>();

                    string existingFeatureHandle = SteelServices.ElementBinder.GetHandleFromTrace();

                    string            elementHandle = element.Handle;
                    FilerObject       obj           = Utils.GetObject(elementHandle);
                    PlateContourNotch plateFeat     = null;
                    if (obj != null && obj.IsKindOf(FilerObject.eObjectType.kPlate))
                    {
                        if (string.IsNullOrEmpty(existingFeatureHandle) || Utils.GetObject(existingFeatureHandle) == null)
                        {
                            Plate plate = obj as Plate;
                            plateFeat = new PlateContourNotch(plate, 0, cutPolyline, normal, lengthVector);

                            if (defaultData != null)
                            {
                                Utils.SetParameters(plateFeat, defaultData);
                            }

                            plate.AddFeature(plateFeat);

                            if (postWriteDBData != null)
                            {
                                Utils.SetParameters(plateFeat, postWriteDBData);
                            }
                        }
                        else
                        {
                            plateFeat = Utils.GetObject(existingFeatureHandle) as PlateContourNotch;
                            if (plateFeat != null && plateFeat.IsKindOf(FilerObject.eObjectType.kPlateContourNotch))
                            {
                                Plate plate = obj as Plate;
                                plate.DelFeature(plateFeat);
                                plate.WriteToDb();

                                plateFeat = new PlateContourNotch(plate, 0, cutPolyline, normal, lengthVector);
                                AtomicElement atomic = obj as AtomicElement;

                                if (defaultData != null)
                                {
                                    Utils.SetParameters(plateFeat, defaultData);
                                }

                                atomic.AddFeature(plateFeat);

                                if (postWriteDBData != null)
                                {
                                    Utils.SetParameters(plateFeat, postWriteDBData);
                                }
                            }
                            else
                            {
                                throw new System.Exception("Not a Plate Feature");
                            }
                        }
                    }
                    else
                    {
                        throw new System.Exception("No Input Element found");
                    }

                    Handle = plateFeat.Handle;
                    SteelServices.ElementBinder.CleanupAndSetElementForTrace(plateFeat);
                }
            }
        }