Instantiate the ConverterRevit

Hi, I am looking for a way to instantiate and use the ConverterRevit on my own (without the connector). Right now I am getting some null reference exceptions from it. Probably because I am not initializing it correctly?

I wish it was that easy

 var collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns);
 var columns = collector.ToElements();
 var converter = new ConverterRevit();
 var speckleObjects = converter.ConvertToSpeckle(columns);

What am I missing here?

1 Like

Hey there, sorry you’re having some trouble with this. We’re chatting internally but can you post a call sack in the meantime and show us the NRE you’re experiencing?

Cheers
Ian H

Thanks Ian :slight_smile:

1 Like

Thanks, can you post the exception detail as well and confirm which thing appears to be null?

Cheers
Ian H

Just to follow up, we are actually pretty confident we know the issue and we are investigating a solution for you :slight_smile:

1 Like

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Objects.Converter.Revit2023
StackTrace:
at Objects.Converter.Revit.ConverterRevit.ParameterToSpeckle(Parameter rp, String paramInternalName, Boolean isTypeParameter, String unitsOverride)
at Objects.Converter.Revit.ConverterRevit.AddElementParamsToDict(Element element, Dictionary2 paramDict, Boolean isTypeParameter, List1 exclusions)
at Objects.Converter.Revit.ConverterRevit.GetAllRevitParamsAndIds(Base speckleElement, Element revitElement, List`1 exclusions)
at Objects.Converter.Revit.ConverterRevit.ElementTypeToSpeckle(ElementType revitType)
at Objects.Converter.Revit.ConverterRevit.ConvertToSpeckle(Object object)
at Ark.Revit.Core.Main(IDesignAutomationData data) in C:\Dev\ark\Ark.Revit\Core.cs:line 54

1 Like

Thanks, we have some guidance to follow… gives us a few… :slight_smile:

1 Like

Hi @vwb! Nice to have you around hacking!

The initialisation of the RevitConverter is a bit odd, as it has some hidden gotchas.

I think what you’re finding is that ParameterToSpeckle is trying to use the revitDocumentAggregateCache but this needs to be initialised on your side. Just like we’re doing here speckle-sharp/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit.Send.cs at e28f84e62b3582a135fbd292207ebdc6a9f4088e · specklesystems/speckle-sharp · GitHub

Most of these classes live in the RevitSharedResources20XX nuget packages, so you may want to add that to your project with the right version for your Revit target.

If you look at the SetDocumentContext implementation, it will expect multiple inputs specially important on send is the RevitDocumentAggregateCache, for receive you may need to set some extra ones.

Just did a quick search of how we’re using this on send/receive, I suggest you mimic this on your side.
Screenshot 2024-06-08 at 11.35.18

Screenshot 2024-06-08 at 11.35.25

Hope this helps!

EDIT:

@oguzhankoral just picked up that the interface for the aggregate cache does live in the shared resources, but that the specific implementation is actually in the connector, you may want to copy that over to your project speckle-sharp/ConnectorRevit/ConnectorRevit/Storage/RevitDocumentAggregateCache.cs at e28f84e62b3582a135fbd292207ebdc6a9f4088e · specklesystems/speckle-sharp · GitHub

3 Likes