Author Topic: Property patternscale for hatch entity problem...  (Read 421 times)

0 Members and 1 Guest are viewing this topic.

dankobananko

  • Mosquito
  • Posts: 8
Property patternscale for hatch entity problem...
« on: January 28, 2024, 03:00:25 AM »
Hello.

I have one very strange issue with hatch patternscale, and couldn't understand what cause it so I hope
that somebody know why this happen.

Problem is when I set patternscale value to Hatch entity with code, pattern is not scaled on the same way as
if it's scaled from AutoCAD user interface. For example if I set value to 0.1,  than set to 0.2, set back to 0.1 it's
visible that  hatch patterns scaling is not identical in two iterations with same patternscale value 0.1. This is not case if I change patternscale inside AutoCAD UI. On Properties pallete is visible that parameter is applied
properly, but  does not have same effect  on pattern scaling when value is changed from code and AutoCAD UI.

this is code:

Code - C#: [Select]
  1.                
  2.    // Start a transaction
  3.                         using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
  4.                         {
  5.                             //Hatch entity
  6.                             _AcDb.Hatch hatch = (_AcDb.Hatch)objid.GetObject(_AcDb.OpenMode.ForWrite);
  7.                            
  8.                             //Pattern and scale
  9.                             hatch.PatternScale = Scale;
  10.                             hatch.PatternSpace = Scale;
  11.  
  12.                             //Color
  13.                             hatch.ColorIndex = iColor;
  14.  
  15.                             //Pattern
  16.                             hatch.SetHatchPattern(_AcDb.HatchPatternType.PreDefined, "some  autocad predefined");
  17.                             hatch.EvaluateHatch(true);
  18.  
  19.                             //Accept changes
  20.                             tr.Commit();
  21.                         }
  22.  

edit Kerry : [ code=csharp ]
« Last Edit: January 28, 2024, 03:23:01 PM by kdub_nz »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Property patternscale for hatch entity problem...
« Reply #1 on: January 28, 2024, 03:29:54 PM »

Have a look at
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-68CAD757-1857-4250-B92B-430318E5C110

The hatch is evaluated twice, before and after scale.

not sure if this is your issue, but . . .
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Property patternscale for hatch entity problem...
« Reply #2 on: January 28, 2024, 05:34:42 PM »
This works for me.

Code - C#: [Select]
  1.  
  2.    [CommandMethod("EditHatchPatternScale2")]
  3.    public static void EditHatchPatternScale2()
  4.    {
  5.       var doc = AcadApp.DocumentManager.MdiActiveDocument;
  6.       var db = doc.Database;
  7.       var ed = doc.Editor;
  8.  
  9.       // Select Hatch
  10.       PromptEntityOptions peo = new PromptEntityOptions(
  11.                   "\nSelect a Hatch to modify PatternScale: ");
  12.       peo.SetRejectMessage("Not a Hatch.");
  13.       peo.AddAllowedClass(typeof(Hatch), true);
  14.       PromptEntityResult per = ed.GetEntity(peo);
  15.       if (per.Status != PromptStatus.OK)
  16.          return;
  17.  
  18.       using (Transaction tr = db.TransactionManager.StartTransaction())
  19.       {
  20.          Hatch hatch = (Hatch)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
  21.          var currentPatternScale = hatch.PatternScale;
  22.  
  23.          // Prompt for PatternScale  
  24.          PromptDistanceOptions pdo = new PromptDistanceOptions(
  25.                         "\nNew PatternScale : ");
  26.          {
  27.             DefaultValue = currentPatternScale,
  28.             AllowZero = false,
  29.             AllowNegative = false
  30.          };
  31.          PromptDoubleResult pdr = ed.GetDistance(pdo);
  32.          if (pdr.Status != PromptStatus.OK)
  33.             return;
  34.          
  35.          // Modify PatternScale
  36.          hatch.EvaluateHatch(true);
  37.          hatch.PatternScale = pdr.Value;
  38.          hatch.SetHatchPattern(hatch.PatternType, hatch.PatternName);
  39.          hatch.EvaluateHatch(true);
  40.          tr.Commit();
  41.       }
  42.    }
  43.  
  44.  

Regards,

« Last Edit: January 28, 2024, 05:44:06 PM by kdub_nz »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

dankobananko

  • Mosquito
  • Posts: 8
Re: Property patternscale for hatch entity problem...
« Reply #3 on: January 29, 2024, 07:08:38 AM »
Great!

Thank you guys, you helped me a lot.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Property patternscale for hatch entity problem...
« Reply #4 on: January 29, 2024, 10:36:08 PM »


we're happy to help  :-)
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.