Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Raster Image

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
drdanielfc
4222 Views, 24 Replies

Insert Raster Image

How could I insert a Raster Image using the Revit API? In other words, the equivalent of doing Insert>Image

24 REPLIES 24
Message 2 of 25
jeremytammik
in reply to: drdanielfc

Install RevitLookup. Explore the Revit database. Insert an image manually. Check what changed. That tells you what elements were added. Then you can look in the Revit API help file RevitAPI.chm to see how to add such elements programmatically. If you do not have RevitLookup and RevitAPI.chm installed, work through the getting started material first of all, especially the My First Revit Plugin and DevTV tutorials.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 25
drdanielfc
in reply to: jeremytammik

RevitLookup is installed, I've gone thru the First Plugin tutorial, and have been writing plugins for about a month now. However, I can't seem to figure this one out. I've found the element in Revit lookup but the information doesn't seem particularly helpful. I also don't seem to be able to find anything relevent in the RevitAPI.chm file. I know how annoying it is when people don't seem to be willing to pull their weight on forums, but I just can't seem to find my way past the first hurdle of what function I would call to create an image. I should be able to figure everything else out thereafter.

 

Cheers

Message 4 of 25
Revitalizer
in reply to: drdanielfc

Dear drdanielfc,

just use:
document.Import Method (String, ImageImportOptions, View, out Element)

 
Best regards,
Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 25
dklasnic
in reply to: Revitalizer

How to insert embeded image into revit file ?

 

 

 

 

Message 6 of 25
Revitalizer
in reply to: dklasnic

Embedded ?

Embedded into what ?

 

If it is part of another Revit document, try copy/paste API.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 7 of 25
dklasnic
in reply to: Revitalizer

For example. I want add custom image on backgroud of the view. I want that i don't need image file
Message 8 of 25
Revitalizer
in reply to: dklasnic

Hi,

 

yourView.SetBackground(ViewDisplayBackground.CreateImage(string imagePath, etc.));

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 9 of 25
dklasnic
in reply to: Revitalizer

Thanks,
I know that . That is not what I want. I want that i don't need external source of image. Because, when I move .rtf file to another computer i also need to move the image file.

Message 10 of 25
Revitalizer
in reply to: dklasnic

Hi,

 

you should better have asked

"How to embed image into revit file ?"

instead of

"How to insert embeded image into revit file ?"

 

The answer is: no, you cannot embed an image, you just can reference it.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 11 of 25
dklasnic
in reply to: Revitalizer

Thanks 🙂
Message 12 of 25
dklasnic
in reply to: Revitalizer

Hi,

Is it possible to reference image from web location and how ?
Message 13 of 25
Revitalizer
in reply to: dklasnic

Hi,

 

here is an approach using AVF:

 

http://thebuildingcoder.typepad.com/blog/2010/06/grabbing-an-internet-webcam-image.html

http://thebuildingcoder.typepad.com/blog/2012/02/revit-webcam-2012.html

 

Using not the view depending analysis visualization framework but persistent image elements:

Once grabbed and stored the image, you can update an existing ImageType by its Reload() methods.

 

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 14 of 25
dklasnic
in reply to: Revitalizer

Hi,

 

is it Possible do something like that.

 

   String PATH_FILE = "http://net.dd/image.png";

   dispBackground = ViewDisplayBackground.CreateImage(PATH_FILE, ViewDisplayBackgroundImageFlags.UseTiling, UV.Zero, UV.Zero);

 

I tried. Got file not found exception.

 

 

Message 15 of 25
Revitalizer
in reply to: dklasnic

Hi,

 

obviously, you answered your question by yourself.

You cannot.

 

RevitAPI.chm says:

"Autodesk.Revit.Exceptions.FileArgumentNotFoundException: The file specified by imagePath doesn't exist. "

 

It seems that Revit needs a valid local file path but not a web URL.

That is understandable:

A web url would be an external resource that would need to be watched by Revit, since it could be temporarily unavailable, could change its content, etc.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 16 of 25
dklasnic
in reply to: Revitalizer

Ok Thanks 🙂
Message 17 of 25
yann.h
in reply to: drdanielfc

Hi !

Nice ! Thanks ! It helped me !

The function "ducument.import(PathToFile, ImageOptins, view, out Element)" is really usefull !

To go further, is it possible to use "out Element" as a raster image ?
Is it possible to get something like "Element.width = ChosenWidth;" ?

Message 18 of 25
sobon.konrad
in reply to: Revitalizer

Revitalizer,

 

Would a nasty workaround like this possibly work: you could store the image inside of view as extensible storage (byte stream?) and then in case that file was moved from its original location write a new image to a relative location (from byte stream), so that ViewCreateBackground.CreateImage() method can be executed. Thoughts? 

 

-K

Message 19 of 25
drdanielfc
in reply to: sobon.konrad

I'm actually doing something similar in one of my add-ins. I store a base64 image string and write it to a temp file for loading. It works fine.

Message 20 of 25
jeremytammik
in reply to: sobon.konrad

Dear Konrad,

 

Yes, absolutely that would work!

 

In fact, I implemented and published a Revit plug-in that stores and retrieves arbitrary files to and from extensible storage:

 

https://github.com/jeremytammik/EstoreFile

 

You should also take a look at The Building Coder topic group on extensible storage:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23

 

I just expanded and completed it a little bit, just for this conversation here.

 

Cheers,

 

Jeremy.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community