Exporting Revit 2017 model materials using a CustomExporter and IExportContext

Anonymous

Exporting Revit 2017 model materials using a CustomExporter and IExportContext

Anonymous
Not applicable

We are attempting to utilize a CustomExporter and IExportContext to pull the geometry and materials from a Revit 2017 model. We seem to be having solid success at retrieving the  geometry from the various "OnElement...", "OnMaterial..", and "OnPolyMesh" methods. However, we have not figured out where to look for the materials.

 

We are looking to utilize the geometry and materials to perform a custom 3d view in an external product. Just to make sure that I am using the correct terminology, we have the geometry to display the model, but do not have the information from the model that would allow us to display the geometry with the color and/or graphics that would  be needed to display their surfaces correctly in a rendering. I am using the term "material" to describe that graphical information that  would be needed to add to the geometry in order to render the model.

 

I am looking for:

1 - Suggestions on where we can look for the above information from our Revit2017 AddIn

2 - Any examples if this type off an export... I thought  I saw an example that Jeremy (Tammik) had done a couple weeks ago that exported a Revit model to a web viewing 3d format that looked like it included the information that I am looking for, but I can't seem to find it now.

3 - Detailed documentation on CustomExporter and IExportContext.

 

Thanks much for any assistance or direction you can provide.

 

Regards,

Eric

0 Likes
Reply
3,221 Views
10 Replies
Replies (10)

jeremytammik
Autodesk
Autodesk

Dear Eric,

 

Maybe this is the post that you are thinking of?

 

http://thebuildingcoder.typepad.com/blog/2013/07/revit-2014-obj-exporter-and-new-sdk-samples.html#2

 

http://thebuildingcoder.typepad.com/blog/2012/07/obj-model-exporter-with-colours.html

 

Here is some more on the thorny issue of accessing bitmaps and UV coordinates:

 

http://thebuildingcoder.typepad.com/blog/2013/07/texture-bitmap-and-uv-coordinates.html

 

Material assignment in Revit is complex in itself:

 

http://thebuildingcoder.typepad.com/blog/2013/08/attributes-relationships-and-other-stuff.html#6

 

A couple of The Building Coder topic groups collect some discussions on the topic:

 

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

 

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

 

http://thebuildingcoder.typepad.com/blog/material/

 

All that I know about the custom exporter is also listed there:

 

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

 

I hope this helps.

 

Please let us know how you get on with this, and what solution you end up with.

 

Thank you!

 

Cheers,

 

Jeremy



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

Anonymous
Not applicable

Hi Jeremy,

 

Thank you for your response. I have been going through and reading each of the articles that you have referenced. I am still searching for how to best get the graphic associated with the texture mapping (materials was the term I used in my initial post) from within our Revit AddIn. I have also done some research into how architects would likely set this value from within the Revit 2017 product. 

 

I believe that the property I am attempting to retrieve from the model is the "Image" file name that is set in the "Appearance" tab of the "Material Browser" from the "Edit Type" and "Edit Assembly" dialog boxes. Yes, that is quite a series of steps. Let me try to explain and I will send some screen shots as well.

 

Example:

1 - Open Revit 2017

2 - Create a standard wall (Basic Concrete will be fine)

3 - Select the "Edit Type" button from the properties windows

4 - From the "Type Properties" dialog, select the "Edit..." button next to the "Structure" field (screenshot1)

5 - From the "Edit Assembly" dialog, click on the "Material" field, and select the small "..." button within the field to bring up the "material Browser" dialog (screenshot2... "..." button circled in red)

6 - From the "Material Browser" dialog, click on the "Appearance" tab 

7 - From the "Appearance" tab, click on the file name directly below the "Image" field to bring up the "Select File" dialog to select a high resolution image to associate with the original wall that we inserted in step 2. Note that the file name does not look like a button, but responds like one when clicked on (screeshot3... "Appearance" tab and "file name" button circled in red)

 

I believe that what I am looking for is the file name (full path name would be even better) for the file that is shown. In my example and screen shots, the file name is "Finishes.Masonry Flooring.Terrazzo.Tan.1.jpg" and it is stored in the "Program Files (x86)\Common Files\Autodesk Shared\Materials\Textures\1\Mats\" folder. I believe that my Revit 2017 installation utilized all of the default folder locations. 

 

