Esempio n. 1
0
        public static string GetDirectionValue(this XYZDirection value)
        {
            string output = null;

            try
            {
                Type type = value.GetType();

                FieldInfo fi = type.GetField(value.ToString());
                DirectionValueAttribute[] attrs =
                    fi.GetCustomAttributes(typeof(DirectionValueAttribute),
                                           false) as DirectionValueAttribute[];

                output = attrs.FirstOrDefault().Value;
            }

            catch (ArgumentNullException ane)
            {
                Console.WriteLine("There are no values in this object" + ane.StackTrace.ToString());
            }


            return(output);
        }
Esempio n. 2
0
        /// <summary>
        /// Offsets an element a set amount in a specific direction set by the XYZDirection enum
        /// </summary>
        /// <param name="originalelement">element, the new element should be offset from</param>
        /// <param name="offsetamount">amount new element should be offset from original</param>
        /// <param name="offsetdirection">direction element should be offset</param>
        /// <returns></returns>
        public static ElementId Offset(this Element originalelement, double offsetamount, XYZDirection offsetdirection)
        {
            // variable for new offset element
            ElementId newelement = null;

            // the current document
            Document curdoc = originalelement.Document;

            // element's XYZ
            LocationPoint elp           = originalelement.Location as LocationPoint;
            XYZ           elem_location = null;


            // depending on user input offset direction should be incremented by the offsetamount
            switch (offsetdirection)
            {
            default:
                break;

            case XYZDirection.X:
                elem_location = new XYZ(offsetamount, 0.0, 0.0) + elp.Point;
                break;

            case XYZDirection.Y:
                elem_location = new XYZ(0.0, offsetamount, 0.0) + elp.Point;
                break;

            case XYZDirection.Z:
                elem_location = new XYZ(0.0, 0.0, offsetamount) + elp.Point;
                break;
            }

            try
            {
                // attempt to offset the element within the transaction
                using (Transaction tr_offset = new Transaction(curdoc, "Offsetting element"))
                {
                    tr_offset.Start();
                    newelement = ElementTransformUtils.CopyElement(curdoc, originalelement.Id, elem_location).FirstOrDefault();
                    tr_offset.Commit();
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Command Failed. See below: \n" + e.StackTrace.ToString());
            }

            return(newelement);
        }