Beispiel #1
0
        /// <summary>
        /// This node can set the Section for Advance Steel beams from Dynamo.
        /// For the Section use the following format: "HEA  DIN18800-1#@§@#HEA100"
        /// </summary>
        /// <param name="beamElement">Advance Steel beam</param>
        /// <param name="sectionName">Section</param>
        /// <returns></returns>
        public static void SetSection(AdvanceSteel.Nodes.Object beamElement, string sectionName)
        {
            //lock the document and start transaction
            using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
            {
                string handle = beamElement.Handle;

                FilerObject obj = Utils.GetObject(handle);

                if (obj != null && obj.IsKindOf(FilerObject.eObjectType.kBeam))
                {
                    string sectionType = string.Empty;
                    string sectionSize = string.Empty;

                    string   separator = "#@" + '§' + "@#";
                    string[] section   = sectionName.Split(new string[] { separator }, System.StringSplitOptions.None);

                    if (section.Length == 2)
                    {
                        sectionType = section[0];
                        sectionSize = section[1];
                    }

                    Beam beam = obj as Beam;
                    beam.ChangeProfile(sectionType, sectionSize);
                }

                else
                {
                    throw new System.Exception("Failed to change section");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This node can set the Section for Advance Steel beams from Dynamo.
        /// For the Section use the following format: "HEA  DIN18800-1#@§@#HEA100"
        /// </summary>
        /// <param name="beamElement">Advance Steel beam</param>
        /// <param name="sectionName">Section</param>
        /// <returns></returns>
        public static void SetSection(AdvanceSteel.Nodes.Object beamElement, string sectionName)
        {
            //lock the document and start transaction
            using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
            {
                string handle = beamElement.Handle;

                FilerObject obj = Utils.GetObject(handle);

                if (obj != null && obj.IsKindOf(FilerObject.eObjectType.kBeam))
                {
                    string sectionType = Utils.SplitSectionName(sectionName)[0];
                    string sectionSize = Utils.SplitSectionName(sectionName)[1];

                    Beam beam = obj as Beam;
                    if (obj.IsKindOf(FilerObject.eObjectType.kCompoundBeam) && !Utils.CompareCompoundSectionTypes(beam.ProfSectionType, sectionType))
                    {
                        throw new System.Exception("Failed to change section as compound section type is different");
                    }
                    beam.ChangeProfile(sectionType, sectionSize);
                }
                else
                {
                    throw new System.Exception("Failed to change section");
                }
            }
        }
        /// <summary>
        /// This node can set User attributes for Advance Steel elements from Dynamo
        /// </summary>
        /// <param name="element">Advance Steel element</param>
        /// <param name="AttIdx">The index of the User attribute. Is a number between 1 and 10</param>
        /// <param name="value">Attribute value</param>
        /// <returns></returns>
        public static void SetUserAttribute(AdvanceSteel.Nodes.Object element, int AttIdx, string value)
        {
            if (AttIdx < 1 || AttIdx > 10)
            {
                throw new System.Exception("Attribute index is not in the range from 1 to 10");
            }

            //lock the document and start transaction
            using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
            {
                string handle = element.Handle;

                FilerObject   obj    = Utils.GetObject(handle);
                AtomicElement atomic = obj as AtomicElement;

                if (obj != null && obj.IsKindOf(FilerObject.eObjectType.kAtomicElem))
                {
                    //[1, 10] ->[0 ,9]
                    AttIdx = AttIdx - 1;

                    atomic.SetUserAttribute(AttIdx, value);
                }
                else
                {
                    throw new System.Exception("Failed to set attribute");
                }
            }
        }
Beispiel #4
0
        internal CompoundBeam(Autodesk.DesignScript.Geometry.Point ptStart, Autodesk.DesignScript.Geometry.Point ptEnd, Autodesk.DesignScript.Geometry.Vector vOrientation, string beamSection)
        {
            //use lock just to be safe
            //AutoCAD does not support multithreaded access
            lock (myLock)
            {
                //lock the document and start transaction
                using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
                {
                    string handle = AdvanceSteel.Services.ElementBinder.GetHandleFromTrace();

                    Point3d beamStart = Utils.ToAstPoint(ptStart, true);
                    Point3d beamEnd   = Utils.ToAstPoint(ptEnd, true);

                    string sectionType = Utils.SplitSectionName(beamSection)[0];
                    string sectionName = Utils.SplitSectionName(beamSection)[1];

                    if (string.IsNullOrEmpty(handle) || Utils.GetObject(handle) == null)
                    {
                        var myBeam = new Autodesk.AdvanceSteel.Modelling.CompoundStraightBeam(beamStart, beamEnd, Vector3d.kXAxis);
                        myBeam.CreateComponents(sectionType, sectionName);

                        myBeam.WriteToDb();
                        handle = myBeam.Handle;
                    }

                    CompoundStraightBeam beamCompound = Utils.GetObject(handle) as CompoundStraightBeam;

                    if (beamCompound != null && beamCompound.IsKindOf(FilerObject.eObjectType.kCompoundStraightBeam))
                    {
                        Utils.AdjustBeamEnd(beamCompound, beamStart);
                        beamCompound.SetSysStart(beamStart);
                        beamCompound.SetSysEnd(beamEnd);
                        Utils.SetOrientation(beamCompound, Utils.ToAstVector3d(vOrientation, true));

                        if (Utils.CompareCompoundSectionTypes(sectionType, beamCompound.ProfSectionType))
                        {
                            if (beamCompound.ProfSectionName != sectionName)
                            {
                                beamCompound.ChangeProfile(sectionType, sectionName);
                            }
                        }
                        else
                        {
                            throw new System.Exception("Failed to change section as compound section type is different than the one created the beam was created with");
                        }
                    }
                    else
                    {
                        throw new System.Exception("Not a compound beam");
                    }

                    this.Handle = handle;

                    AdvanceSteel.Services.ElementBinder.CleanupAndSetElementForTrace(beamCompound);
                }
            }
        }
Beispiel #5
0
        internal Plate(Autodesk.DesignScript.Geometry.Polygon poly)
        {
            if (poly.IsPlanar == false)
            {
                throw new System.Exception("Polygon is not planar");
            }

            //use lock just to be safe
            //AutoCAD does not support multithreaded access
            lock (myLock)
            {
                //lock the document and start transaction
                using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
                {
                    string handle = AdvanceSteel.Services.ElementBinder.GetHandleFromTrace();

                    Point3d[] astPoints = Utils.ToAstPoints(poly.Points, true);
                    var       astPoly   = new Autodesk.AdvanceSteel.Geometry.Polyline3d(astPoints, null, poly.IsClosed, true);
                    var       polyPlane = new Plane(astPoints[0], astPoly.Normal);

                    if (string.IsNullOrEmpty(handle) || Utils.GetObject(handle) == null)
                    {
                        var myPlate = new Autodesk.AdvanceSteel.Modelling.Plate(polyPlane, astPoints);

                        myPlate.WriteToDb();
                        handle = myPlate.Handle;
                    }

                    Autodesk.AdvanceSteel.Modelling.Plate plate = Utils.GetObject(handle) as Autodesk.AdvanceSteel.Modelling.Plate;

                    if (plate != null && plate.IsKindOf(FilerObject.eObjectType.kPlate))
                    {
                        plate.DefinitionPlane = polyPlane;
                        plate.SetPolygonContour(astPoints);
                    }
                    else
                    {
                        throw new System.Exception("Not a Plate");
                    }

                    this.Handle = handle;

                    AdvanceSteel.Services.ElementBinder.CleanupAndSetElementForTrace(plate);
                }
            }
        }
Beispiel #6
0
        internal StraightBeam(Autodesk.DesignScript.Geometry.Point ptStart, Autodesk.DesignScript.Geometry.Point ptEnd, Autodesk.DesignScript.Geometry.Vector vOrientation)
        {
            //use lock just to be safe
            //AutoCAD does not support multithreaded access
            lock (myLock)
            {
                //lock the document and start transaction
                using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
                {
                    string handle = AdvanceSteel.Services.ElementBinder.GetHandleFromTrace();

                    Point3d beamStart = Utils.ToAstPoint(ptStart, true);
                    Point3d beamEnd   = Utils.ToAstPoint(ptEnd, true);

                    if (string.IsNullOrEmpty(handle) || Utils.GetObject(handle) == null)
                    {
                        ProfileName profName = new ProfileName();
                        ProfilesManager.GetProfTypeAsDefault("I", out profName);
                        var myBeam = new Autodesk.AdvanceSteel.Modelling.StraightBeam(profName.Name, beamStart, beamEnd, Vector3d.kXAxis);

                        myBeam.WriteToDb();
                        handle = myBeam.Handle;
                    }

                    Beam beam = Utils.GetObject(handle) as Beam;

                    if (beam != null && beam.IsKindOf(FilerObject.eObjectType.kStraightBeam))
                    {
                        Utils.AdjustBeamEnd(beam, beamStart);
                        beam.SetSysStart(beamStart);
                        beam.SetSysEnd(beamEnd);

                        Utils.SetOrientation(beam, Utils.ToAstVector3d(vOrientation, true));
                    }
                    else
                    {
                        throw new System.Exception("Not a straight Beam");
                    }

                    this.Handle = handle;

                    AdvanceSteel.Services.ElementBinder.CleanupAndSetElementForTrace(beam);
                }
            }
        }
Beispiel #7
0
        public virtual void Dispose()
        {
            //use lock just to be safe
            //AutoCAD does not support multithreaded access
            lock (myLock)
            {
                // Do not cleanup elements if we are shutting down Dynamo.
                if (AdvanceSteel.Services.DisposeLogic.IsShuttingDown || AdvanceSteel.Services.DisposeLogic.IsClosingHomeworkspace)
                {
                    return;
                }

                //this function is not implemented for the moment
                bool didAdvanceSteelDelete = AdvanceSteel.Services.LifecycleManager <string> .GetInstance().IsAdvanceSteelDeleted(Handle);

                var elementManager = AdvanceSteel.Services.LifecycleManager <string> .GetInstance();

                int remainingBindings = elementManager.UnRegisterAssociation(Handle, this);

                // Do not delete owned elements
                if (remainingBindings == 0 && !didAdvanceSteelDelete)
                {
                    //lock the document and start a transaction
                    using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
                    {
                        if (Handle != null)
                        {
                            var filerObject = Utils.GetObject(Handle);

                            if (filerObject != null)
                            {
                                filerObject.DelFromDb();
                            }

                            ObjectHandle = string.Empty;
                        }
                    }
                }
                else
                {
                    //This element has gone
                    ObjectHandle = string.Empty;
                }
            }
        }
        internal TaperedBeam(Autodesk.DesignScript.Geometry.Point ptStart, Autodesk.DesignScript.Geometry.Point ptEnd, Autodesk.DesignScript.Geometry.Vector vOrientation, double startHeight = 100, double endHeight = 100, double webThickness = 100)
        {
            //use lock just to be safe
            //AutoCAD does not support multithreaded access
            lock (myLock)
            {
                //lock the document and start transaction
                using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
                {
                    string handle = AdvanceSteel.Services.ElementBinder.GetHandleFromTrace();

                    Point3d beamStart = Utils.ToAstPoint(ptStart, true);
                    Point3d beamEnd   = Utils.ToAstPoint(ptEnd, true);

                    if (string.IsNullOrEmpty(handle) || Utils.GetObject(handle) == null)
                    {
                        var myBeam = new Autodesk.AdvanceSteel.Modelling.BeamTapered(beamStart, beamEnd, Vector3d.kXAxis, startHeight, endHeight, webThickness);
                        myBeam.CreateComponents();

                        myBeam.WriteToDb();
                        handle = myBeam.Handle;
                    }

                    BeamTapered beamTapered = Utils.GetObject(handle) as BeamTapered;

                    if (beamTapered != null && beamTapered.IsKindOf(FilerObject.eObjectType.kBeamTapered))
                    {
                        Utils.AdjustBeamEnd(beamTapered, beamStart);
                        beamTapered.SetSysStart(beamStart);
                        beamTapered.SetSysEnd(beamEnd);

                        Utils.SetOrientation(beamTapered, Utils.ToAstVector3d(vOrientation, true));
                    }
                    else
                    {
                        throw new System.Exception("Not a tapered beam");
                    }

                    this.Handle = handle;

                    AdvanceSteel.Services.ElementBinder.CleanupAndSetElementForTrace(beamTapered);
                }
            }
        }
        /// <summary>
        /// This node can set the Material for Advance Steel elements from Dynamo
        /// </summary>
        /// <param name="element">Advance Steel element</param>
        /// <param name="materialName">Material</param>
        /// <returns></returns>
        public static void SetMaterial(AdvanceSteel.Nodes.Object element, string materialName)
        {
            //lock the document and start transaction
            using (var _CADAccess = new AdvanceSteel.Services.ObjectAccess.CADContext())
            {
                string handle = element.Handle;

                FilerObject   obj    = Utils.GetObject(handle);
                AtomicElement atomic = obj as AtomicElement;

                if (obj != null && obj.IsKindOf(FilerObject.eObjectType.kAtomicElem))
                {
                    atomic.Material = materialName;
                }

                else
                {
                    throw new System.Exception("Failed to set material");
                }
            }
        }