Two different model space scale of text?

Hi. I’m trying to read text info from OpenNurbs. When I try to get the text height, I think I should do like this:
double textHeight = dimStyle.TextHeight() ;
But I got a wrong height value. After checking the model, I found that it’s the model space scale that affects the text scale.
image

So I do like this:
double textHeight = dimStyle.TextHeight() * dimStyle.DimScale();
or:
double textHeight = dimStyle.TextHeight() * pText->DimScale(&dimStyle);

But I still got the wrong value because dimStyle.DimScale() returns 1.0, not 0.001. After checking the model again, I find that both the text and the annotation style have a model space scale and will affect the text scale respectively:

So could anyone do me a favor to figure out the difference between these two kinds of model space scale? How can I get the correct scale whice is 0.001? Thanks!

Hi @shushenrui1996,

I can see from your first image the the model space scale has been overridden from the dimension style - this is why the text label is blue.

Have a look at ON_Annotation::DimensionStyle in opennurbs_annotationbase.h and let me know if you have any questions.

– Dale

Hi Dale. Thanks for your reply!
Actually the dimStyle I got from pText is just from ON_Annotation::DimensionStyle like this:

const ON_ModelComponentReference& parentDimStyleRef = onxModel.DimensionStyleFromId(pText->DimensionStyleId());
const ON_DimStyle* parentDimStyle = ON_DimStyle::Cast(parentDimStyleRef.ModelComponent());
if (!parentDimStyle) 
        return nullptr;
const ON_DimStyle& dimStyle = pText->DimensionStyle(*parentDimStyle);

And the dimScale I got is still 1.0.
Is there anything wrong with this? Thanks!

Hi @shushenrui1996,

This chunk of code works with the attached model.

ONX_ModelComponentIterator it(model, ON_ModelComponent::Type::ModelGeometry);
const ON_ModelComponent* model_component = nullptr;
for (model_component = it.FirstComponent(); nullptr != model_component; model_component = it.NextComponent())
{
  const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component);
  if (nullptr != model_geometry)
  {
    const ON_Annotation* annotation = ON_Annotation::Cast(model_geometry->Geometry(nullptr));
    if (nullptr == annotation)
      continue;

    // Get the id of the main (parent) dimstyle used by this object.
    // The style with this id should not be used directly if there is 
    // an override dimstyle present. 
    ON_UUID parent_dimstyle_id = annotation->DimensionStyleId();

    // Get a dimension style from its model id.
    const ON_ModelComponentReference& parent_dimstyle_ref = model.DimensionStyleFromId(parent_dimstyle_id);
    const ON_DimStyle* parent_dimstyle = ON_DimStyle::Cast(parent_dimstyle_ref.ModelComponent());
    if (nullptr == parent_dimstyle)
      continue;

    // Get the proper dimension style, including overrides, to use for this
    // annotation object.
    const ON_DimStyle& dimstyle = annotation->DimensionStyle(*parent_dimstyle);

    // Model space scale
    printf("Model space scale: %g\n", dimstyle.DimScale());
  }
}

test_model_space_scale.3dm (32.2 KB)

Does this help?

– Dale


Hi, Dale. That’s what in my code, which seems similar. But the dimScale is still 1.0.
I also noticed that aText->DimScaleSource() == 0. In this case, is there anything different I should do to get the correct dimscale?
Thanks!

Hi @shushenrui1996,

Does the code, I posted, work with the model I posted?

Feel free to upload your model if you’d like me to investigate further.

Regards,

– Dale

Hi Dale.
Yes. It works with your test model.
I may find the reason…The text belongs to a block. If this block is exploded, the scale will be correct.
Thank you very much to do further investigation for me. But the model with blocks is too big to upload. How do I upload the model?
Best regards!

https://www.rhino3d.com/upload

Hi Dale.
Thanks. The file is uploaded as dimScale.zip

The unit system of the model is meters. But the unit system of the block is millimeters, as seen with ON_InstanceDef::UnitSystem. Thus, the block was scaled during insertion.

– Dale

This works. Thank you so much!