Revit c# export json

Revit c# export json

Anonymous
Not applicable
1,581 Views
1 Reply
Message 1 of 2

Revit c# export json

Anonymous
Not applicable

Hi all;

 

we are working on a plugin "revit system element database working with mongodb".

The  project working on visual studio c# and we convert the revit element object  directly to mongo we have a problem  on converting the object to json format the error  are blow. 

 

as an alternative we tried to insert the element object directly to mongodb  the  export data is like the picture below.

how can we overcome the export to json issue?

thanks in advance

 

 

[JsonObject(MemberSerialization.OptOut)]
[Serializable]
public class ElementDataEntity
{
[JsonProperty]
public int ElementDataEntityId { get; set; }

[JsonProperty]
public int ElementId { get; set; }

[JsonProperty]
public String element { get; set; }


}

 

 

public void Execute(UIApplication uiapp)
{

mongoDbConnection mongoDbConnection = new mongoDbConnection();

 

//get all data
List<ElementDataEntity> elementDataEntitys= mongoDbConnection.GetAllElement();

 

Document doc = uiapp.ActiveUIDocument.Document;
Selection sel = uiapp.ActiveUIDocument.Selection;


Transaction ts = new Transaction(doc, "");
ts.Start();

Element elemPick = null;
Reference refelem = sel.PickObject(ObjectType.Element);
elemPick = doc.GetElement(refelem.ElementId);

ElementDataEntity elementDataEntity = new ElementDataEntity();
elementDataEntity.element = Newtonsoft.Json.JsonConvert.SerializeObject(elemPick);
elementDataEntity.ElementId = refelem.ElementId.IntegerValue;
elementDataEntity.ElementDataEntityId =1;

//insert   revit element data 

mongoDbConnection.insertDataMongoDb(elementDataEntity);


}

 

error : Error getting value from 'WorksharingCentralGUID' on 'Autodesk.Revit.DB.Document'.

 

data.jpg

 

 

0 Likes
1,582 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

in addition insert mongodb function is

var collection = _mongoDatabaseConnection.GetCollection<ElementDataEntity>("entities");
await collection.InsertOneAsync(elementDataEntity);

0 Likes