The "fusion" post for coders

I saw this post by @john_pierson at LinkedIn (working with Revit documents in #DynamoBIM is.... a bit of a pain - LinkedIn), due to I have stopped using this forum, so I am not aware if it is posted somewhere here… sorry for that :slight_smile:
However, this post is one of those every coder should pay very serious attention towards!

I have to admit that this post was like the invention of fusion, not that it was a brand new invention, but John made me aware of using reflection to circumvent the limitations set by the dynamo team.

I use reflection for many things, but I have never combined it with the shielded classes we all need when using the Dynamo API for coding our solutions. But I only saw the first few lines of John’s code, and fusion took place … in a few seconds, I realized I could retire most of the types I made in Orchid due to not being able to use the shielded dynamo classes.

This is in my eyes one of the greatest posts and with the greatest impact in many years!

So my humble contribution to all coders is the attached class that can convert many of the things everyone needs. I’m just a little embarrassed that it was not me who saw this first … good job John :slight_smile:

remove .txt and implement it as pleased :slight_smile:
Converters.cs.txt (6.7 KB)

Subscript (01.07.2022), I have updated the converter file with more conversions :slight_smile:

11 Likes

:astonished: very nice erfajo! Thanks for building upon that example and sharing it. The document conversion was a frustration for a very long time and I too was glad to realize I could use reflection for it (it actually came up here). The code you shared is great and I’m sure it’s going to help a lot of people looking to convert between types (especially those annoying internal types).

Also, like you, I will be making sure to return the dynamo types wherever possible in the future. (No more Autodesk.Revit.DB.Document getting returned in rhythm).

8 Likes

Good to see you around!

:slight_smile:

3 Likes

@john_pierson,
My weekend did go totally bananas :slight_smile: I am refactoring all nodes initiating/returning “Document”, “FamilyDocument”, “Parameter”, “FamilyParameter”, and where else I can get a Dynamo type instead of having an Orchid type… It is a huge job to refactor. I am now in the testing phase :slight_smile:

However, I hope to release within very few days, so It might be a good idea for you to start deprecating your nodes dealing with casting forth and back to Orchid nodes.

I had on the other hand some challenges with nodes for Revit 2020, due to the missing “FamilyParameter”, so for Revit 2020 did I need to remain my Orchid “FamilyParameter” type, but with new nodes for all versions hereafter.
I have also made it doable to migrate, but they will exist until Revit 2024 is released, where I will deprecate nodes only for Revit 2020.

And as I mentioned on LinkedIN, I have opened all my types using the keyword “WrappedType”, so no need to use reflections on my nodes, and I will strongly recommend the DynamoTeam to do the same. Open up all classes so we don’t need to bypass it by using reflection!

Please be aware that Orchid types will be deprecated if possible!

public static Autodesk.Revit.DB.FamilyType FromOrchidType(Orchid.RevitFamily.FamilyType item)
{
    return item.WrappedType;
}

public static Orchid.RevitFamily.FamilyType ToOrchidType(Autodesk.Revit.DB.FamilyType item)
{
    return new Orchid.RevitFamily.FamilyType(item);
}
3 Likes

Very cool erfajo, I can work on getting that implemented on my side as well. Do you have a hint as to which version number you will assign to your DLLs? This would enable me to allow for compatibility for folks who might have an older version installed and I can target accordingly moving forward?

*Edit. I see you assign the same sub-version to all of your releases here, so I should be able to add a “minimum version” to my nodes, to facilitate the conversion if the user is on an older version. Also, if you think I should just target your newer versions and only account for Revit 2020, that is fine as well and I am cool with that too :slight_smile:

So I have an in-progress branch on Rhythm with what I am thinking will work. (Also, I used the converters you provided. Thanks so much for that)

1 Like

I will have to write it when I release… but my numbers are as described below
…major number is related to the dynamo version (2.12 = 212)
…minor number is a major version number for me (e.g. version 3)
…build number is a minor number for me (e.g version 1)
…revision is my build number and I use a function that counts the days since 01.01.2000 (8213 days today) and includes it automatically when I compile.

In other words I can only release once a day, and I am not sure when I am ready :slight_smile:
However, you should be able to just look at the last number, since that is a kind of universal number…

I am not sure how many nodes you have there relates to Orchid, but if it is not FamilyParameters, then dont anything :slight_smile:

2 Likes

Sounds good. The only nodes I needed to convert documents on were my collectors. So now I just watch for Revit.Application.Document instead. :slight_smile:

3 Likes

I managed to release 8214, and as promised…“Document”, “FamilyDocument”, “Parameter”, “FamilyParameter” have changed to the alike Dynamo type :slight_smile:

It is so nice that we can use reflection to circumvent the limitations for all the shielded classes :slight_smile:

3 Likes

I have released 8217 with even more wrapper classes changed to the alike dynamo type. The converter file is updated as well :slight_smile:

2 Likes

Try to se part 2 of options for coders using reflection :slight_smile:

Reflection post for coders (part 2)