Restore hatch boundaries if they have been lost

By Philippe Leefsma

Q:

How can I restore hatch boundaries if they have been lost due to some reason?

A:

AutoCAD doesn’t have a command to do that. Fortunately, we can create one with ObjectARX API.

The most complex in the task is to handle splines properly as there are various of splines in AutoCAD, fixed point spline, rational spline, not rational spline, etc. The code works quite well for lines, arcs, circles, ellipses and splines.  Note that error checking is minimal for brevity.  Please bear in mind that it is not possible to restore the original boundary entities exactly, because the underlying geometry objects prefixed with AcGe in AcDbHatch do not match AutoCAD database entities prefixed with AcDb one by one. For example, if there is a closed loop composed of some lines in the original hatch boundary entities, it will become a polyline in the final result restored back.

In the example, the boundaries restored are in red and put on the current layer. You can use selection filter to get them for further modification.  There is a Test.dwg drawing included, for test purposes.

How To Use The Example:

1. Build the attached project with VC2010 or copy the code for “BzhRestoreHatchBoundary” to your own project

2. Startup AutoCAD

3. Load the ARX file

4. Open the drawing that you want to restore hatch boundaries

5. Issue the command with short name RHB or long name RESTOREHATCHBOUNDARY

6. Choose hatch entities that you would like to restore boundaries. You could choose multiple hatches one time


Comments

7 responses to “Restore hatch boundaries if they have been lost”

  1. Andrew Puller Avatar
    Andrew Puller

    Autocad has two methods to restore hatch boundaries.
    Method 1. Select a hatch, right click and select generate boundary (which runs the HatchGenerateBoundary command).
    Method 2. Select a hatch, on the ribbon, Hatch Editor context tab, Boundaries panel, click Recreate, choose polyline or region, then yes or no to associate the new boundary to the hatch.

  2. René Davis Ramirez Avatar
    René Davis Ramirez

    Is it possible to have the same code posted as managed .Net (VB or C#), not all of us are able to build / understand the ObjectARX API.
    Thanks

  3. Philippe Leefsma Avatar
    Philippe Leefsma

    Sorry René, we can’t convert every arx sample we post into .Net. The .Net API is mainly a wrapper around arx classes, so in most of the cases the member methods are pretty similar. As far as the class names are concerned, they are identical but without prefix in .Net: AcDbHatch -> Hatch, AcGePoint3d -> Point3d.

  4. René Davis Ramirez Avatar
    René Davis Ramirez

    I have been trying to convert the sample to managed Net myself, but it seems that I’m missing some header files:
    acmemdebug.h
    gemetatp.h
    gegetmti.h
    dbidnln.h
    I have also tried asking ADN, CaseNo-08044841, but with no result.
    Thanks in any case.
    René

  5. incognito Avatar
    incognito

    Mr Andrew, you are the cad Master !
    Thanks a lot ! Your advice worked perfectly and saved me a lot of trouble !

  6. Afiqah Ismail Avatar
    Afiqah Ismail

    Thank you so much! :’D You help me.

Leave a Reply to Alexander RivilisCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading