So i’m setting some data via SetUserString() on a brep edge that is then saved to a 3dm file like so
sorry for the formatting, i can’t figure out your forum’s codeblock syntax
ONX_Model model;
ON_TextLog errorLog;
const int version = 60; // write 6.0 compatible
model.m_properties.m_Application.m_application_name = "engine";
model.m_properties.m_Application.m_application_URL = "";
model.m_properties.m_Application.m_application_details = "";
model.AddDefaultLayer(L"brep", ON_Color::UnsetColor);
for(const auto &brep : breps)
{
ON_3dmObjectAttributes attributes;
attributes.m_name = "brep";
brep->preserveEdgeUUIDs(); //calls setCustomId
model.AddModelGeometryComponent(brep->get(), &attributes, true);
model.m_sStartSectionComments = "";
}
ok = model.Write(filename.c_str(), version, &errorLog);
—-
and loading it like so
if(model.Read(filename.c_str(), &errorLog))
{
ONX_ModelComponentIterator it(model, ON_ModelComponent::Type::ModelGeometry);
const ON_ModelComponent *mc = nullptr;
auto &renderer = Graphics::Core::Renderer::current();
auto transferCommands = renderer.getFrameTransferCommandList();
Graphics::Core::PipelineState defaultState;
defaultState.setDefault();
auto solidPipeline = renderer.getPipeline(Graphics::Core::Renderer::ShaderType::PBR_BASIC_SS_TRIM_GBUFFER, &defaultState);
auto material = BasicPBRMaterial::createDefaultMaterial(solidPipeline, transferCommands);
for(mc = it.FirstComponent(); mc; mc = it.NextComponent())
{
if(auto geometry = ON_ModelGeometryComponent::Cast(mc))
{
if(auto fileBrep = ON_Brep::Cast(geometry->Geometry(nullptr)))
{
for(int ei = 0; ei < fileBrep->m_E.Count(); ei++)
{
auto edge = fileBrep->Edge(ei);
if(auto id = Utils::ON::getCustomId(edge, L"source-uuid"))
{
logger << "got one! " << id->toString() << endl;
}
}
//….
where
template
std::optional<Utils::UUID> getCustomId(const P &obj, const wchar_t \*key)
{
ON_wString onStr;
if(obj->GetUserString(key, onStr))
{
return Utils::UUID(std::wstring(onStr.Array()));
}
return std::nullopt;
}
template
void setCustomId(P &obj, const wchar_t \*key, const Utils::UUID &id)
{
std::wstring uuidStr = id.toString<wchar_t>();
obj->SetUserString(key, uuidStr.c_str());
}
I’ve been able to confirm via breakpoints that the archive write method and read methods for the user string lists are being called, but for some reason no matter what I try, I simply cannot get the user string back from the 3dm file.