Get File Path for Raster Image

Get File Path for Raster Image

Anonymous
Not applicable
3,484 Views
12 Replies
Message 1 of 13

Get File Path for Raster Image

Anonymous
Not applicable

I am trying to get the filepath for an inserted image.

Looks like RASTER_SYMBOL_FILENAME builtinparameter holds the value (see revit loop up below).

But I am not being able to get the value. 

I am using the RevitPythonShell and Revit 2015. Below is the code I tried.

 

Questions:

- Is get_Parameter still the proper way to get the BIP value?

Found this method being used in several examples, including here, although it's an old post I think I remember seeing a deprecation msg about this method. I tried .looking for it using Parameter and iterating through GetParameters as as well.

- Is RASTER_SYMBOL_FILENAME what I should be looking for when trying to find the original img filepath?

 

Thanks you in advance

 

 

IronPython 2.7.3 (2.7.0.40) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> img = selection[0]
>>> img.Category.Name
'Raster Images'
>>> BIP = BuiltInParameter.RASTER_SYMBOL_FILENAME
>>> fname = img.get_Parameter(BIP)
>>> fname
>>> print(fname)
None
>>> fname = img.Parameter(BIP)
Traceback (most recent call last):
  File "<stdin>", line 1in <module>
TypeError: indexer# is not callable

 

 

 2016-08-23 13_23_09-NxDock.png

0 Likes
Accepted solutions (1)
3,485 Views
12 Replies
Replies (12)
Message 2 of 13

jeremytammik
Autodesk
Autodesk

Maybe the parameter has not been set and really is null.

 

You can check that using RevitLookup as well.

 

Also, some parameter values cannot be retrieved, because they have more complex values that do not fit into the valid parameter data type list of integer, double, string or element id.

 

Cheers,

 

Jeremy



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

0 Likes
Message 3 of 13

Anonymous
Not applicable
Hi Jeremy
I did use revit look up, and the value I am looking for is present, and stored as a string.
(see previously attached image, bottom right quadrant)
0 Likes
Message 4 of 13

jeremytammik
Autodesk
Autodesk

Very weird... almost cannot be... maybe some Python weirdness... sorry, I have no idea. 

 

I would suggest you create a reproducible case for this:

 

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

 

Cheers,

 

Jeremy



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

0 Likes
Message 5 of 13

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

may it be that you try to get the parameter from the image instance ?

Obviously it is a type parameter, which is attached to the image's ImageType.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 13

Anonymous
Not applicable

You were spot on. Thank you so much @Revitalizer

Here here is a dumb follow up question. I am just starting to get learn the api.

What's the best/most direct method for getting the type of an instance?

I used the GetValidTypes, and it worked. Then I tried just the GetType, and get parameter methods were not available.

 

Thanks in advance.

 

IronPython 2.7.3 (2.7.0.40) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> img = selection[0]
>>> img.GetValidTypes()
List[ElementId]([<Autodesk.Revit.DB.ElementId object at 0x000000000000002D [245115]>])
>>> for img_type in img.GetValidTypes():
...  print img_type
245115
>>> t = doc.GetElement(img_type)
<Autodesk.Revit.DB.ImageType object at 0x000000000000002E [Autodesk.Revit.DB.ImageType]>
>>> t.Category.Name
'Raster Images'
>>> img.Category.Name
'Raster Images'
>>> t.get_Parameter(BuiltInParameter.RASTER_SYMBOL_FILENAME)
<Autodesk.Revit.DB.Parameter object at 0x000000000000002F [Autodesk.Revit.DB.Parameter]>
>>> p.AsString()
'C:\\Users\\gtalarico\\Pictures\\Solid.jpg'  <<< UHUUU!
>>> img = selection[0]
[Autodesk.Revit.DB.Element]>
>>> img_type = img.GetType()
>>> img_type.FullName
'Autodesk.Revit.DB.Element'
>>> img_type.get_Parameter(BuiltInParameter.RASTER_SYMBOL_FILENAME)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'RuntimeType' object has no attribute 'get_Parameter'
>>> 
0 Likes
Message 7 of 13

jeremytammik
Autodesk
Autodesk
Message 8 of 13

Anonymous
Not applicable
Thanks!

So what is GetType() actually returning of not the Element type?
0 Likes
Message 9 of 13

Anonymous
Not applicable
Ps:
Here is the tool I'm working on
It's an image cropper!
https://www.dropbox.com/s/hb9zdm82kxx11pm/2016-08-26%2019-29-21.flv?dl=0
0 Likes
Message 10 of 13

jeremytammik
Autodesk
Autodesk

GetType has nothing to do with Revit.

 

It is part of the .NET framework, on the base Object class, and cannot be eliminated:

 

https://msdn.microsoft.com/en-us/library/system.object.gettype%28v=vs.110%29.aspx

 

Cheers,

 

Jeremy

 

 



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

Message 11 of 13

Anonymous
Not applicable

Many thanks @jeremytammik . That makes perfect sense now.

I am coming from python and I am just getting started with .net. I have a long way to go! Smiley Indifferent

 

Here is demo of the final thing working. It's an image cropper for embeded revit images

https://vimeo.com/180429233?ref=tw-share

 

0 Likes
Message 12 of 13

michellem
Advocate
Advocate

Hello;

 

I have tried gui.talarico image cropper on a image that I copy/pasted from the architect's Revit file into our Revit file. Unfortunately, it failed with an error about "path not found". I check the image type and found that the path points to the architect's path for the image. And I do not have access to the original file. Is there a way to save the pasted image - via the API or the user interface - onto my hard drive?

 

I have tried to copy/paste the image from the Revit file into a Word document but that fails also. I think the reason might be that Revit copies onto the clipboard a Revit Image Object and not a generic Image Object.

 

Sincerely;

Michelle

Message 13 of 13

Revitalizer
Advisor
Advisor

Hi,

 

if your ElementType is an ImageType,

what about "imageType.GetImage()"?

It returns a Bitmap object which in turn could be saved locally.

 




Rudolf Honke
Software Developer
Mensch und Maschine