Code Red > .NET

Hatch not showing up after creation

<< < (5/6) > >>

Kralj_klokan:

--- Quote from: kdub on July 19, 2019, 06:31:52 AM ---
Sorry, I'm lost regarding what you are trying to do.

Are you calling this from another module ??

It's way past my bedtime ... perhaps someone will be able to assist you over(my)night.

--- End quote ---

GMT+1 here.

Good night :)

I ' m actually trying to run this code from a modeless dialog in a synchronous way.

I want to be able to click on the button wait for the command to finish and then call  the next line of code.
So far i have implemented various methods where i could just instantiate the class like this example.


--- Code - C#: ---var jig = new HatchJig(new Matrix3d(), new Plane(200, 200, 200, 200), new Polyline() /*{ Color = color }*/, hat);jig.RunHatchJig(layerName, color);
This example works fine and everything gets drawn the appropriate way.

When i try to execute the code for hatching by pickpoint this way. I get the error i posted the video about.

--- Code - C#: ---var hatch = new PickPointHatch(layerName, color); hatch.TraceBoundaryAndHatch();I 'm puzzled why every other method works fine this way but not this one.
After i found out that it would work if i called a command  i ignored this error and tried to call a command. The problem is that i can't get it to be synchronous.

When I call the method like this Document.SendStringToExecute() the result is good. But its async (other code gets executed while the command is still running).

I 'm looking for a way to call the command either by this way
--- Code - C#: ---var hatch = new PickPointHatch(layerName, color);hatch.TraceBoundaryAndHatch(); and to work fine.

or to call it somehow with
--- Code - C#: ---Editor.Command() or
--- Code - C#: ---Document.SendStringToExecute() while being synchronous.

I ' m not an native english speaker and sorry if you have a hard time understanding my problem.

gile:
Hi,

It's a good practice to wrap your method in a CommandMethod and call it with SendStringToExevute() from a modeless dialog (typically a palette set). This way you let AutoCAD taking care of locking the document and setting the focus to the editor.

Kralj_klokan:

--- Quote from: gile on July 19, 2019, 08:19:34 AM ---Hi,

It's a good practice to wrap your method in a CommandMethod and call it with SendStringToExevute() from a modeless dialog (typically a palette set). This way you let AutoCAD taking care of locking the document and setting the focus to the editor.

--- End quote ---

I have no problem with doing it that way. But what if i want to wait when the command is over to do some more code. Should i listen for a CommandEnded() event or something like that? Let's say i want to have some values updated when i execute this command.

gile:
As SendStringToExecute runs asynchronously, you have to also wrap the jig process in the same CommandMethod or another one.

If you do not want to use SendStringToExecute, you are responsible of locking the document (in a using statement) and setting the focus to the editor window before calling the methods.

Kralj_klokan:

--- Quote from: gile on July 19, 2019, 10:10:55 AM ---As SendStringToExecute runs asynchronously, you have to also wrap the jig process in the same CommandMethod or another one.

If you do not want to use SendStringToExecute, you are responsible of locking the document (in a using statement) and setting the focus to the editor window before calling the methods.

--- End quote ---

Thank you for your help.

I think that i now correctly lock the document and set the focus to the dwg. But still if i try to call the code like this
--- Code - C#: ---hatch.TraceBoundaryAndHatch(); It still does not show the hatch. The exact same code will work if i call it with SendStringToExecute  This is the code i came up with:


--- Code - C#: ---public void TraceBoundaryAndHatch()        {            Document doc = Application.DocumentManager.MdiActiveDocument;            Database db = doc.Database;            Editor ed = doc.Editor;            bool ContinueHatch = true;             using (DocumentLock acLckDoc = doc.LockDocument())            {                Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();                while (ContinueHatch)                {                    PromptPointResult ppr = ed.GetPoint("\nSelect internal point: ");                    if (ppr.Status != PromptStatus.OK) ContinueHatch = false;                     if (ContinueHatch)                    {                        DBObjectCollection objs = ed.TraceBoundary(ppr.Value, true);                        if (objs.Count == 0) return;                          using (Transaction tr = doc.TransactionManager.StartTransaction())                        {                            BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;                            BlockTableRecord MSrecord = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;                             using (Hatch hat = new Hatch())                            {                                MSrecord.AppendEntity(hat);                                tr.AddNewlyCreatedDBObject(hat, true);                                hat.HatchStyle = HatchStyle.Outer;                                hat.SetDatabaseDefaults();                                hat.Color = color;                                hat.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");                                hat.DowngradeOpen();                                hat.Associative = true;                                foreach (DBObject obj in objs)                                {                                    Curve c = obj as Curve;                                    if (c != null)                                    {                                        ObjectId curveId = MSrecord.AppendEntity(c);                                        tr.AddNewlyCreatedDBObject(c, true);                                        hat.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection() { curveId });                                    }                                }                            }                             tr.Commit();                        }                    }                }            }        }
Could it be that AutoCAD does some more things while executing a command? Maybe some kind of redraw or regen? If i manually call regen or redraw the hatch still will not show.
The only way it shows is if i try to edit its outer boundary. Or maybe the way i append the loop is not correct? Still i can't explain why the same code works when called as a command with SendStringToExecute() but not if I just call the method from code?.

I can only be grateful for your patience.


Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version