Code Red > .NET

help is code

(1/1)

A-SABER:
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:
Hi,

You should add:

--- Code - C#: ---db.TransactionManager.QueueForGraphicsFlush();after the line:

--- Code - C#: ---trans.AddNewlyCreatedDBObject(point, true);

A-SABER:
thank you sir it's ok now

A-SABER:

--- Quote from: gile on January 14, 2021, 01:23:06 AM ---Hi,

You should add:

--- Code - C#: ---db.TransactionManager.QueueForGraphicsFlush();after the line:

--- Code - C#: ---trans.AddNewlyCreatedDBObject(point, true);
--- End quote ---

sir how can yous text jigs in same code pls

gile:
Hi,

Here's a basic example:


--- Code - C#: ---    public class Commands    {        [CommandMethod("TEST")]        public static void Test()        {            var doc = Application.DocumentManager.MdiActiveDocument;            var db = doc.Database;            var ed = doc.Editor;             var pir = ed.GetInteger("\nEnter the start number: ");            if (pir.Status != PromptStatus.OK)                return;            int index = pir.Value;             using (var tr = db.TransactionManager.StartTransaction())            {                var cSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);                while (true)                {                    using(var text = new DBText())                    {                        text.SetDatabaseDefaults();                        text.Height = 0.5;                        text.TextString = index.ToString();                        var jig = new TextJig(text);                        var pr = ed.Drag(jig);                        if (pr.Status == PromptStatus.Cancel)                            return;                        if (pr.Status == PromptStatus.None)                            break;                        cSpace.AppendEntity(text);                        tr.AddNewlyCreatedDBObject(text, true);                        db.TransactionManager.QueueForGraphicsFlush();                        index++;                    }                }                tr.Commit();            }        }    }     public class TextJig : EntityJig    {        DBText text;        Point3d dragPoint;         public TextJig(DBText text) : base(text)        {            this.text = text;        }         protected override SamplerStatus Sampler(JigPrompts prompts)        {            var options = new JigPromptPointOptions("\nSpecify insertion point: ");            options.UserInputControls =                UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted;            var result = prompts.AcquirePoint(options);            if (result.Value.IsEqualTo(dragPoint))                return SamplerStatus.NoChange;            dragPoint = result.Value;            return SamplerStatus.OK;        }        protected override bool Update()        {            text.Position = dragPoint;            return true;        }    }

Navigation

[0] Message Index

Go to full version