How to Mirror MText Using AutoCAD api in c#?

varun_nct
Participant Participant
881 Views
2 Replies
Message 1 of 3

How to Mirror MText Using AutoCAD api in c#?

varun_nct
Participant
Participant

MtxtMirror.PNG

 

The first Image showing the AutoCAD mirror command output :

Second Image: We implemented the following code and get this output.

 

Can you help us, what we are missing in this implementation? while mirroring MText using  Matrix3d.Mirroring(line) API.

 

We are using the following code for mirroring :

 DocuclonedEntitynt doc =

Autodesk.AutoCAD.ApplicationServices.Application.DocuclonedEntityntManager.MdiActiveDocument 

clonedEntitynt Matrix3d mtrx3d = Matrix3d.Mirroring(line);

Transaction tr = db.TransactionManager.StartTransaction();

   using (tr)

         {

            try

               {

                  // Get the entity to mirror

                         Entity entity = tr.GetObject(id, OpenMode.ForRead) as Entity;

                          mirroredEntity = entity;

                          // Clone it

                          Entity clonedEntity = entity.Clone() as Entity;

                           // Apply the mirror transformation

                           clonedEntity.TransformBy(mtrx3d);

                            // Add mirrored entity to the database

                            BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

  BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                            btr.AppendEntity(clonedEntity);

                            tr.AddNewlyCreatedDBObject(clonedEntity, true);

                            if (erase)

                            {

                                // Finally erase the original entity (if needed)

                                entity.UpgradeOpen();

                                entity.Erase();

                                mirroredEntity = clonedEntity;

                            }

                      }

                    catch (System.Exception ex)

                    {

 

                    }

                    tr.Commit();

 

0 Likes
882 Views
2 Replies
Replies (2)
Message 2 of 3

hosneyalaa
Advisor
Advisor
0 Likes
Message 3 of 3

_gile
Consultant
Consultant

Hi,

You should have a look at this reply.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes