So, it wasn’t as easy as i thought it would be, but I was still able to do what you were asking for. Here it is:
First you need to import an image into a drafting view and to achieve it we need to call the method that I mentioned previously:
Document.Import(string, ImageImportOptions, View, Element)
Where:
String is a file path to the image.
ImageImportOptions is a class in Revit API that defines where and how we want to place our image.
View is a view that you want to place your import in.
Element is a new element class that Revit will use to store the newly created image in so that you can use that image element later.
Now, let’s have a detailed look at how we create a node like that:
File Path is simple enough because that node already exists.
ImageImportOptions would need to be created like so: ImageImportOptions() and there are three properties that we can set for that class: Placement, Ref Point and Resolution.
Placement can be set to either one of the outputs of BoxPlacement enumeration class and can be one of the following: Center, TopLeft, TopRight, BottomRight, BottomLeft. This basically sets what point in the image will be aligned with the Ref Point.
This gets us to the next property which is RefPoint. This is a point in a view that image will be placed at and has to be a XYZ() class. For that we can use just a Dynamo point and use a simple conversion function later.
Resolution is a resolution of the image in DPI and by default it will be set to 72 but can be changed with an integer input. Here are refpoint and resolution defined and new ImageImportOptions node:
This should define our import options for the image.
Next we need to obtain a View that we want to place our imported image in. You can use archi-lab’s node called Get All Views and then extract the one that interests you like so:
You can put that into our newly created Import Image node. We already defined inputs for it. That node will only execute the call that we talked about early in the post. Once its done, you should see a new image pop into your drafting view.
To reload it you would have to use the last bit of code that i provided here.