Author Topic: Hatch not showing up after creation  (Read 545 times)

0 Members and 1 Guest are viewing this topic.

Kralj_klokan

  • Mosquito
  • Posts: 15
Hatch not showing up after creation
« on: July 16, 2019, 06:31:05 PM »
Hi,

I ' m new to this forum and i have a problem while creating a hatch using traceboundaries().
After i creating my hatch and setting hatchstyle to outer i does not show up. The border polylines is displayed but the hatch only shows up if i click on any object and change its property.
I have no idea what the issue could be. I 've set all my system variables to the default. I tried it on various drawings and even on other autocad versions.
Once the hatch appears everything is working fine.

This issue is driving me nuts. Here is my Hatch creation code. Maybe someone sees something i don't.  :x :x :x
Code - C#: [Select]
  1.   Document doc = Application.DocumentManager.MdiActiveDocument;
  2.             Database db = doc.Database;
  3.             Editor ed = doc.Editor;
  4.             PromptPointResult ppr = ed.GetPoint("\nSelect internal point: ");
  5.             if (ppr.Status != PromptStatus.OK) return;
  6.  
  7.             DBObjectCollection objs = ed.TraceBoundary(ppr.Value, true);
  8.             if (objs.Count == 0) return;
  9.  
  10.             using (Transaction tr = doc.TransactionManager.StartTransaction())
  11.             {
  12.                 BlockTable acBlkTbl;
  13.                 acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  14.  
  15.                 // Open the Block table record Model space for write
  16.                 BlockTableRecord acBlkTblRec;
  17.                 acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  18.  
  19.                 using (Hatch hat = new Hatch())
  20.                 {
  21.                     acBlkTblRec.AppendEntity(hat);
  22.                     tr.AddNewlyCreatedDBObject(hat, true);
  23.                     hat.HatchStyle = HatchStyle.Outer;
  24.                     hat.SetDatabaseDefaults();
  25.                     hat.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
  26.  
  27.                     hat.Associative = true;
  28.                     foreach (DBObject obj in objs)
  29.                     {
  30.                         Curve c = obj as Curve;
  31.                         if (c != null)
  32.                         {
  33.                             ObjectId curveId = acBlkTblRec.AppendEntity(c);
  34.                             tr.AddNewlyCreatedDBObject(c, true);
  35.                             hat.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection() { curveId });
  36.                         }
  37.                     }
  38.                     hat.EvaluateHatch(true);
  39.                     var ds = new DrawStream();
  40.                 }
  41.                 tr.Commit();
  42.             }
  43.  
Any help would be greatly appreciated since i 'm working on this for days.


edit kdub: code tag for code=csharp added.
« Last Edit: July 16, 2019, 09:27:07 PM by kdub »

gile

  • Water Moccasin
  • Posts: 2222
  • Marseille, France
Re: Hatch not showing up after creation
« Reply #1 on: July 17, 2019, 02:00:39 AM »
Hi,

Your code works for me (tested on A2019).
You can try adding:
Code - C#: [Select]
  1. hat.DowngradeOpen();
just after:
Code - C#: [Select]
  1. hat.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
Speaking English as a French Frog

Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #2 on: July 17, 2019, 03:41:27 AM »
Hi,

Your code works for me (tested on A2019).
You can try adding:
Code - C#: [Select]
  1. hat.DowngradeOpen();
just after:
Code - C#: [Select]
  1. hat.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");

I 've tried your suggestion but unfortunately still no result. It could be some graphics card setting or something like that.
This is really getting ridiculous. I 'm also using AutoCAD 2019.

Is the hatch created with hatchstyle.outer?

Ty for your help anyway.
« Last Edit: July 17, 2019, 08:00:59 AM by Kralj_klokan »

Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #3 on: July 17, 2019, 04:13:43 AM »
I 've recorded my behaviour to show a picture how its working.
It's uploaded on vimeo on this link https://vimeo.com/user100893766/review/348539021/7a97fe464e
I also attached the video.

So i pick a point inside of the area i want to hatch. The hatch does not show up. But if i click on the polyline that surrounds the hatch  twice quickly it suddenly appears.

 :uglystupid2: :uglystupid2: :uglystupid2:

Atook

  • Swamp Rat
  • Posts: 933
Re: Hatch not showing up after creation
« Reply #4 on: July 17, 2019, 12:30:07 PM »
Have you tried Editor.Regen() once you're done creating the hatch and committing the transaction?

Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #5 on: July 17, 2019, 12:37:41 PM »
Hi Atook,

