.NET

Reply
Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 1 of 8 (589 Views)

creating Mtext object with an annotative TextStyle

589 Views, 7 Replies
09-25-2012 09:14 AM

Hello .NET gurus out there,

 

I am trying to create a Mtext object with an annotative TextStyle.  I make the textstyle current (which I don't know if is exactly the same as changing the TextStyleId of the mtext object) and create the MText.  The problem which I encounter is that the newly crated MText Object has textheight as the textstyle's paper space text height, instead of scaling the text height by the annotative scale, as when you create the Mtext using Autocad menu.

 

Any example helping with this problem will be greatly appreciated.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 8 (551 Views)

Re: creating Mtext object with an annotative TextStyle

09-26-2012 09:49 AM in reply to: DLyaskov

Take a look at this article:

 

http://through-the-interface.typepad.com/through_the_interface/2007/04/making_autocad_.html

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 3 of 8 (531 Views)

Re: creating Mtext object with an annotative TextStyle

09-26-2012 02:31 PM in reply to: Hallex

Thank you Hallex,

 

I used similar code.  After detailed debugging I found out that if I don't make the text object annotative the text height is appropriately scaled, but if I try to, as soon as the code goes over the line making the text object annotative the model space text height of the mtext object is change to the value of the Paper Space text height as specified in the text style dialog box, and the paper space text height of the mtext object is scaled down as seen in the snapshots.

 

TextStyleTableRecord textstyleTblRec = trans.GetObject(textstyleTbl[pt.TagStyle], OpenMode.ForRead) as TextStyleTableRecord;
if (textstyleTblRec.Annotative == AnnotativeStates.True)
{
ObjectContextManager ocm = db.ObjectContextManager;
ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
//Autodesk.AutoCAD.Internal.ObjectContexts.AddContext(abbr, occ.CurrentContext);
abbr.AddContext(occ.CurrentContext);
abbr.Annotative = AnnotativeStates.True;
}

 

Any ideas, on how to have correct text height and make it annotative?

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 4 of 8 (452 Views)

Re: creating Mtext object with an annotative TextStyle

10-09-2012 09:33 AM in reply to: DLyaskov

I tried the sample code from Kean's blog that Hallex was referring to but could not reproduce the same behavior.

Can you please share a small buildable project to demonstrate the issue ?

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 5 of 8 (439 Views)

Re: creating Mtext object with an annotative TextStyle

10-09-2012 06:04 PM in reply to: DLyaskov

I have attached file with simple example.  I simply want to create annotative mtext object with text height taken from text style if the style is not annotative, and modified with the annotation scale if the text style is annotative.

 

For example if text style "Standard" is not annotative and has height of 5, I want to create an annotative mtext object with height=5,

if text style "Standard" is annotative and has height of 5/96 and annotative scale 1/8"=1'-0", again I want to have annotative mtext object with model space height of 5.

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 6 of 8 (403 Views)

Re: creating Mtext object with an annotative TextStyle

10-11-2012 04:30 AM in reply to: DLyaskov

Hello,

 

I am still not sure if I fully understand the problem.

 

Assuming that you have entered a value of 5.0 for the text height in the style dialog,

 

Do you mean you want to create a annotative text of height = 5.0 irrespective of whether the text style is made "Annotative" or not ?

 

In that case, you could set the TextHeight of the MText using the value from the text style.

For example, in your code you can add these lines :

 

TextStyleTableRecord textstyleTblRec = trans.GetObject(textstyleTbl[style], OpenMode.ForRead) as TextStyleTableRecord;
if (textstyleTblRec.TextSize > 0.0)
{
	abbr.TextHeight = textstyleTblRec.TextSize;
}

 

Hope this helps.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 7 of 8 (356 Views)

Re: creating Mtext object with an annotative TextStyle

10-15-2012 06:23 AM in reply to: DLyaskov

The problem seems to arise when I set:

 

abbr.Annotative = AnnotativeStates.True;

 

Paper text height is 0", and Model text height is 1/8" which is the height in define in the text style.

 

If I don't set the

 

//abbr.Annotative = AnnotativeStates.True;

 

then I have only one property for the height (text height, not paper and model text heights as above) and the height is scaled correctly, but the text is not annotative.

 

See snapshots.

 

Any ideas?

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 8 of 8 (306 Views)

Re: creating Mtext object with an annotative TextStyle

10-23-2012 09:13 AM in reply to: DLyaskov

If you do not want the scaling to happen, can you try setting the cannoscale of the database to a value that will ensure that the text height is retained same as the one that you have provided to the MText ?

 

After the annotative text is inserted, you can reset the cannoscale of the database to what it was originally.

 

Here is a sample code that might help :

 

// Set an anno scale based on how you want the scaling to happen
// when the entity is made annotative.
ObjectContext oc = occ.GetContext("1:500");
if (oc != null)
{
	AnnotationScale annoScale = oc as AnnotationScale;
	if (annoScale != null)
		db.Cannoscale = annoScale;
}

// Create the annotative text
//...

// Set an anno scale back to what it was originally
// before we changed it.
oc = occ.GetContext("1:1000");
if (oc != null)
{
	AnnotationScale annoScale = oc as AnnotationScale;
	if (annoScale != null)
		db.Cannoscale = annoScale;
}

 The code snippet is only to explain more clearly what I meant and the scale values that I have used may not be the right ones.

 

Hope this helps.



Balaji
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community