.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MLeader Mtext not updating

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
matt.worland
1937 Views, 8 Replies

MLeader Mtext not updating

Im sure I have a simple error, but Im spinning my wheels at the end of a long week.

 

 Dim myMleader As MLeader = CType(mySelObj.ObjectId.GetObject(OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.MLeader)
 Dim myNewValue As String = "New Value"
 myMleader.UpgradeOpen()
 myMleader.MText.Contents = myNewValue

My code above doesnt seem to update the contents of the mtext. I have tried a couple of iterations, but cant seem to get it to update.

 

Thanks,

matt

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
8 REPLIES 8
Message 2 of 9

Try by creating a  New Mtext and change the Mtext property of Mleader

 

 Dim mt As MText = New MText
                mt.SetDatabaseDefaults()
                mt.Contents = "new Value"
                myMleader.UpgradeOpen()
                myMleader.MText = mt

 

Message 3 of 9

That worked, Thank you very much.

I wasnt thinking of the MTEXT as being a property, and therefore trying to modify the current one. Which makes sense, since I couldnt get an objectid on the original mtext.

 

Thanks again,

matt

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 4 of 9
matt.worland
in reply to: matt.worland

Another question, is there a trick to getting the current settings from the old mtext (text style, height, color...). Could I clone instead of creating a new?

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 5 of 9

Yes, I think you could clone the old mtext to get the properties.

Also there is entType1.GetProperties(); if you want to list the properties of any object.

See an example in here

 

Message 6 of 9
fsztuczny
in reply to: matt.worland

You can also set to the mleader the same mtext:

MLeader mld = ent as MLeader;    //Remember open for write!
MText mtxt = mld.MText;
//some operations on mtext
//and finally update the mleader:
mld.MText = mtxt;

Tested on autocad 2018 and 2014.

Message 7 of 9
CADbloke
in reply to: Ajilal.Vijayan

Here's another way to clone the properties of anything but you will need JSON.NET .. or you could use a different serializer

 

string serialized = JsonConvert.SerializeObject(mText);
MText newMtext   = JsonConvert.DeserializeObject<MText>(serialized);

from: https://stackoverflow.com/a/15788750/492

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 8 of 9
CADbloke
in reply to: CADbloke

So I can't edit my answer. This forum software, eh?
So, don't do this - JSON.NET blew up ...

Newtonsoft.Json.JsonSerializationException: Error getting value from 'ColumnFlowReversed' on 'Autodesk.AutoCAD.DatabaseServices.MText'. ---> Autodesk.AutoCAD.Runtime.Exception: eNotApplicable
   at bool value Autodesk.AutoCAD.DatabaseServices.MText.get_ColumnFlowReversed()
   at object GetColumnFlowReversed(object)
   at object Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(object target)

so do this ...

var serializerSettings = new JsonSerializerSettings();
serializerSettings.Error = (serializer, err) => err.ErrorContext.Handled = true;

string serialized = JsonConvert.SerializeObject(mLeaderMtext, serializerSettings);
MText  newMtext   = JsonConvert.DeserializeObject<MText>(serialized, serializerSettings);

 from https://stackoverflow.com/a/21901646/492

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 9 of 9
CADbloke
in reply to: CADbloke

did I mention how crap this forum is?

 

ok, try 

var serializerSettings = new JsonSerializerSettings();
serializerSettings.Error = (serializer, err) => err.ErrorContext.Handled = true;

MText newMtext = new MText();
newMtext.SetDatabaseDefaults();

string serialized = JsonConvert.SerializeObject(mText, serializerSettings);
JsonConvert.PopulateObject(serialized, newMtext, serializerSettings);

 before I run out of time, dropping this here ...

MText newMtext = oldMtext.Clone() as MText;

from  https://www.theswamp.org/index.php?topic=51641.msg567186#msg567186https://www.theswamp.org/index.php...

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost