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: 

Extensible Storage

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
reylorente1
686 Views, 4 Replies

Extensible Storage

Hola
Quiero crear un Extensible Storage a partir de xml, estoy usando el ejemplo del Revit SDK 2021,pero no se como continuar, aquí esta mi xml

 

 Hi I want to create an Extensible Storage from xml, I am using the example from Revit SDK 2021, but I don't know how to continue, here is my xml

 

<?xml versión="1.0" encoding="UTF-8" ?>
<longitudequivalente>
     <Diametro valor = "15">
           <M_Codo_45>0.25</M_Codo_45>
           <M_Codo_90>0.46</M_Codo_90>
           <M_Te_angulo>1.01</M_Te_angulo>
            <M_Te_recta>0.34</M_Te_recta>
            <M_Reducer>0.18</M_Reducer>
            <Valve_Angle>2.6</Valve_Angle>
            <Ball_Valve>0.11</Ball_Valve>
           <CheckValve>1.63</CheckValve>
           <FootValve>3.59</FootValve>
            </Diámetro>
    <Diámetro valor = "20">
       <M_Codo_45>0.31</M_Codo_45>
       <M_Codo_90>0.64</M_Codo_90>
      <M_Te_angulo>1.37</M_Te_angulo>
      <M_Te_recta>0.4</M_Te_recta>
      <M_Reducer>0.24</M_Reducer>
      <Valve_Angle>3.66</Valve_Angle>
      <Ball_Valve>0.15</Ball_Valve>
      <CheckValve>2.43</CheckValve>
      <FootValve>5.19</FootValve>
    </Diámetro>

<longitudequivalente>

4 REPLIES 4
Message 2 of 5
joshua.lumley
in reply to: reylorente1

You do it via serialisation, and you'll need to write code to convert it into a schema structure (an entity) that is in turn stored in an element. 
I would start with the simpliest possible example, like a text string that says "Hello World."

Message 3 of 5
reylorente1
in reply to: joshua.lumley

 

 Hello,

I must convert xml to object, to do the serialisation? since I found this code in https://spiderinnet.typepad.com/

 

prívate const string SingleStringFiledName = "Almacen_Piezas_Hidraulicas";


        public static void SetDataToElement(string id, object o, Element e)
        {
            SchemaBuilder sb = new SchemaBuilder(new Guid(id));
            sb.SetSchemaName(id.Replace("-", ""));
            FieldBuilder fb = sb.AddSimpleField(SingleStringFiledName, typeof(string));

            XmlSerializer xml = new XmlSerializer(o.GetType());
            using (StringWriter w = new StringWriter())
            {
                XmlSerializer(w, o);

                Entity ent = new Entity(sb.Finish());
                ent.Set<string>(SingleStringFiledName, w.ToString());
                e.SetEntity(ent);
            }
        }

 

Message 4 of 5
joshua.lumley
in reply to: reylorente1

 

 Stream stream = new FileStream(string_Default_GuidToAlias, FileMode.Create, FileAccess.Write);
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<Guid, string>));
serializer.WriteObject(stream, dict_GuidToAlias); stream.Close();

 

I use System.Runtime.Serialization. 

Message 5 of 5
reylorente1
in reply to: joshua.lumley

Thank you!!

Gracias!!

Спасибо!!

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

Post to forums  

Forma Design Contest


Rail Community