MText match orientation to layout

MText match orientation to layout

office
Enthusiast Enthusiast
470 Views
1 Reply
Message 1 of 2

MText match orientation to layout

office
Enthusiast
Enthusiast

I have a working code for the mtext match orientation to layout, but it won't set the match orientation to layout in bricscad. Anyone have any working code for the match orientation to layout in bricscad?

The acMText.SetPaperOrientation(true); does not work with bricscad, only works with autocad.

Here is my code:

 

 

#if BRX_APP
    Document doc = Bricscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
#elif ACAD_APP
    Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
#endif
    Database acCurDb = doc.Database;
    using (doc.LockDocument())
    {
        using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
        {
            MText acMText = acTrans.GetObject(id, OpenMode.ForWrite, false) as MText;

            ObjectContextManager ocm = acCurDb.ObjectContextManager;
            ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
            if (isAnnotation == true)
            {
                acMText.Annotative = AnnotativeStates.True;
                acMText.SetPaperOrientation(true);
#if BRX_APP
                try
                {
                    acMText.AddContext(occ.CurrentContext);
                }
                catch { }
#elif ACAD_APP
                try
                {
                    ObjectContexts.AddContext(acMText, occ.CurrentContext);
                }
                catch { }
#endif
            }
            else
            {
                acMText.Annotative = AnnotativeStates.False;
                acMText.SetPaperOrientation(false);
            }

            acTrans.Commit();
        }
    }
0 Likes
Accepted solutions (1)
471 Views
1 Reply
Reply (1)
Message 2 of 2

office
Enthusiast
Enthusiast
Accepted solution

I found a lisp code how to enable the match orientation to layout and I made a C# code that works both with AutoCAD and BricsCAD.

        /// <summary>
        /// Match orientation to layout.
        /// </summary>
        /// <param name="paperOrientation">0 = Disable match orientation to layout. 1 = Enable match orientation to layout</param>
        /// <param name="dbObj">Any annotative database object: MText, BlockTableRecord, etc...</param>
        static void SetPaperOrientation(Database acCurDb, Transaction acTrans, DBObject dbObj, int paperOrientation)
        {
#if ACAD_APP
            if (paperOrientation == 1)
                dbObj.SetPaperOrientation(true);
            else
                dbObj.SetPaperOrientation(false);
#elif BRX_APP
            //This portion of code works with AutoCAD too.
            string regAppName = "AcadAnnoPO";
            ResultBuffer resbuf = dbObj.GetXDataForApplication(regAppName);
            if (resbuf != null)
            {
                TypedValue[] data = resbuf.AsArray();
                for (int i = 0; i < data.Length; i++)
                {
                    TypedValue tv = data[i];
                    if (tv.TypeCode == 1070)
                    {
                        data[i] = new TypedValue(1070, paperOrientation);
                    }
                }
                resbuf = new ResultBuffer(data);
                dbObj.XData = resbuf;
            }
            else
            {
                if (paperOrientation == 1)
                {
                    RegAppTable regAppTable = (RegAppTable)acTrans.GetObject(acCurDb.RegAppTableId, OpenMode.ForRead);
                    if (!regAppTable.Has(regAppName))
                    {
                        using (RegAppTableRecord regAppRecord = new RegAppTableRecord())
                        {
                            regAppRecord.Name = regAppName;
                            regAppTable.Add(regAppRecord);
                            acTrans.AddNewlyCreatedDBObject(regAppRecord, true);
                        }
                    }

                    ResultBuffer rb = new ResultBuffer(new TypedValue(1001, regAppName), new TypedValue(1070, paperOrientation));
                    dbObj.XData = rb;
                }
            }
#endif
        }

 

0 Likes