Revit API extended storage extensible Storage

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.