Conversion from Deprecated ParameterType to ForgeTypeId and display ForgeTypeId?

Conversion from Deprecated ParameterType to ForgeTypeId and display ForgeTypeId?

stephen_harrison
Advocate Advocate
1,237 Views
5 Replies
Message 1 of 6

Conversion from Deprecated ParameterType to ForgeTypeId and display ForgeTypeId?

stephen_harrison
Advocate
Advocate

I am trying to prepare some of my old code for the deprecation of ParameterType. Within that old code I obtained some data on Shared Parameters including the ParameterType:

 

ParameterElement paramElem = elem as ParameterElement;
SharedParameterElement sharedParamElem = paramElem as SharedParameterElement;
Definition def = sharedParamElem.GetDefinition();
ParameterType DataType = def.ParameterType;

 

This is then stored within a class list "ExistingSharedParameters" and contains:

 

public class ExistingSharedParam
{
    ........
    public ParameterType DataType { get; set; }
    ........
}

 

I believe this can be updated as follows:

 

ParameterElement paramElem = elem as ParameterElement;
SharedParameterElement sharedParamElem = paramElem as SharedParameterElement;
Definition def = sharedParamElem.GetDefinition();
ForgeTypeId DataType = def.GetDataType();


public class ExistingSharedParam
{
    .......
    public ForgeTypeId DataType { get; set; }
    .......
}

 

I Currently displayed these ParameterType within a DataGridView as below:

 

SharedParamDGV.Rows.Add(DataType);

 

However I am unable to display the ForgeTypeId as a meaningful string i.e. Length etc.

I am sure it will be a very simple answer but I am just not seeing it.

Any assistance much appreciated.

 

0 Likes
Accepted solutions (1)
1,238 Views
5 Replies
Replies (5)
Message 2 of 6

mhannonQ65N2
Collaborator
Collaborator

Use the TypeId property.

0 Likes
Message 3 of 6

stephen_harrison
Advocate
Advocate

@mhannonQ65N2. Thank you for your response and I know I am being rather dense today but can you provide a little for detail as I don't see how that fits into the code I provided unless you are saying it needs a full re-write?

I have tried the below but it still keeps showing "Autodesk.Revit.DB.ForgeTypeId"

DataType.TypeId
DataType.TypeId.ToString()

Thanks again.

0 Likes
Message 4 of 6

mhannonQ65N2
Collaborator
Collaborator

The TypeId property is a string. Just put it into the grid cell as it is. Try doing something like this:

ParameterElement paramElem = elem as ParameterElement;
SharedParameterElement sharedParamElem = paramElem as SharedParameterElement;
Definition def = sharedParamElem.GetDefinition();
ForgeTypeId ForgeDataType = def.GetDataType();
string DataType = ForgeDataType.TypeId;

public class ExistingSharedParam
{
    .......
    public string DataType { get; set; }
    .......
}

It's hard to say more without knowing how exactly you populate your grid.

0 Likes
Message 5 of 6

stephen_harrison
Advocate
Advocate

@mhannonQ65N2. Thank you for your response your proposal of

ForgeTypeId ForgeDataType = def.GetDataType();
string DataType = ForgeDataType.TypeId;

 This Is the same as my thoughts which I had tried and didn't work

ForgeTypeId DataType = def.GetDataType();
DataType.TypeId;

The result is ""autodesk.spec.aec:length-1.0.0".

There must be a way other than using split string to get length?

0 Likes
Message 6 of 6

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

"autodesk.spec.aec:length-1.0.0" is the 'official' name for it. You could use LabelUtils.GetLabelForSpec(ForgeTypeId) instead of TypeId to get the user-friendly name for it.