Modifying CharacterSet Property of MText Object

Modifying CharacterSet Property of MText Object

drewj
Enthusiast Enthusiast
1,157 Views
5 Replies
Message 1 of 6

Modifying CharacterSet Property of MText Object

drewj
Enthusiast
Enthusiast

Is it possible to modify the CharacterSet of a MTEXT element?

 

You can modify it on the ribbon (see attached CharacterSet image) but I the only reference I can see for it is that it is readonly on the Font rather than on the individual mtext element (see FontCharacterSet image).


Regards,


Drew

0 Likes
Accepted solutions (1)
1,158 Views
5 Replies
Replies (5)
Message 2 of 6

ActivistInvestor
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Is it possible to modify the CharacterSet of a MTEXT element?

 

You can modify it on the ribbon (see attached CharacterSet image) but I the only reference I can see for it is that it is readonly on the Font rather than on the individual mtext element (see FontCharacterSet image).


Regards,


Drew


I'm pretty sure that the way to do this is via the TextEditor class. You call TextEdtior.CreateTextEditor() passing in the MText.

 

Then, you establish the selection or range of text that you want to modify (or use SelectAll() to modify the entire MText), then you use the Language property of the TextEditorSelection object returned by the TextEditor's Selection property. The value of the Language property is an int, which can be cast to/from System.Windows.Forms.VisualStyles.TextMetricsCharacterSet.

 

 

Message 3 of 6

drewj
Enthusiast
Enthusiast

That's exactly the type of push in the right direction I was looking for, thanks. I will report back if I get it working.

 

Cheers,

 

Drew

0 Likes
Message 4 of 6

drewj
Enthusiast
Enthusiast

Whoops, let me check that Language you suggested. I missed that, nearly there.

0 Likes
Message 5 of 6

drewj
Enthusiast
Enthusiast

Thanks for the help, this code accomplished the requirement:

 

public static void SetTextToModifiedCharacterSet(Document document)
{
Database db = document.Database;
Editor ed = document.Editor;
TypedValue[] tvs = new[]
{
new TypedValue(0, "MTEXT"), // only MText
new TypedValue(410, "Model") // in model space
};
SelectionFilter filter = new SelectionFilter(tvs);
PromptSelectionResult selection = ed.SelectAll(filter);
if (selection.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
foreach (SelectedObject obj in selection.Value)
{
ObjectId id = obj.ObjectId;
if (id.ObjectClass.DxfName == "MTEXT")
{
MText mtext = (MText)tr.GetObject(id, OpenMode.ForWrite);
TextEditor textEditor = TextEditor.CreateTextEditor(mtext);
textEditor.SelectAll();
TextEditorSelection sel = textEditor.Selection;
sel.Language = (int)System.Windows.Forms.VisualStyles.TextMetricsCharacterSet.Russian;
textEditor.Close(TextEditor.ExitStatus.ExitSave);
}

}
tr.Commit();
}
}

0 Likes
Message 6 of 6

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

Thanks for the help, this code accomplished the requirement:

 


Great. Glad you solved the problem.

0 Likes