Converting Received Base from GH to Revit element

Hi Speckle team

I’m sure this has been asked before but I could not find the answer.

I’m sending some DirectShapes from GH using the Speckle Objects kit:

Then trying to receive it using the Speckle API:

data = receive(objectId, transport)
#returns Base object from GH

# convert Speckle Base to Revit Geometry
kit = Kits.KitManager.GetDefaultKit()
converter = kit.LoadConverter(Objects.Converter.Revit.ConverterRevit.RevitAppName)
converter.SetContextDocument(doc)

directShape = converter.ConvertToNative(data)
#returns none

All works well, except that after using the ConvertToNative method I get None.

As a test, I tried receiving a geometry that I send straight from Revit using the same piece of code, and that actually works, implementing the necessary transactions.

Is there a missing step to convert Base objects received from Grasshopper to a Revit Object? Can you guys please point me to what I might be doing wrong?

A snippet of code, even if in C# would be extremelly helpful.
@AlanRynne

Thanks!

@jonathon @AlanRynne this issue still persists… even when I try to bring a DirectShape that has been sent from Revit itself, it doesn’t work:


Can anyone please help? Happy to provide more info if needed.

Hi @janx!

What’s the context you’re running this C# code in? Is this running inside Revit, and if so, how?

It would help if you would give us as much detail as possible of what you’re trying to achieve?

1 Like

Hi @AlanRynne. Sorry, I understand that I have explained myself quite poorly. Let me try again:

I am in the context of a Revit Plugin. Taking from this sample that you provided, I’ve created this piece of code:

var streamId = "51d8c73c9d"; //obviously using my own stream here
var branchName = "main";

var defaultAccount = AccountManager.GetDefaultAccount();

var client = new Client(defaultAccount);

var branch = client.BranchGet(streamId, "main", 1).Result;
var hash = branch.commits.items[0].referencedObject;

var transport = new ServerTransport(defaultAccount, streamId);
var receivedBase = Operations.Receive(hash, transport).Result;

At this point, I have a Speckle Base object in receivedBase , which is a DirectShape that is currently in the server (such as the one on the screenshot of the previous post).

Additionally, I load Object.Revit.Coverter2024.dll and create a converter:

var kit = Speckle.Core.Kits.KitManager.GetDefaultKit();
var converter = kit.LoadConverter(Objects.Converter.Revit.ConverterRevit.RevitAppName);
converter.SetContextDocument(doc); // doc is the Revit doc 

now, I try to convert the Base object to a Revit obj with the following code:

bool canConvert = converter.CanConvertToNative(receivedBase); // returns false
var converted = converter.ConvertToNative(receivedBase); // returns null

I am expecting a Revit DirectShape at this point, but I only get null from the converter. Am I missing something in between for the conversion??

I’m sure it’s something silly… please enlighten me with your Speckle wisdom as I’m desperate at this point! :pray:

Thanks!

1 Like

@AlanRynne In case it gives more hints:

Hi @janx , you’ll have to traverse the receivedBase first before converting the resulting objects: refer to our traversal docs for more info.

For traversal in Revit specifically, you can use our default revit traversal function DefaltTraversal.CreateRevitTraversalFunc(converter) which should return your DirectShape object :slight_smile:

1 Like

thank you for your answer @clrkng. I have a few following questions:

  • Was this concept added recently? I was able to use ConvertToNative as it was a couple of months ago without this

  • Since I’m only interested in getting the DirectShapes and their parameters, would flattening work in my case?

  • Could I ask you to please provide a small example of how CreateRevitTraversalFunc work in in the Revit context in order to get the DirectShape? :pray: I’m still learning about these concepts and can’t find any other reference anywhere. It would be super helpful :slight_smile:

thanks in advance!

my first attempt with CreateRevitTraversalFunc failed miserably :disappointed: :

ConvertToNative fails, in spite of CanConvertToNative resulting true.

Also tried isolating the DirectShape, same result:

is traversing the problem? or what else could be the issue? @clrkng @AlanRynne

Hmm your traversal implementation doesn’t seem to be the problem, there may be a few possible reasons for the exception including recent changes to our DirectShape conversion, needing to instance the converter properly, or a Settings variable not being instantiated or handled correctly on our end.

I can take a closer look on Monday after we get back from our company retreat, unless @AlanRynne gets around to it first!

1 Like

thanks @clrkng @AlanRynne for looking into this! Hope you enjoyed your company retreat :slight_smile:

I’m looking forward to your reply, as we’ve been stuck with this for quite a while now and our project is somewhat blocked at this point :sweat_smile:

If you need anything from me, please let me know I can provide it right away.

Ok, tl;dr is that the current workaround for receiving in Revit requires manual setting of the converter receive mode to create:

converter.SetContextDocument(doc);
converter.ReceiveMode = Speckle.Core.Kits.ReceiveMode.Create;

Unfortunately, there is no quick fix for accessing our default Update receive mode functionality, so if you’d like your received revit elements to replace existing ones in the document you’ll have to handle that behavior in your plugin after receiving.

We’ll also add some sample code for receiving in Revit that includes 1) traversal and 2) receive mode explanations @Pavol @ianh : feat(dotnet): adds sample traversal and conversion method by clairekuang · Pull Request #2 · specklesystems/speckle-examples · GitHub

Hopefully we’ll have more robust dx for our converter libraries soon, thanks as always for reporting issues!

2 Likes

Those sample codes will be most welcome :star_struck: Thanks @clrkng for all your help!

A post was split to a new topic: ConvertToNative() not returning a valid converted Revit object