How to get the value of type parameters?

How to get the value of type parameters?

zhongbo.wu
Contributor Contributor
3,313 Views
2 Replies
Message 1 of 3

How to get the value of type parameters?

zhongbo.wu
Contributor
Contributor

Hi, all

 

I want to get the value of type parameters of an element, and i write the codes as below:

 

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    public class cmdParameter : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            Selection sel = uiApp.ActiveUIDocument.Selection;

            Transaction ts = new Transaction(doc, "http://test.com");
            ts.Start();
            //选中的元素,这里选中一个管道Pipe
            Element elemPick = null;
            Reference refelem = sel.PickObject(ObjectType.Element, "请选择一个风管");
            elemPick = doc.GetElement(refelem.ElementId);

            //遍历元素的普通参数
            string strParameter = "基本属性";
            foreach (Parameter p in elemPick.Parameters)
            {
                strParameter += p.Definition.ParameterGroup + "," + p.Definition.Name + "," + p.AsValueString() + "\n";
            }

            strParameter += "类型属性:\n";
            //遍历元素的类型属性
            ElementType elemType = doc.GetElement(elemPick.GetTypeId()) as ElementType;            
            foreach (Parameter p in elemType.Parameters)
            {
                //doc.GetElement(p.AsElementId());
                strParameter += p.Definition.ParameterGroup + "," + p.Definition.Name + "," + p.AsValueString() + "\n";
                
            }
            TaskDialog.Show("parameter", strParameter);

            ts.Commit();

            return Result.Succeeded;
        }
  }

i can get the parameters of elemType, but can not get the value of them, is there any problem in my code?

 

Thanks a lot!

 

0 Likes
Accepted solutions (1)
3,314 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

The .AsValueString method is only valid for storage types of double and integer, containing measured quantities.

 

If used on parameters with storagetype String or ElementID for example then I believe it should return nothing.

 

Generally you should review the storage type property of the parameter first and then use the approriate .As### function to get the internal value.

 

If the storage type is double or integer then you can check if it has a valid display unit type and either use the UnitUtils class to convert from internal units or use the .AsValueString. Otherwise you can't use this and should use instead .AsElementID, AsString, AsDouble, AsInteger.

 

Some parameters have a 'None' storage type (internal parameters) and should be skipped.

 

 

0 Likes
Message 3 of 3

zhongbo.wu
Contributor
Contributor
I get it ,thanks a lot!
0 Likes