Yes, i 've tried putting Editor.Regen() after everything. I also tried typing manually regen in the command prompt. Still the hatch does not show.
I m wondering now the whole day how it is working for Gile but not for me.

The hatch wont show until I double click on the outer polyline and then press ESC.

In fact, even if i change the hatchlooptype being appended to Outermost, the hatch will show but not with the proper HatchStyle(Outer).
A hatch created in such manner will get the desired hatchstyle also only if i press twice on the polyline or do something with it.

I know, it's really weird.
« Last Edit: July 17, 2019, 12:45:38 PM by Kralj_klokan »

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1363
  • class keyThumper<T>:ILazy<T>
Re: Hatch not showing up after creation
« Reply #6 on: July 17, 2019, 04:15:09 PM »
I dropped the code into a Method and compiled with VS2019 Win10.
Netloaded debug build into AC2020 Vanilla.
Ran in Modelspace,
Worked as expected.


Changed to Paperspace Layout, toggled to Modelspace.

Worked as expected.

In both cases I ran the command twice .. once to select outer space, once to select inner space.

« Last Edit: July 17, 2019, 04:20:52 PM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1363
  • class keyThumper<T>:ILazy<T>
Re: Hatch not showing up after creation
« Reply #7 on: July 17, 2019, 04:27:14 PM »
What does the DrawStream Class do ??

I did comment it out.


« Last Edit: July 17, 2019, 04:38:34 PM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #8 on: July 18, 2019, 06:08:26 AM »
What does the DrawStream Class do ??

I did comment it out.

The DrawStream class is useless. It 's just a c/p error. By your image i can see that the HatchStyle is not set to outer. I would expect that the smallest circle is not hatched if the hatchstyle is set to outer.
Could there be a difference since I call my method by button click, while you call it with a command?

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1363
  • class keyThumper<T>:ILazy<T>
Re: Hatch not showing up after creation
« Reply #9 on: July 18, 2019, 06:31:51 AM »
First time I selected the outer circle .. it filled the outer

Second time I selected the inner circle .. it filled the inner.

I didn't check if selecting the inner filled both.

I haven't fully read the docs so I'm not certain if the result is correct of not, but it made sence at the time ; and I'm too brain dead (GMT +12 ) at the moment to investigate further.

added:
Perhaps you could do some manual Hatches from the command line to test the expected default behaviour.
« Last Edit: July 18, 2019, 06:38:29 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

MickD

  • Gator
  • Posts: 3289
  • (x-in)->[process]->(y-out)
Re: Hatch not showing up after creation
« Reply #10 on: July 18, 2019, 06:51:29 AM »
....
Could there be a difference since I call my method by button click, while you call it with a command?

Have you tried locking the document? Some times this is required when using dialog to give the CAD system full control of the editor.
Debugging:
Being the detective in a crime movie where you're also the murderer.

“Someone's sitting in the shade today because someone planted a tree a long time ago.”
- Warren Buffet

Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #11 on: July 18, 2019, 07:21:53 AM »
....
Could there be a difference since I call my method by button click, while you call it with a command?

Have you tried locking the document? Some times this is required when using dialog to give the CAD system full control of the editor.

I 've tried your suggestion but still the same problem. Reinstalling autocad also did nothing.
Only if i edit the outer polyline (move it around, set the transparancy in the property view to 51 instead of 50...) the hatch shows.

It's also interesting that if I set the appended loop type to outermost. The hatch shows, but still the smallest circle get hatched. And if i then edit the outer polyline, the inner hatch disappears and everything looks as it should


Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #12 on: July 18, 2019, 01:33:47 PM »
After some investigation i finally came to the answer.

When I try to run this code with an command it works without any problems.
Since I was just calling the method to execute, there must be some issue with it.

I had just to restructure my code to call the code as an command and now it's working great.

Thank you all for your help.

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1363
  • class keyThumper<T>:ILazy<T>
Re: Hatch not showing up after creation
« Reply #13 on: July 18, 2019, 03:27:56 PM »
For the benefit of anyone reading this thread later, perhaps you should post your revised code in full so we understand what you have changed.
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

Kralj_klokan

  • Mosquito
  • Posts: 15
Re: Hatch not showing up after creation
« Reply #14 on: July 18, 2019, 05:32:01 PM »
I 'll see to it as soon i get everything to work. Then I 'll post a complete answer.