How to set custom parameter values on titleblock ?

How to set custom parameter values on titleblock ?

Anonymous
Not applicable
2,969 Views
10 Replies
Message 1 of 11

How to set custom parameter values on titleblock ?

Anonymous
Not applicable

I wanted to set custom parameter value on titleblock.

I tried following way,

 

Created one shared parameter - 'TestParameter'

Added one label on titleblock and assigned a shared parameter to it.

In project, added the same shared parameter under ProjectParameters with 'Sheets' as category.

FilteredElementCollector TitleBlocks = new FilteredElementCollector(Document).OfCategory(BuiltInCategory.OST_TitleBlocks).OwnedByView(ViewSheet.Id);
Element elem = TitleBlocks.First();
Options opts = new Options();
opts.View = ViewSheet;

IList<Parameter> P1 = elem.GetParameters("TestParameter");
if (P1.Count > 0)
   P1[0].Set(100);

But everytime I get P1 as null.

 

TIA

0 Likes
Accepted solutions (1)
2,970 Views
10 Replies
Replies (10)
Message 2 of 11

thannaingoo.api
Advocate
Advocate

Hi

 

Below code is a reference for you.

 

IList<Element> elmt = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_TitleBlocks).ToElements();

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Set Parameter");

                    foreach(Parameter p in elmt[0].Parameters)
                    {
                        if(p.Definition.Name == "TestParameter")
                        {
                            p.Set(100);
                        }
                    }

                    tx.Commit();
                }
Message 3 of 11

Anonymous
Not applicable

@thannaingoo.api  Thank you for reply.

I have tried this method, but it never hit p.Set(100);

The total number of parameters for titleblock remains same even after adding custom parameter. 

May be I am missing some step while creating and attaching parameter to titleblock.

Need help on this.

 

Regards,
Gautam

0 Likes
Message 4 of 11

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

 

using filter try to find whether the parameter is present in the element or not?

 

How did you create your parameter? using API or UI?

If you created your parameter via API and want to assign value to your parameter then you have to use 2 separate transactions.

The first transaction is to create your parameter and the second transaction is to assign value to your parameter.

When your first transaction completes your parameter is created in the document and in the second transaction you can filter your parameter and assign value to it.

 

As you mentioned, "The total number of parameters for titleblock remains same even after adding custom parameter." I think that the parameter is not added to your project.

 

I hope this helps.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 11

thannaingoo.api
Advocate
Advocate

Hi, 

 

If you have "TestParameter" in title block, the code will work properly.

I already tested with my title block.

 

Thanks,

Naing Oo

 

WhatsApp Image 2019-06-26 at 5.07.08 PM.jpeg

 

 

 

0 Likes
Message 6 of 11

Anonymous
Not applicable

Hi @naveen.kumar.t 

Thank you for reply.

 

All process of adding label to titleblock, creating new custom parameter and assigning it to label, adding shared parameter into project information are done in UI (without API).

 

After my operation I am checking sheet and titleblock only to find added parameter present over there but unable to get it using API. 

Am I missing any step in UI while doing this?

0 Likes
Message 7 of 11

Anonymous
Not applicable

Hi @thannaingoo.api 

Thank you for reply.

 

The parameter you are adding applies to total sheet.

I wanted parameter value to be set on a particular label position on sheet as shown below. See below image.

 

Created own text and labels on upper right portion of sheet and wanted to display values of parameters over there (green arrow) with the help of APIs.

revitForum.PNG

 

Regards,

Gautam

0 Likes
Message 8 of 11

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

is your shared parameter is a type or an instance parameter?

//ACCESS INSTANCE SHARED PARAMETER
                foreach(Parameter p in e.Parameters)
                {
                    if(p.IsShared)
                    {
                       if(p.Definition.Name=="YOUR PARAMETER NAME")
                       {
                            p.Set("VALUE");
                       }
                    }
                 
                }

//ACCESS TYPE SHARED PARAMETER
                ElementType ET = doc.GetElement(e.GetTypeId()) as ElementType;
                foreach(Parameter P in ET.Parameters)
                {
                    if(P.IsShared)
                    {
                        if(P.Definition.Name=="YOUR PARAMETER NAME")
                        {
                            P.Set("VALUE");
                        }
                    }
                }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 9 of 11

Anonymous
Not applicable

Hi @naveen.kumar.t 

I am using Instance Shared Parameter


//ACCESS INSTANCE SHARED PARAMETER
                foreach(Parameter p in e.Parameters)
                {
                    if(p.IsShared)
                    {
                       if(p.Definition.Name=="YOUR PARAMETER NAME")
                       {
                            p.Set("VALUE");
                       }
                    }                
                }

I have tried this method suggested by you, but as mentioned earlier I am unable to find the parameter which was created by me.

I feel that I am missing a link between creating custom parameter and attaching it to title block to gain its access using API.

 

Regards,

Gautam

0 Likes
Message 10 of 11

Anonymous
Not applicable
Accepted solution

I found a solution which worked for me.

 

While setting a parameter to the newly added label, I was setting its 'Type of Parameter' as 'Volume' as I wanted to display volume on the sheet. It failed to update the value of volume.

I just changed its type to 'Text' and updated value using API and it worked well.

revitForum2.png

 

 

Thank you all for support.

 

0 Likes
Message 11 of 11

jsnowHJVYV
Contributor
Contributor
how could i make this where it applies to all title blocks
0 Likes