Ejemplo n.º 1
0
        /// <summary>
        /// Create a new Global Parameter by Name and Type
        /// </summary>
        /// <param name="name">Name fo the parameter</param>
        /// <param name="parameterType">Parameter type</param>
        /// <returns></returns>
        public static GlobalParameter ByName(string name, string parameterType)
        {
            Autodesk.Revit.DB.ParameterType ptype = Autodesk.Revit.DB.ParameterType.Text;
            if (!Enum.TryParse <Autodesk.Revit.DB.ParameterType>(parameterType, out ptype))
            {
                ptype = Autodesk.Revit.DB.ParameterType.Text;
            }

            if (!Autodesk.Revit.DB.GlobalParametersManager.AreGlobalParametersAllowed(Document))
            {
                throw new Exception(Properties.Resources.DocumentDoesNotSupportGlobalParams);
            }

            return(new GlobalParameter(name, ptype));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize a GlobalParameter element
        /// </summary>
        /// <param name="line"></param>
        private void InitGlobalParameter(string name, Autodesk.Revit.DB.ParameterType type)
        {
            if (Autodesk.Revit.DB.GlobalParametersManager.IsUniqueName(Document, name))
            {
                TransactionManager.Instance.EnsureInTransaction(Document);

                Autodesk.Revit.DB.GlobalParameter g = Autodesk.Revit.DB.GlobalParameter.Create(Document, name, type);

                InternalSetGlobalParameter(g);

                TransactionManager.Instance.TransactionTaskDone();

                ElementBinder.SetElementForTrace(this.InternalElement);
            }
            else
            {
                throw new Exception(Properties.Resources.NameAlreadyInUse);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize a GlobalParameter element
        /// </summary>
        /// <param name="line"></param>
        private void InitGlobalParameter(string name, Autodesk.Revit.DB.ParameterType type)
        {
            var existingId = Autodesk.Revit.DB.GlobalParametersManager.FindByName(Document, name);

            if (existingId != null && existingId != Autodesk.Revit.DB.ElementId.InvalidElementId)
            {
                // GP already exists
                var existingParameter = Document.GetElement(existingId) as Autodesk.Revit.DB.GlobalParameter;
                InternalSetGlobalParameter(existingParameter);
            }
            else
            {
                // Create a new GP
                TransactionManager.Instance.EnsureInTransaction(Document);
                Autodesk.Revit.DB.GlobalParameter newParameter = Autodesk.Revit.DB.GlobalParameter.Create(Document, name, type);
                InternalSetGlobalParameter(newParameter);
                TransactionManager.Instance.TransactionTaskDone();
            }

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalGlobalParameter);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// GlobalParameter
 /// </summary>
 /// <param name="name"></param>
 /// <param name="type"></param>
 private GlobalParameter(string name, Autodesk.Revit.DB.ParameterType type)
 {
     SafeInit(() => InitGlobalParameter(name, type));
 }
Ejemplo n.º 5
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     Autodesk.Revit.DB.ParameterType type = (Autodesk.Revit.DB.ParameterType)value;
     return(type.ToString());
 }