Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Given a material Element, how can I obtain it's "Image" map (ie. chestnut_natural.png for Wood - Floorng)?
Thanks
Solved! Go to Solution.
Given a material Element, how can I obtain it's "Image" map (ie. chestnut_natural.png for Wood - Floorng)?
Thanks
Solved! Go to 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.
Hi joe.ye,
if we cannot get the image file path at all, this question shouldn't be marked as *solved*...
Best regards,
Revitalizer
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.
Its been nearly 3 years since this post. Have we gotten this yet?
Good question.
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
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