Results 1 to 3 of 3

Thread: How to update content of the MText?

  1. #1
    Login to Give a bone
    0

    Default How to update content of the MText?

    Hello everyone!

    I have a question. I have a method wich creates Mtext with а list of block names. I need that every time when I insert new block in drawing and call my method the list in Mtext wil be updated and name of block wil be added to list. Now it only adds new Mtext but I need only update existing Mtext without insert new MText. I dont know how realize update.

    How to update content of the MText?

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    5,568
    Login to Give a bone
    0

    Default Re: How to update content of the MText?

    It would help if you posted the code you already have. Don't forget to enclose it in code tags. Use the Go Advanced button and the # button.
    C:> ED WORKING....

  3. #3
    Login to Give a bone
    0

    Default Re: How to update content of the MText?

    Here is my code
    Code:
    public static List<string> GetAllFormats () // Получает все примененные форматы для подсчета их количества
              {
                   Document doc = Application.DocumentManager.MdiActiveDocument;
                   Editor ed = doc.Editor;
                   Database db = doc.Database;
    
                   List<string> listOfFormatsInDrawing = new List<string>();
                   using ( Transaction tr = doc.TransactionManager.StartTransaction() )
                   {
                        BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                        if ( bt.Has("MainTitle") )
                        {
                             foreach ( ObjectId btrId in bt )//bt набор btrRecord то есть по своей сути уже коллекция!
                             {
                                  BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
                                  if ( btr.Name.Contains("Title"))
                                  {
                                       ObjectIdCollection brIdCollection = btr.GetBlockReferenceIds(false, true);// собрать все Id от BlockReference из BlockTableRecord в коллекцию
    
                                       foreach ( ObjectId brId in brIdCollection )
                                       {
                                            BlockReference br = tr.GetObject(brId, OpenMode.ForRead) as BlockReference;// получить все BlockReference
                                            AttributeCollection attrIdCollection = br.AttributeCollection;// собрать все Id от атрибутов из BlockTableRecord в коллекцию
                                            foreach ( ObjectId idAttRef in attrIdCollection )
                                            {
                                                 AttributeReference att = tr.GetObject(idAttRef, OpenMode.ForRead) as AttributeReference;
                                                 if ( att.Tag=="Format" )
                                                 {                                                  
                                                      pageFormat=att.TextString;
                                                      listOfFormatsInDrawing.Add(pageFormat);
                                                 }
                                            }
                                       }
                                  }
                             }
                        }
    
                        tr.Commit();
                   }
                   return listOfFormatsInDrawing;
    
    
              }
    
              [CommandMethod("CreateFormatList")]
              public static void CreateFormatList ()//Создает список всех примененных в чертеже форматов
    			{
                  
                   Document acDoc = Application.DocumentManager.MdiActiveDocument;
                   Database acCurDb = acDoc.Database;
                   
                   GetAllFormats();
                   List<string> formatInCurrentDrawing =GetAllFormats();
                   formatInCurrentDrawing.Sort();
                   string resultString= string.Join("| ", formatInCurrentDrawing);
                   // Start a transaction
                   using ( Transaction acTrans = acCurDb.TransactionManager.StartTransaction() )
                   {
                        // Open the Block table for read
                        BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
    
                        BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[ BlockTableRecord.PaperSpace ], OpenMode.ForWrite) as BlockTableRecord;
                        // Create a multiline text object
                        using ( MText listOfFormats = new MText() )
                        {
                             listOfFormats.Location=new Point3d(-185, -15, 0);
                             listOfFormats.TextHeight=10.5;
                             listOfFormats.Attachment=AttachmentPoint.TopLeft;
                             listOfFormats.Width=182;
                             listOfFormats.Contents=$"This drawing contains {resultString}";
                             listOfFormats.Layer="-10-Viewports";
    
                             acBlkTblRec.AppendEntity(listOfFormats);
                             acTrans.AddNewlyCreatedDBObject(listOfFormats, true);
                        }
                            
    
    
                   acTrans.Commit();
                   }
    			}

Similar Threads

  1. 2014: no thumbnails for 2014 content after batch update
    By geistwolke in forum Revit Architecture - Families
    Replies: 0
    Last Post: 2014-07-14, 07:24 PM
  2. GetBoundingBox MText actual content only
    By mailmaverick361505 in forum AutoLISP
    Replies: 5
    Last Post: 2013-12-11, 11:24 AM
  3. Content center update
    By bub4 in forum Inventor - General
    Replies: 1
    Last Post: 2009-09-10, 01:21 AM
  4. Update Shared Content with WU2?
    By mibzim in forum Revit Architecture - General
    Replies: 1
    Last Post: 2008-10-02, 10:18 AM
  5. Differences in content of Mtext returned
    By jmcshane in forum AutoLISP
    Replies: 2
    Last Post: 2007-06-14, 08:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •