Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding
Announcements
We are currently migrating data within this board to improve the community. During this process, posting, replying, editing and other features are temporarily disabled. We sincerely apologize for any inconvenience caused and appreciate your understanding. Thank you for your patience and support.

How to get an image file path for a material

pfk
Enthusiast Enthusiast
3,386 Views
8 Replies
Message 1 of 9

How to get an image file path for a material

pfk
Enthusiast
Enthusiast

Given a material Element, how can I obtain it's "Image" map (ie. chestnut_natural.png for Wood - Floorng)? 

 

ThanksRevit Materials.png

Reply
Reply
0 Likes
Accepted solutions (1)
3,387 Views
8 Replies
Replies (8)
Message 2 of 9

Joe.Ye
Alumni
Alumni
Accepted solution

 

Use the appearance asset retrieved from Material.RederAppearance property, we can get part of the property values for that material.


Here is the code snippet. (Written in VSTA)

 

<code>

         public void MaterialAppearanceProperties()
        {
            //
            Document doc = this.ActiveUIDocument.Document;
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.OfClass(typeof(Material));
            foreach(Element elem in collector)
            {
                if(elem.Name == "Wood - Flooring")
                //if(elem.Name == "Concrete - Cast-in-Place Concrete")                
                {
                    Material mat = elem as Material;
                    Asset set = mat.RenderAppearance;
                    
                    string props = null;
                    props = "Size = " + set.Size.ToString() + "\r\n";
                    props +"Title = " + set.Title + "\r\n";
                    props +"Lirary name = " + set.LibraryName + "\r\n";
                    props +"Asettype" + set.AssetType.ToString();
                    
                    
                    for(int i = 0; i < set.Size; i++)
                    {
                        AssetProperty property = set[i];
                        if(property is AssetPropertyString)
                        {
                            AssetPropertyString val = property as AssetPropertyString;
                            props += val.Name + "= " + val.Value.ToString() +"\r\n";
                        }
                        else if(property is AssetPropertyInteger)
                        {
                            AssetPropertyInteger val = property as AssetPropertyInteger;
                            props += val.Name + "= " + val.Value.ToString() +"\r\n";
                        }
                        else if(property is AssetPropertyEnum)
                        {
                            AssetPropertyEnum val = property as AssetPropertyEnum;
                            props += val.Name + "= " + val.Value.ToString() +"\r\n";
                        }    
                        else if(property is AssetPropertyDouble)
                        {
                            AssetPropertyDouble val = property as AssetPropertyDouble;
                            props += val.Name + "= " + val.Value.ToString() +"\r\n";
                        }
                        else if(property is AssetPropertyBoolean)
                        {
                            AssetPropertyBoolean val = property as AssetPropertyBoolean;
                            props += val.Name + "= " + val.Value.ToString() +"\r\n";
                        }                        
                        else if(property is AssetPropertyReference)
                        {
                            AssetPropertyReference val = property as AssetPropertyReference;
                            AssetProperty value = val.Value;
                            if(value is AssetPropertyString)
                            {
                                AssetPropertyString valueString = value as AssetPropertyString;
                                props += val.Name + "= " + valueString.Value.ToString() +" Reference \r\n";
                            }
                        }                            
                        else 
                        {
                            props += property.Name + property.ToString() +"Other Type " + "\r\n";
                        }
                                        
                    }
                    TaskDialog.Show("asdf",props);
                
                }            
            }
            
        }
             

<code>

 

However  we just cannot retrieve the file that is assigened to the material. Sorry for this. I will let the engineering team know this request.

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Reply
Reply
0 Likes
Message 3 of 9

Revitalizer
Advisor
Advisor

Hi joe.ye,

 

if we cannot get the image file path at all, this question shouldn't be marked as *solved*...

 

Best regards,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Reply
Reply
Message 4 of 9

Joe.Ye
Alumni
Alumni

 

HI Revitalizer,

 

Thanks for the input. 

Actually not all topics can have a workaround or workable solution. Solved mark here doesn't mean it can be achieved, but means there is a definite conclusion for this question. 

The solved mark reminds other viewers or community contributors there is a definite conclusion, maybe an API wish to engineering team, or just not possible. So they don't need to spend time to think about it again for solutions.

Thanks again for your great contribution to the Revit API board.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Reply
Reply
0 Likes
Message 5 of 9

Anonymous
Not applicable

Its been nearly 3 years since this post.  Have we gotten this yet?

Reply
Reply
0 Likes
Message 6 of 9

Dale.Bartlett
Collaborator
Collaborator

Good question.




______________
Yes, I'm Satoshi.
Reply
Reply
0 Likes
Message 7 of 9

Revitalizer
Advisor
Advisor

Hi Michael,

 

as far as I can see, there is still no such Material Library API.

So we still have an image file name but not the file path.

 

There may be a workaround, just an idea:

 

The file is stored using "Autodesk Material Library 201x".

One could browse the Windows Registry to get the related directories of this program.

Once found the paths, one could examine the readable files (*.txt, *xml, etc.) existing there, to gain further information.

Just searching for "sample.png", inside those files.

I don't believe that a "sample.png" file can be found directly since there may be some sort of mapping, e.g. it may be saved as "previews/12345.png".

Perhaps this mapping information can be found out.

 

Just a guess.

Perhaps somebody may pick up this idea and spend some time to try it out...

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Reply
Reply
0 Likes
Message 8 of 9

pfk
Enthusiast
Enthusiast
...or Autodesk could add this into the API!
Reply
Reply
Message 9 of 9

arnostlobel
Alumni
Alumni

I agree that it should be Autodesk to provide a meaningful and useful API for materials. That's for sure. However, it cannot be the Revit R&D group to do so because they simply to not know what the material library does. We (Revit programmers) do not have any API to it either. We just invoke material dialog (which comes with the library) when the end-user asks for it, and later during rendering (for example) we hand over the chosen material Id to the rendering engine which communicates with the material library directly (by some means). I am not writing this as an excuse - it is simply the way it is (and very unfortunately the way it has been for long). We are extremely aware of the need for a material API - we would like to have it ourselves too. All I can promise is that I will again channel this request up to the Autodesk teams maintaining the library.

 

Thanks for understanding

Arnošt Löbel
Reply
Reply