Any suggestions on how I could get access to the field that contains the file name? Or any other suggestions on how an architect would/should better select a texture or material graphic for rendering or detailed display of a Revit 2017 model?

 

Regards,

Eric

 

 

jeremytammik
Autodesk
Autodesk

Rudolf Honke aka @Revitalizer provided a workaround that might help:

 

http://thebuildingcoder.typepad.com/blog/2013/07/texture-bitmap-and-uv-coordinates.html#3

 

Cheers,

 

Jeremy



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

0 Likes

Anonymous
Not applicable

Hi Jeremy,

Thank u for your reply. Now same question confused me. How can I get texture bitmap. I have read you blog:

http://thebuildingcoder.typepad.com/blog/2013/07/texture-bitmap-and-uv-coordinates.html

that inspired me a lot.

But  I still have some questions.

0 Likes

Revitalizer
Advisor
Advisor

Hi,

 

I've lost the code for that approach, but

 

I remember that I used a Family in the shape of a box with an material parameter, residing in the center of a new project file.

I think I did that manually, creating the simple family and placing it into an empty project file.

 

Then for each material in the project file, I assigned it to the placed FamilyInstance's material Parameter, via API.

After this, I took a screenshot via Windows API.

I think this can now be replaced by document.Export overload which enables you to generate image files without that Windows API approach.

 

After all, the exported image files not only contain the material sample but also much white areas, so they need to be cropped.

The view is larger than the box.

 

Also think that a material is more than just a single texture bitmap.

There may be additional bump maps, opacity maps and so on, but the generated image just displays the resulting composite image, not the texture bitmap alone.

 

I really do not recommend such a workaround.

 

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes

Anonymous
Not applicable

Hi Revitalizer,

Thank you for your reply. In fact, in Jeremy's blog he mentioned " The Building Coder: Texture Bitmap and UV Coordinates it might be better to grab the screen image directly rather than passing it through the Document.ExportImage method". After read you reply, I really understand what Jeremy's mean and why you do not recommend this method. But I'm still curious about how to grab the screen image directly or get the path of texture bitmap. Anyway, thank you for your reply.

 

0 Likes

Revitalizer
Advisor
Advisor

Hi,

 

there may be another way to get the paths of the texture files.

 

Export your model to a DXF file.

In my case, I selected the DXF2018 format.

This DXF is a plain text file.

 

The material I'm looking for has the ID 96504.

 

You can find something like this in the DXF file:

 

[...]

AcDbMaterial
  1
RevitMaterialDefinition96504
 70
     1
 90
-1026186137
 71
     1
 91
-1026186137
  3
C:/Program Files (x86)/Common Files/Autodesk Shared/Materials/Textures/\1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png
 73
     1
 44

[...]

 

So you only need to correct the backslash-slash sequence /\ to get a valid file path.

It would be interesting if you can get also user defined image paths since this is a material which references Autodesk's common material library.

Also, if there is more than one image used in a material's definition (texture, opacity etc.), how to discern them...?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Revitalizer
Advisor
Advisor

Hi,

 

I've defined a new material and assigned a custom image file.

 

I got this:

 

[...]

AcDbMaterial
  1
RevitMaterialDefinition248403
 70
     1
 71
     1
  3
D:\Test.jpg
 73
     1
 44

[...]

 

Seems that you only need to read the line after the " 3" line.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Anonymous
Not applicable

Hi Revitalizer,

Thank you for your kind help. I'm sry to reply you so late for some reasons. Now I can get dxf file automaticly through Document.Export(String, String, ICollection<ElementId>, DXFExportOptions) method. And then I can use a python script to pick up the bitmap file path from dxf file.  Finally, I use Copy(filepath) to get what I want.

BTW, instead of reading the line after the " 3" line, finding the key word "BitmapFile filename" will be more accurate because there are many lines like "  3","   3","     3" etc. 

PS: it's correct even though you had more than one image texture.

 Young Wang

 

Anonymous
Not applicable

Hi wbq9224,

 

Could you explain more how do you export the dxf file using the method that you mentioned?

 

(Document.Export(String, String, ICollection<ElementId>, DXFExportOptions) method.)

0 Likes