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

creating Mtext object with an annotative TextStyle

7 REPLIES 7
Reply
Message 1 of 8
DLyaskov
1436 Views, 7 Replies

creating Mtext object with an annotative TextStyle

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.

7 REPLIES 7
Message 2 of 8
Hallex
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
Message 3 of 8
DLyaskov
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?

Message 4 of 8
Balaji_Ram
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

Message 5 of 8
DLyaskov
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.

Message 6 of 8
Balaji_Ram
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

Message 7 of 8
DLyaskov
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?

Message 8 of 8
Balaji_Ram
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

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