0

I am looking for a way to save in a list the instances of my class (ArduraRepresentacion) that have properties and a constructor.

public class ArmaduraRepresentacion
    {
        Document doc;
        View vistaBarra;
        Rebar barraRefuerzo;
        List<CurveElement> listaCurvas;
        List<TextNote> listaTextos;
        XYZ posicion;
        List<Int32> listaCurvasId = new List<int>();
        List<Int32> listaTextosId = new List<int>();

        public ArmaduraRepresentacion(Document doc, View vista, Rebar barra)
        {
            this.doc = doc;            
            this.vistaBarra = vista;
            this.barraRefuerzo = barra;
        }

        public List<Int32> ListaCurvasId
        {
            get { return listaCurvasId; }

            set { this.listaCurvasId = value; }
        }
    }

I read about extensible storage and also about data storage that is provided by the Revit API. One of the limitations that can be observed is the types of data that can be stored.

I'm looking into serialization in binary, Json and in XML. But I have some concerns because I make references to RevitAPI classes and I don't think they are serializable.

My doubts is: The correct approach would be to create an entity for each property of my class and save it in a revit object?

Any help is welcome no matter how small.

I tried to use the Newtonsoft.json library to serialize my class instances but revit crashes, this crash is not a revit problem.

4
  • To serialize and deserialize the Revit XYZ class with Json.NET, see Deserialize Json XYZ Point. Commented Feb 20, 2023 at 19:34
  • That being said, do not use BinaryFormatter. It is being obsoleted and removed. And for another reason not to use BinaryFormatter see this answer by Matt to Deserialize Revit API. If you want to go with binary consider protobuf-net. Commented Feb 20, 2023 at 19:36
  • This question may be off-topic for Stack Overflow as asked. Firstly, opinion-based question like What is the best approach I can take to save my class objects? are generally off-topic. Secondly, you are asking three separate questions but the format for questions on stack overflow is one question per post. Try to break your post down into discrete answerable questions as defined by the help center. Commented Feb 20, 2023 at 19:42
  • Thanks @dbc for your help. I'm will go to divide the post into several specific questions. Commented Feb 20, 2023 at 20:44

1 Answer 1

0

You say, you have some concerns because of references to Revit API classes and you don't think they are serializable.

Well, true, the classes per se are not serrializable. However, that is probably not your meaning or intention at all. Presumably, if you wish to persist something in the Revit BIM and maintain references to other BIM objects, the referenced objects will be Revit Element instances. All Revit BIM objects are Element instances.

Element instances can be references within the model using their ElementId. Extensible storage provides support for serialising ElementId, and even support for automatically updating references and relationships established using them, cf. Handling of ElementId Data in EStorage.

I would certainly encourage you to use extensible storage, and simply store the member data you require to reconstruct your ArmaduraRepresentacion instance.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks jeremy for guiding. I re-read all possible posts and found the answer by applying Victor Chekalin's effortless extensible storage.
A personal question is: The best way to store a Dictionary<ElementId,ElementId> is in the ProjectInformation element or in an instance of the DataStorage class? This item is not related to any element in the project, I think someone on the development team recommended that you stop using singleton instances. Cheers
Definitely in your own DataStorage element. Definitely not in ProjectInfo. They did not recommend avoiding singleton instances. That is a very valid and useful and often appropriate pattern. They did recommend not using ProjectInfo: thebuildingcoder.typepad.com/blog/2015/02/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.