Hatch patterns list and preview

Hatch patterns list and preview

jptallano
Enthusiast Enthusiast
1,463 Views
10 Replies
Message 1 of 11

Hatch patterns list and preview

jptallano
Enthusiast
Enthusiast

Hi,

I need to recreate the hatch pattern dialog (see screen cap below), since it seems it is not exposed by the API, and the solution suggested here does not seem to work anymore.

 

jptallano_0-1736337369369.png

 

How can I list existing patterns, and given a hatch pattern name, is it possible to retrieve its preview image?

For listing, I found this post, but can't get the solution to work.

 

0 Likes
1,464 Views
10 Replies
Replies (10)
Message 2 of 11

ActivistInvestor
Mentor
Mentor

The solution you referenced is most-likely pre-unicode, and that might explain why it doesn't work, but this should work:

 

public static class Class1
{
   /// <summary>
   /// List the names of all patterns
   /// </summary>
   [CommandMethod("LISTPATTERNS")]
   public static void ListPatterns()
   {
      var ed = Application.DocumentManager.MdiActiveDocument.Editor;
      var names = HatchPatterns.Instance.AllPatterns.ToList();
      foreach(var item in names)
      {
         ed.WriteMessage($"\n{item}");
      }
   }

   /// <summary>
   /// Select a pattern using the UI:
   /// </summary>
   [CommandMethod("HATCHPAL")]
   public static void HatchPalletteTest()
   {
      string name = "ANSI32";
      bool result = acedHatchPalletteDialog(name, false, out string output);
      if(result)
      {
         Application.DocumentManager.MdiActiveDocument
            .Editor.WriteMessage($"\nSelected {output}");
      }
   }

   [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
      CharSet = CharSet.Unicode,
      EntryPoint = "?acedHatchPalletteDialog@@YA_NPEB_W_NAEAPEA_W@Z")]
   public static extern bool acedHatchPalletteDialog(string pattern, bool allowCustom, out string result);
}

 

 

0 Likes
Message 3 of 11

Anthony_PungitoreJFMRZ
Contributor
Contributor

His link to the original code was fine.  The real answer is that these EntryPoints are unmanaged native references that seem to always change with new software versions.  They aren't a documented part of the API.  You need to use the Visual Studio Dev Command Prompt and get it through bash with dumpbin on the acad.exe.  (dumpbin /exports "C:\Program Files\Autodesk\AutoCAD 2024\acad.exe")

Message 4 of 11

kerry_w_brown
Advisor
Advisor

@Anthony_PungitoreJFMRZ 

 

The EntryPoint used by Tony is correct for acad2024 & 2025

ie : "?acedHatchPalletteDialog@@YA_NPEB_W_NAEAPEA_W@Z"

 

added:  I just checked my archive ; ac2012 used the same EntryPoint

Dumpbin_acad2012_exe.txt  2025-01-09_09-39-43.jpg

but is the different to the sample as shown in Kean's 2007 blog post

https://www.keanw.com/2007/03/showing_autocad.html     which is a different link than the OP's


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 5 of 11

Anthony_PungitoreJFMRZ
Contributor
Contributor

Absolutely.  I was just trying to provide some inside that will help others find EntryPoints in future releases.

0 Likes
Message 6 of 11


@Anthony_PungitoreJFMRZ wrote:

His link to the original code was fine. 

The link to the original code is only fine if the OP is using AutoCAD 2007.

 

Entry point symbols do not change with each release. They are dependent on the platform (32/64 bit), and on whether the release is UNICODE or not, which changed between 2007 and 2008. AutoCAD 2008 was the first release to support 64 bit platforms natively, and AutoCAD 2020 was the last release to support 32 bit builds, so the "real answer" depends on what release and platform the OP is using.

 

Most use DependencyWalker (depends.exe) or its managed cousin for examining export symbols.

 

 

0 Likes
Message 7 of 11

Anthony_PungitoreJFMRZ
Contributor
Contributor

That's definitely good to know, thank you.  No offense intended, when I said "real answer" I only meant to point out that the most important part of the code is the bit that is undocumented, and explaining the process on how to get these EntryPoints.  Everything else is basic API stuff.  

0 Likes
Message 8 of 11

Yes, the api entry points are not documented because the apis themselves are not documented and subject to change or removal at any time.

So one is always taking a risk by the depending on them.
0 Likes
Message 9 of 11

18348401357
Enthusiast
Enthusiast

/// <summary>
/// 模态显示图案选择对话框
/// </summary>
/// <returns>成功返回<c>true</c></returns>
public bool ShowDialog()
{
var dr = ShowHatchPaletteDialog(Name, ShowCustom, out var newPattern);
if (dr)
{
Name = Marshal.PtrToStringAuto(newPattern) ?? "";
}

return dr;
}

[DllImport("acad.exe", CharSet = CharSet.Auto,
EntryPoint = "?acedHatchPalletteDialog@@YA_NPEB_W_NAEAPEA_W@Z")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowHatchPaletteDialog(string currentPattern,
[MarshalAs(UnmanagedType.Bool)] bool showCustom, out IntPtr newPattern);

0 Likes
Message 10 of 11

jptallano
Enthusiast
Enthusiast

Thanks for your answers guys!

Actually I know how to find the entry point, and am currently using the correct one for my platform.

I gave a try to suggested solution in the post above this one, but it does nothing, the dialog won't show up.

0 Likes
Message 11 of 11

ActivistInvestor
Mentor
Mentor

In that case, you will need to post the code that you are trying to get to work. I've had no problem with showing that dialogue using Code like the example I posted about. You also need to indicate what product and release you are using. 

0 Likes