Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How To read the Value of a Family instance SharedParameter

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
fawzimasri7137
1194 Views, 12 Replies

How To read the Value of a Family instance SharedParameter

Hi ,

 

I am trying to read the value of a family instance Shared Parameter.  I can set it alright, but i cannot read it.

I created a TEXT Shared-Parameter named "KDS_PIPING_SYSTEM_TYPE" in the Document UI:

shared parmater file:

------------------------

# This is a Revit shared parameter file.
# Do not edit manually.
*METAVERSIONMINVERSION
META21
*GROUPIDNAME
GROUP1KDS_IDENTITY_PARAMS
GROUP2KDS_GROUP_
*PARAMGUIDNAMEDATATYPEDATACATEGORYGROUPVISIBLEDESCRIPTIONUSERMODIFIABLEHIDEWHENNOVALUE
PARAM d7196377-8d4d-4b25-8789-912f72cc2f80 KDS_PIPING_SYSTEM_TYPE TEXT 1 1 1 0

-----------------


Then I opened a Sleeve Family and i added the above Shared-parameter "KDS_PIPING_SYSTEM_TYPE" inside it, using the UI as well.

 


Now in the API, I did the following to print out the content of the Sleeve Shared-Parameter "KDS_PIPING_SYSTEM_TYPE"

I create a new instance of the sleeve family as:

 

using (Transaction insertSleeve_trx = new Transaction(actvDoc, "Insert Sleeves"))
{
insertSleeve_trx.Start();
sleeveFamSymbol.Activate();
sleeve_famInst = actvDoc.Create.NewFamilyInstance(intersection, sleeveFamSymbol, f, StructuralType.NonStructural);
insertSleeve_trx.Commit();
sleevesLocPnt_lst.Add(intersection);
}

 

 

Then I get the "KDS_PIPING_SYSTEM_TYPE" parameter as:

 

    Parameter slv_SysType = sleeve_famInst.LookupParameter("KDS_PIPING_SYSTEM_TYPE");

 


Then i assign a Value to it:

 

slv_SysType.Set(p_SysType.AsValueString());   // "KDS_RWL_AG_CI"

 

 

I try to read it but i get nothing.

 

TaskDialog.Show("insrtSleeve", "AFTER set KDS_PIPING_SYSTEM_TYPE: " + sleeve_famInst.LookupParameter("KDS_PIPING_SYSTEM_TYPE").AsValueString());

 

 


But the UI shows that it DOES have the correct  Value...

image.png

Realizing that it is a Shared-Parameter and it should be treated differently, i tried soso method.

 

Element element = actvDoc.GetElement(sleeve_famInst.Id);
Parameter p4 = element.get_Parameter(new Guid("d7196377-8d4d-4b25-8789-912f72cc2f80"));
TaskDialog.Show("insrtSleeve", "p4 AsString: " + p4.AsString());

 

 

But this gave me nothing as well.

image.png

I made sure that my code is using the correct family instance and correct  shared parameter and it is:

image.png

image.png

Any idea on how to tackle this problem, i.e how do i "Read" the value of a shared Parameter in a Family instance?

 

thanks.. and sorry for the long post.

12 REPLIES 12
Message 2 of 13

@fawzimasri7137 can you post all the relevant code together in a reply?

Message 3 of 13

@fawzimasri7137 can you post all the relevant code together in a reply?
Message 4 of 13
NGM_AiYo
in reply to: fawzimasri7137

what about AsValueString ?
Message 5 of 13
fawzimasri7137
in reply to: NGM_AiYo

I did not show that part of the code, but I tried AsValueString, ToString and AsString and nothing worked… as in all returned empty string and not what the UI is showing.

 

Are my steps correct though? 

Message 6 of 13

Hi @fawzimasri7137 ,

 

One suggestion is to install the RevitLookUp tool and explore the Family instance parameters.

 

RevitLookUp tool: https://github.com/jeremytammik/RevitLookup 

 

Also, please take a look at this below link

https://www.youtube.com/watch?v=8I3k3NjHV84


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 7 of 13

@danielJY6FBcode has too many debug notes in it so i can't send it now... sorry,

@naveen.kumar.t  

i installed the lookup tool.  it did not help me in this matter, but i thought maybe someone here has keener eyes than myself and can spot something.

As far as i can tell, everything checks:

- The value that i am getting from the pipe

- The ID of the Sleeve instance

- The GUID of the Parameter

- The Value of the Parameter in the UI

The only thing that is still missing is that  "p4.AsString."

Other things i tried was changing the default value in the family instance itself, just to make sure that whatever i am seeing is not stale value  in the family itself and i am not actually doing any writing to this parameter to begin with , but even this did not help.  i am able to write other values based on the associated pipe.

 

I attached a large image, just to make the point but the above summarizes it, if it was too busy .

 

any other ideas i can try ?

Message 8 of 13

Hi @fawzimasri7137 ,

 

Looks like, this is not an expected behavior.

To analyze this issue at our end, Could you please send me the below details?

1)A complete yet minimal non-confidential Revit sample model.

2)A complete yet minimal non-confidential sample code

3)Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch, etc.

4)Revit version details

Please note, Do not send us any information that you consider to be a trade secret to your company.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 9 of 13

Here is an RVT 2020 with a macro the depicts the problem with reading a shared parameter as described above.

i also attached the shared parameter file... i guess you have to reload it once you open the RVT.

Message 10 of 13

Hi @fawzimasri7137 ,

 

Sorry, I am not able to reproduce the issue at my end.

 

I am not able to find anything called "KDS_Hilti-FS_CFS_CID" in the project file you shared.

 

So I created my own family and added the shared parameters to my family. (The shared parameter in the text file KDS_SHARED_PARAMS.txt)

 

I am able to get the shared parameters by GUIDs. I am able to set the value to the parameter using the Parameter.Set().

 

One suggestion I have for you is,
1)Creating a family instance should be inside the transaction.
2)Setting a value to a parameter should be in a separate transaction

 

The only problem I find in your macro is after setting the value to the parameter, you are trying to read the value of the parameter in the same transaction. Since the transaction is not committed, the value has not been set to the parameter yet. The value will be set to the parameter only after the transaction is committed. So That's why you are getting nothing in AsValueString() or AsString().

Parameter slv_SysType_param = sleeve_famInst.LookupParameter("KDS_PIPING_SYSTEM_TYPE");
slv_SysType_param.Set(SysType_str);

In the above code, After setting the value, commit the transaction.

After committing the transaction, try to retrieve the value.

Could you please try this and let me know?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 11 of 13

hi @naveen.kumar.t 

Thanks for your support...

 

so i moved reading the parameter to after the commit and it works as you said.... i am a bit disappointed with myself since this was my first "Aha moment" when i was first debugging it...

 

Anyways, regarding Separate transactions. i think i had that correct already, i.e. one trx for inserting the sleeve, and another for setting a value to the shared parameter.

 

i have attached the missing family and the fix on the macro.

thanks again,

 

 

Message 12 of 13

HI @fawzimasri7137 ,

 

I am glad that my suggestion helped you to resolve the issue.
Do you need any other help from my end on this issue you reported?

Looks like, everything is working fine for you now.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 13 of 13

yes, it does...

 

thanks for seeing this through.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community