Author Topic: help is code  (Read 2122 times)

0 Members and 1 Guest are viewing this topic.

A-SABER

  • Mosquito
  • Posts: 11
help is code
« on: January 14, 2021, 12:28:16 AM »
in this code, I write it to make auto number but numbers do not draw after click when pressing ESC all number draw. I want to write each number after a click

[CommandMethod("autonumber")]
        public void writecoorpoint()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptPointOptions ppoint1;
            PromptPointResult pr1;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                PromptIntegerOptions pintop = new PromptIntegerOptions("\nenter start number");
                PromptIntegerResult pinreslet = ed.GetInteger(pintop);
                int num = pinreslet.Value;
                while (true)
                {
                    ppoint1 = new PromptPointOptions("\nspecifay point :");
                    pr1 = ed.GetPoint(ppoint1);
                    if (pr1.Status == PromptStatus.Cancel)
                    {
                        break;
                    }
                    else if (pr1.Status == PromptStatus.OK)
                    {
                        MText mt1 = new MText();
                        mt1.SetDatabaseDefaults();
                        mt1.Location = pr1.Value;
                        mt1.Contents = num.ToString();
                        mt1.TextHeight = .5;
                        btr.AppendEntity(mt1);
                        trans.AddNewlyCreatedDBObject(mt1, true);
                        DBPoint point = new DBPoint(pr1.Value);
                        btr.AppendEntity(point);
                        trans.AddNewlyCreatedDBObject(point, true);
                        num = num + 1;
                    }
                }
                    trans.Commit();
                }                             
            }
        }
    }


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: help is code
« Reply #1 on: January 14, 2021, 01:23:06 AM »
Hi,

You should add:
Code - C#: [Select]
  1. db.TransactionManager.QueueForGraphicsFlush();
after the line:
Code - C#: [Select]
  1. trans.AddNewlyCreatedDBObject(point, true);
Speaking English as a French Frog

A-SABER

  • Mosquito
  • Posts: 11
Re: help is code
« Reply #2 on: January 14, 2021, 07:31:13 PM »
thank you sir it's ok now

A-SABER

  • Mosquito
  • Posts: 11
Re: help is code
« Reply #3 on: January 15, 2021, 11:58:50 PM »
Hi,

You should add:
Code - C#: [Select]
  1. db.TransactionManager.QueueForGraphicsFlush();
after the line:
Code - C#: [Select]
  1. trans.AddNewlyCreatedDBObject(point, true);

sir how can yous text jigs in same code pls

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: help is code
« Reply #4 on: January 16, 2021, 12:12:56 PM »
Hi,

Here's a basic example:

Code - C#: [Select]
  1.     public class Commands
  2.     {
  3.         [CommandMethod("TEST")]
  4.         public static void Test()
  5.         {
  6.             var doc = Application.DocumentManager.MdiActiveDocument;
  7.             var db = doc.Database;
  8.             var ed = doc.Editor;
  9.  
  10.             var pir = ed.GetInteger("\nEnter the start number: ");
  11.             if (pir.Status != PromptStatus.OK)
  12.                 return;
  13.             int index = pir.Value;
  14.  
  15.             using (var tr = db.TransactionManager.StartTransaction())
  16.             {
  17.                 var cSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  18.                 while (true)
  19.                 {
  20.                     using(var text = new DBText())
  21.                     {
  22.                         text.SetDatabaseDefaults();
  23.                         text.Height = 0.5;
  24.                         text.TextString = index.ToString();
  25.                         var jig = new TextJig(text);
  26.                         var pr = ed.Drag(jig);
  27.                         if (pr.Status == PromptStatus.Cancel)
  28.                             return;
  29.                         if (pr.Status == PromptStatus.None)
  30.                             break;
  31.                         cSpace.AppendEntity(text);
  32.                         tr.AddNewlyCreatedDBObject(text, true);
  33.                         db.TransactionManager.QueueForGraphicsFlush();
  34.                         index++;
  35.                     }
  36.                 }
  37.                 tr.Commit();
  38.             }
  39.         }
  40.     }
  41.  
  42.     public class TextJig : EntityJig
  43.     {
  44.         DBText text;
  45.         Point3d dragPoint;
  46.  
  47.         public TextJig(DBText text) : base(text)
  48.         {
  49.             this.text = text;
  50.         }
  51.  
  52.         protected override SamplerStatus Sampler(JigPrompts prompts)
  53.         {
  54.             var options = new JigPromptPointOptions("\nSpecify insertion point: ");
  55.             options.UserInputControls =
  56.                 UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted;
  57.             var result = prompts.AcquirePoint(options);
  58.             if (result.Value.IsEqualTo(dragPoint))
  59.                 return SamplerStatus.NoChange;
  60.             dragPoint = result.Value;
  61.             return SamplerStatus.OK;
  62.         }
  63.         protected override bool Update()
  64.         {
  65.             text.Position = dragPoint;
  66.             return true;
  67.         }
  68.     }
Speaking English as a French Frog