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 store custom data in a revit file (.rvt, .rfa, .rte)?

10 REPLIES 10
Reply
Message 1 of 11
cristian.tudusciuc
2694 Views, 10 Replies

How to store custom data in a revit file (.rvt, .rfa, .rte)?

Hi everybody,

is there any way to store custom data in a revit file?
I am interested to save either a name/value list or simply a string of max 1024bytes.

A *shared parameter* file is not what I am looking for.

Thank you for any feedback.
Regards,
Cristian
10 REPLIES 10
Message 2 of 11

Here is a link to one of Jeremy Tammik's blog entries which may help:

http://thebuildingcoder.typepad.com/blog/2009/07/store-structured-data.html

Note: I recommend using XML serialization instead of Binary serialization.

Best of luck.
Message 3 of 11

Hi David,

thanks for your quick response. I read Jeremy's blog last night, as far as I could understand he is using shared parameters, using a file , const string _filename = "C:/tmp/SharedParams.txt";
to do what he is doing.

I want to avoid that...
Message 4 of 11

Actually, if I understand what you're trying to do, it's really not very difficult. XML serialize your data to a string and store that string in a parameter of type Text.

Am I missing something?
Message 5 of 11

That is exactly what I want to do. Though, I don't know how to programmatically create a parameter of type text.
And I don't know to which collection I should append it. (using Revit API, c# environment)
Message 6 of 11

Here's some code that may help at least get you started. It was written against the Family Editor API, but I would imagine it would be very similar in the Project Editor API:

Build up the data, and store it into a new parameter we'll create:

// Set up data to store into a parameter
System.Collections.Generic.List values;
values = new System.Collections.Generic.List();

values.Add("Value1");
values.Add("Value2");

// Convert the data to a string
System.Xml.Serialization.XmlSerializer XMLSerializer;

XMLSerializer = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.Generic.List));
System.IO.StringWriter stringWriter = new System.IO.StringWriter();

XMLSerializer.Serialize(stringWriter, values);
string sParamValue = stringWriter.ToString();


FamilyParameter oFamParam;
bool bIsInstance = true;

// The INVALID group will have the new family parameter created in the "Other" group.
oFamParam = commandData.Application.ActiveDocument.FamilyManager.AddParameter("New Parameter",
BuiltInParameterGroup.INVALID,
ParameterType.Text,
bIsInstance);

// Store the XML-serialized string value into the parameter we just created
commandData.Application.ActiveDocument.FamilyManager.Set(oFamParam, sParamValue);




Now get the data back out and put it into the collection again so we can use it as normal:


// Get the string value back and put the data into our data structure
XMLSerializer = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.Generic.List));

oFamParam = commandData.Application.ActiveDocument.FamilyManager.get_Parameter("New Parameter");

sParamValue = commandData.Application.ActiveDocument.FamilyManager.CurrentType.AsString(oFamParam);

System.IO.StringReader stringReader = new System.IO.StringReader(sParamValue);

values = (System.Collections.Generic.List)XMLSerializer.Deserialize(stringReader);


Best of luck,
Message 7 of 11

Thanks, I tested your code and it works.

Most of the research I did was focused on project api, where I still can't find a solution.
If you come across some code that works in a similar way as the family api works, i will appreciate if you paste it here.

Thank you again for your help.

Best,
Cristian
Message 8 of 11

I'm pretty sure you can create a parameter in the Project API, but it's been ages since I looked at that API.

Here's a bit from Jeremy's blog entry(http://thebuildingcoder.typepad.com/blog/2009/07/store-project-data.html, which has other links in it), which may help:


Question: Where can I store project-wide information in a Revit file, data which is not related to any specific individual element?

Answer: First of all, there is no need to separate the two issues of element-specific versus global data, because the only way to store application data in Revit is to use shared parameters on certain elements. Luckily, there is one object which occurs exactly once in the entire project and therefore constitutes a suitable repository for global document data, also known as a singleton object: the project information or ProjectInfo element. It can be retrieved using Revit 2009 filtering by searching for the "Project Information" category with the built-in category OST_ProjectInformation. This is discussed in the standard Revit programming introduction presentation and demonstrated by the labs 4-4-1 and 4-4-2 in the Revit API introduction labs.
Message 9 of 11

All I understand from there is how to create a Shared parameter. What I would need is to add a new Project parameter.

In his code things are well explained:

Document doc = app.ActiveDocument;
CategorySet catSet = app.Create.NewCategorySet();
catSet.Insert( doc.Settings.Categories.get_Item( BuiltInCategory.OST_ProjectInformation ) );
Binding binding = app.Create.NewInstanceBinding( catSet );
doc.ParameterBindings.Insert( docParamDefVisible, binding );

BUT the docParamDefVisible is created via shared DefinitionGroup
Message 10 of 11
bsyap
in reply to: cristian.tudusciuc

Hi,

 

I am using a Structural Modeling/Design application to model'design a simple building. And I am trying to save the content/data generated by the application into a revit file format (.rvt) using the Revit API.

As a result, Autodesk Revit Structure can be able to generate the same building i have modeled/designed.

Any idea of doing this?

 

Any would be greatly appreciated.

 

Regards,

bsyap

 

 

Message 11 of 11

Did you eventually have to use a shared parameter file?

Did you find another solution to create a project parameter using the Project Editor API?

I am looking for an answer to the same problem.

Thanks

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community