How to get ON_Text's transform matrix

ON_Text* aText = const_cast<ON_Text*>(dynamic_cast<const ON_Text*>(geometry));
ON_Xform xform = ON_Xform::IdentityTransformation;
const ON_ModelComponentReference& dimStyleRef = onxModel.DimensionStyleFromId(aText->DimensionStyleId());
const ON_DimStyle* dimStyle = ON_DimStyle::Cast(dimStyleRef.ModelComponent());
aText->GetTextXform(&ON_Viewport::DefaultTopViewYUp, dimStyle, 1.0f, xform);

Am I doing right? I’m little confused about the parameters of function GetTextXform().
Thank you!

I exported a model using code above, and found that the transform matrix of the ON_Text object is wrong. Could anyone help me find out why? Thanks!

@lowell - can you help with this?

@jiangz-a - Your code looks ok. Can you post a file with the text you’re trying to export?

text_test.3dm (99.8 KB)
Hi! Here is the file. I noticed that the m_plane of the ON_Text was drifting away from the board.

Thanks for the file.

One thing that may be part of the problem is that in your dimstyle, the Orient toward reader… setting is checked, meaning the text will be adjusted to be readable in a specific viewport.
Try unchecking that and see if it makes more sense.
If your viewport is anything other than world top coordinates, that is especially significant.


How are you using the xform you get from GetTextXform()?

You use DimensionStyleFromId() which returns the parent dimstyle. If there are property overrides, that will be different than the effective dimstyle for the annotation. I think the only override in your case is TextHeight which won’t cause a problem here, but in general, you should use

const ON_DimStyle& ON_Annotation::DimensionStyle(
  const ON_DimStyle& parent_dimstyle,
  bool bForceOverrideUpdate
) const

to get a dimstyle that includes overrides.

Uncheck it works! Thank you very much!