Add Reference to Revit/Dynamo dll files through Visual Studio Professional/Community

Hi all!
I am relatively new to writing code, especially Python for Dynamo/Revit. Anyhow, for quite a while I was breaking my neck on how to add Revit/Dynamo dll files to the project in Visual Studio as the program seems to not allow me to add references through the “Add Reference” option of the project solution as there is no browser button to load them.

Loaded Dll's to the Object Browser

Yesterday I had a breakthrough in which I discovered that it is able to add references through the Object Browser (where I managed to add the dll files) and from there add them to the reference. Only that now when I try to Add Reference in the code or access the dll libraries - I am still receiving the following error (added below as it is pretty long).

Pic of error

I would like to add that it still doesn’t show me the Assemblies inside the Add Reference window (it may sound smart but have no idea if relevent :sweat_smile:)

Assemblies & Project Solution


File “”, line 1, in
IOError: System.IO.IOException: Could not add reference to assembly RevitNodes
at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object reference)
at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object references)
at Microsoft.Scripting.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.DynamicInstruction4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
at Microsoft.Scripting.Interpreter.FuncCallInstruction3.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.FuncCallInstruction6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Runtime.FunctionCaller1.Call1(CallSite site, CodeContext context, Object func, T0 arg0) at IronPython.Runtime.Method.MethodBinding.SelfTarget(CallSite site, CodeContext context, Object target) at Microsoft.Scripting.Interpreter.DynamicInstruction3.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

Hi,

I do my Python in the Python node and have only used VS for C#. The number of people using Python with VS on here will be very small.

I suspect that if you post to Stack or similar you will get better assistance.

That said, I’ll have a go, apologies if I am wrong!

In the Python node we load .dlls from a path…

import sys		
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')

I suspect you will do the same in VS. It is possible that VS has the functionality to bundle everything up and create relative paths for everything, but I haven’t seen that. Of course you could do that yourself manually.

I suspect it’s fundamentally about how Python works… I think Python expects that you have the relevant files installed and your .Py just points to them.

I found this link which seemed interesting Get Started Tutorial for Python in Visual Studio Code

Good luck, let us know how you get on :slight_smile:

Mark

I also have thought of the alternative of adding a path and I have tried to add the path to the file of “DynamoForRevit” which contains all the dynamo dlls (and I think also Revit). Thing is that I am new to this and not sure if I did it properly as it seems not to work :sweat_smile:
I saw a vid explaining that appending to the end of the sys.path list is less efficient than adding to the computer’s environment but it seems, as well not to work for me.
Hoping of course that maybe someone knows the issue or can give me a lead on how to apply it so it works!
Tnks Mark

Ok, never mind, as I said, perhaps post on Stack Exchange and let us know if they manage to help you?

Apologies,

Mark

Hi,

It was a bit of a complicated issue, but there are enough resources available to do that.
First of all, I think it is not possible to add “”.dll reference" to the python file with VS. Instead, the file is easy for you to do.

Download the file and store it in an appropriate location.

Exp:
We have to go to the settings first.


Then let’s change the file extension.

"python.pythonPath": "C:\\Program Files\\Python27\\python.exe",
"python.autoComplete.extraPaths": ["C:\\Path\\To\\ironpython-stubs\\release\\stubs.min"],

And a happy ending:


Durmus

1 Like

I think you are using Visual Studio Code and no Visual Studio Professional/Community

Try This:

View> Object Browser>Custom Component Set:
Then you can add any “.dll reference” you want.

That is what I did (you can see the pics of it in the top post).

Besides that, I broke and downloaded the VS Code and set up the path for autocomplete but it doesn’t recognize the “clr” when I put in the command “import.clr”. Any idea why?