Skip to content

Commit 5b67c7d

Browse files
anderslanglandsld-kerley
authored andcommitted
do Value: replacement on all attributes on all ports
1 parent eb6e338 commit 5b67c7d

File tree

1 file changed

+17
-19
lines changed
  • source/MaterialXBuildTools/buildLibrary

1 file changed

+17
-19
lines changed

source/MaterialXBuildTools/buildLibrary/Main.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,26 @@ void replaceNamedValues(mx::DocumentPtr doc, mx::ConstDocumentPtr stdlib)
6767
continue;
6868
}
6969

70-
if (!port->hasValueString())
71-
{
72-
continue;
73-
}
74-
75-
auto valueStr = port->getValueString();
76-
if (mx::stringStartsWith(valueStr, typeValuePrefix))
77-
{
70+
mx::StringVec const& attributeNames = port->getAttributeNames();
71+
for (std::string const& attrName: attributeNames) {
72+
std::string const& valueStr = port->getAttribute(attrName);
7873

79-
auto typeDef = stdlib->getTypeDef(port->getType());
80-
if (!typeDef)
74+
if (mx::stringStartsWith(valueStr, typeValuePrefix))
8175
{
82-
throw mx::Exception("Unable to find typeDef '"+port->getType()+"'");
76+
auto typeDef = stdlib->getTypeDef(port->getType());
77+
if (!typeDef)
78+
{
79+
throw mx::Exception("Unable to find typeDef '"+port->getType()+"'");
80+
}
81+
82+
auto valueNameStr = valueStr.substr(typeValuePrefix.size());
83+
if (!typeDef->hasAttribute(valueNameStr))
84+
{
85+
throw mx::Exception("Unable to find named value '"+valueNameStr+"' for type '"+typeDef->getName()+"'");
86+
}
87+
88+
port->setAttribute(attrName, typeDef->getAttribute(valueNameStr));
8389
}
84-
85-
auto valueNameStr = valueStr.substr(typeValuePrefix.size());
86-
if (!typeDef->hasAttribute(valueNameStr))
87-
{
88-
throw mx::Exception("Unable to find named value '"+valueNameStr+"' for type '"+typeDef->getName()+"'");
89-
}
90-
91-
port->setValueString(typeDef->getAttribute(valueNameStr));
9290
}
9391
}
9492
}

0 commit comments

Comments
 (0)