Revit 2012 API provides extended storage extensible storage to attach data to revit files.
The data is appended to the object. For more information, see the projectinfo example attached to the project file. Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
UsingWinform=System. Windows. forms;
UsingAutodesk. revit. UI;
UsingAutodesk. revit. dB;
UsingAutodesk. revit. attributes;
UsingAutodesk. revit. DB. Mechanical;
UsingAutodesk. revit. UI. selection;
UsingAutodesk. revit. applicationservices;
UsingAutodesk. revit. DB. structure;
UsingAutodesk. revit. DB. extensiblestorage;
using system. XML;
namespace revitcodes
{< br> [transactionattribute (Autodesk. revit. attributes. transactionmode. manual)]
Public class External Store: iexternalcommand
{< br> Public result execute (externalcommanddata commanddata, ref string messages, elementset elements)
{
Uiapplication app=Commanddata. Application;
Document Doc=App. activeuidocument. Document;
Reference refwall = App. activeuidocument. selection. pickobject (objecttype. element, " Select a wall " );
Wall = Doc. getelement (refwall) As Wall;
XYZ = App. activeuidocument. selection. pickpoint ( " Select a vertex " );
Storedatainwall (wall, XYZ );
ReturnResult. succeeded;
}
Public VoidStoredatainwall (wall, XYZ datatostore)
{
Transaction createschemaandstoredata= NewTransaction (wall. Document,"Tcreateandstore");
Createschemaandstoredata. Start ();
Schemabuilder=
NewSchemabuilder (NewGUID ("720080cb-da99-40dc-9415-e53f280aa1f0"));
//Allow anyone to read the object
Schemabuilder. setreadaccesslevel (accesslevel. Public );
// restrict writing to this vendor only
schemabuilder. setwriteaccesslevel (accesslevel. vendor);
// required because of restricted write-access
schemabuilder. setvendorid ( " adsk " );
//Create a field to store an XYZ
Fieldbuilder=
Schemabuilder. addsimplefield ("Wiresplicelocation",Typeof(XYZ ));
Fieldbuilder. setunittype (unittype. ut_length );
Fieldbuilder. setdocumentation ("A stored Location Value representing a wiring splice in a wall.");
Schemabuilder. setschemaname ("Wiresplicelocation");
Schema=Schemabuilder. Finish ();//Register the schema object
//Create an entity (object) for this schema (class)
Entity entity= NewEntity (schema );
// get the field from the schema
Field fieldsplicelocation = schema. getfield ( " wiresplicelocation " );
entity. set XYZ > (fieldsplicelocation, datatostore, displayunittype. dut_meters); /// set the value for this entity
wall. setentity (entity); /// store the entity in the element
//Get the data back from the wall
Entity retrievedentity=Wall. getentity (schema );
XYZ retrieveddata=
Retrievedentity. Get<XYZ>(Schema. getfield ("Wiresplicelocation"), Displayunittype. dut_meters );
Createschemaandstoredata. Commit ();
}
}
}
From: http://revit.5d6d.com/thread-1289-1-1.html