Different Document Objects?

Different Document Objects?

rhanzlick
Advocate Advocate
1,455 Views
4 Replies
Message 1 of 5

Different Document Objects?

rhanzlick
Advocate
Advocate

Does anyone know the difference between:

 

Autodesk.Revit.Creation.Document

and

Autodesk.Revit.DB.Document.Create()

 

Can I just cast the DB.Document into a Creation.Document?

0 Likes
Accepted solutions (1)
1,456 Views
4 Replies
Replies (4)
Message 2 of 5

paul.t.macknight
Advocate
Advocate

No. Within the API documentation:

 

Document under the Creation namespace is a class, with the description: "The Document Creation object is used to create new instances of elements within the Autodesk Revit project."

 

Create() under the Document class of the DB namespace is a property, with the description: "An object that can be used to create new instances of Autodesk Revit API elements within a project."

 

Base on this, Creation.Document is used for creating objects/elements within Revit itself, while DB.Document.Create() is used to create new instances of API objects (aka code elements, not model elements).

 

I could be mistaken, so you could always test it to see what errors, if any, you get.

0 Likes
Message 3 of 5

rhanzlick
Advocate
Advocate
Thanks for your response. I have always used DB.Document.Create() to create new FamilyInstances within the model without any errors. The api doc description is ambiguous as I interpret those two underlined things as the same. Is one of these deprecated or are they truly for different things?

How do I create an instance of Creation.Document? Is it a simple cast from DB.Document?
0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

A review of the return types provides the answer:

 

...DB.Document.Create is a property that returns a type of:

Autodesk.Revit.Creation.Document

 

...DB.Document.FamilyCreate is a property that returns a type of:

Autodesk.Revit.Creation.FamilyItemFactory

 

You need an instance of DB.Document to use otherwise what document are you creating the items in? Also the red class types above have no public constructor and they only have instance methods (so can't ordinarily be used directly with CLR language).

 

i.e. most things in Autodesk.Revit.Creation are objects found elsewhere. Most of the objects in  Autodesk.Revit.Creation.Application now have constructors on the classes e.g. Color. I don't think there is much in there you can't obtain in a more straightforward way.

0 Likes
Message 5 of 5

rhanzlick
Advocate
Advocate

Thanks very much for your response! Upon further searches, I also found this older response, which alludes to the fact that most things in the Creation Namespace are unofficially deprecated:

 

https://forums.autodesk.com/t5/revit-api-forum/how-to-use-autodesk-revit-creation-namespace-space-cr...

0 Likes