@leonard.moelders you are not doing anything wrong, the mapping from .net to Python/IronPython is a bit confusing 
Bascially, clr.AddReference()
is supposed to make IronPython aware of the assembly, and import
imports the types into the Python scope. We do some imports and reference adding in the background, which adds a bit to the confusion.
We used to have autogenerated docs, but they never went beyond a single assembly so that was relatively useless. As per previous suggestions in this thread from @Michael_Kirschner2 we do like Fuget.org where you can search all of the Assemblies. Example below, covering a full case (and I know you know most of this already!).
Fuget Dynamo Revit Example:
Under the DynamoVisualProgramming.Revit nuget, you will find two Assemblies;
- RevitNodes.dll
- RevitServices.dll
In order to inform Python that these assemblies exist, you need to add a reference to them.
So, inside of Dynamo for Revit we will open up a Python node and add in this reference.
clr.AddReference('RevitNodes')
But if we use dir()
(Exploring the current directory), we will notice that nothing has ostensibly changed inside of the Python window. Because while Python knows about the reference, it’s yet to pull things in. You can check the references that are “known” by querying the clr, which now shows Revit.
So you can simply now import Revit
or from Revit import *
depending on your flavour choice to import the namespace into the Python scope. You can also import sub-elements of the Revit namespace such as from Revit.Elements import *
or from Revit.Transaction import *
import Revit
example:
from Revit.Elements import *
example:
Typically, getting granular is better as it has an impact on memory and execution time - so only import the things you need!
Fuget Dynamo Core Example:
Under the [DynamoVisualProgramming.Core nuget, you will find nine Assemblies;
- DesignScriptBuiltin.dll
- DSCpython.dll
- DynamoApplications.dll
- DynamoCore.dll
- DynamoInstallDetective.dll
- DynamoShapeManager.dll
- DynamoUtilities.dll
- ProtoCore.dll
- VMDataBridge.dll
Again, in order to inform Python that these assemblies exist, you need to add a reference to them.
So, inside of Dynamo for Revit we will open up a Python node and add in this reference.
clr.AddReference('DynamoCore')
Again, if we use dir()
(Exploring the current directory), we will notice that nothing has ostensibly changed inside of the Python window. Because while Python knows about the reference, it’s yet to pull things in. You can again check the references that are “known” by querying the clr, which now shows Dynamo (As well as other, pre-loaded assemblies like Autodesk).