Author Topic: [topology-Hatch]Complete solution set of functions for handling Hatch Entities  (Read 837 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
Different from ACAD's HATCH entity, the HATCH and boundary LOOP processed by the API have complete "topological" relationships.


1.
Merge (MERGE)


(xdrx_hatch_merge <ss ... ent>)



2.
Detachment (DETACH)


   1). Specify the point location and remove a HATCH with independent topology relationship.
      (xdrx_hatch_detach ent pnt)
      (xdrx_getpropertyvalue ent "detach" pnt)



   2). Detach all HATCHs with independent topological relationships
      (xdrx_hatch_detach ent t)

      (xdrx_getpropertyvalue ent "detach" t)



3.
Extract a HATCH with independent topological relationship


       (xdrx_getpropertyvalue ent "extractloopat" pnt)



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e (car (xdrx_entsel "\nPickup HATCH<exit>:" '((0 . "hatch")))))
  3.             (setq pnt (getpoint "\nClick to extract the LOOP<Exit>:"))
  4.             (setq ss (xdrx_getpropertyvalue e "extractloopat" pnt))
  5.             (xdrx_entity_setcolor ss (xdrx_math_rand 0 40))
  6.        )
  7.      (xd::drag:simplemove ss "\nInsertion point:" 5 t)
  8.    )
  9.    (princ)
  10. )

4.
HATCH --> REGION (with topological relationship)


       (xdrx_hatch->region <ss ...ent ...>)



5.
HATCH --> MPOLYGON (with topological relationship)


       (xdrx_hatch->mpolygon <ss ...ent ...>)



6.
HATCH --> Boundary LOOP geometric entity table

       (xdrx_getpropertyvalue ent "getloops")

The following code demonstrates obtaining the boundary geometry entity table, then generating a polyline and moving it.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e (car (xdrx_entsel "\nPickup HATCH<exit>:" '((0 . "hatch")))))
  3.             (setq ents (xdrx_getpropertyvalue e "getloops"))
  4.        )
  5.      (progn (setq ss (xdge::entity:make ents))
  6.             (xdrx_entity_setcolorss 7)
  7.             (xd::drag:simplemove ss "\nInsertion point:" 5 t)
  8.             (xdge::free ents)
  9.      )
  10.    )
  11.    (princ)
  12. )

7.
 HATCH --> "Root Loops (obtain the root LOOP of the topological relationship)"


       (xdrx_getpropertyvalue ent "rootloops" [t])

Give T parameter, directly generate GE geometric entity, otherwise return LOOP index number (integer)
The following code demonstrates obtaining the ROOT boundary geometric entity table, then generating a polyline and moving it.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e (car (xdrx_entsel "\nPickup HATCH<exit>:" '((0 . "hatch")))))
  3.             (setq ents (xdrx_getpropertyvalue e "rootloops" t))
  4.        )
  5.      (progn (setq ss (xdge::entity:make ents))
  6.             (xdrx_entity_setcolorss 7)
  7.             (xd::drag:simplemove ss "\nInsertion point:" 5 t)
  8.             (xdge::free ents)
  9.      )
  10.    )
  11.    (princ)
  12. )

8.
HATCH --> Child Loops (obtain all child LOOPs under a certain root LOOP of the topological relationship)


       (xdrx_getpropertyvalue ent "childloops" <ent or pnt or inx integer index or t>)

       Give the T parameter and get all sub-LOOPs.
       Return the LOOP index number table

    The following code demonstrates obtaining all sub-LOOP boundary geometric entity tables under ROOT, then generating polylines and moving them.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e (car (xdrx_entsel "\nPickup HATCH<exit>:" '((0 . "hatch")))))
  3.             (setq pnt (getpoint "\nPick point <exit> under a certain ROOT:"))
  4.             (setq ents (xdrx_getpropertyvalue e "childloops" pnt))
  5.        )
  6.      (progn (setq ss nil)
  7.             (mapcar '(lambda (x)
  8.                        (setq e1 (xdrx_getpropertyvalue e "getloopat" x))
  9.                        (setq e2 (xdge::entity:make e1))
  10.                        (xdge::free e1)
  11.                        (setq ss (cons e2 ss))
  12.                      )
  13.                     ents
  14.             )
  15.             (xdrx_entity_setcolorss 7)
  16.             (xd::drag:simplemove ss "\nInsertion point:" 5 t)
  17.      )
  18.    )
  19.    (princ)
  20. )

9.
HATCH --> Parent Loops (obtain the parent LOOP of a certain child LOOP in the topological relationship)


       (xdrx_getpropertyvalue ent "parent" <ent or pnt or inx integer index>)

    The following code demonstrates obtaining the parent LOOP boundary geometric entity table of the child ROOT, then generating a polyline and moving it.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e (car (xdrx_entsel "\nPickup HATCH<exit>:" '((0 . "hatch")))))
  3.             (setq pnt (getpoint "\nPick point under a certain sub-ROOT <exit>:"))
  4.             (setq inx (xdrx_getpropertyvalue e "parentloop" pnt))
  5.        )
  6.      (progn (setq e1 (xdrx_getpropertyvalue e "getloopat" inx))
  7.             (setq e2 (xdge::entity:make e1))
  8.             (xdge::free e1)
  9.             (xdrx_entity_setcolor e2 7)
  10.             (xd::drag:simplemove e2 "\nInsertion point:" 5 t)
  11.      )
  12.    )
  13.    (princ)
  14. )

10.
HATCH --> Get the boundary LOOP geometric entity of the specified index


           (xdrx_getpropertyvalue ent "getloopat" <inx>)

11.
HATCH --> Give a point and get the nearest LOOP index of the point


           (xdrx_getpropertyvalue ent "LoopIndexAt" <pnt>)

           (xdrx_getpropertyvalue ent "ClosestLoopTo" <pnt>)


12.
HATCH --> Get the number of LOOPs


           (xdrx_getpropertyvalue ent "NumLoops")

13.
HATCH --> Get the ROOT LOOP of the topological relationship of the specified entity, point nearby or specified index


           (xdrx_getpropertyvalue ent "RootLoop" <ent or pnt or inx> [t])

           Returns the geometric entity for the T parameter, otherwise returns the index number

14.
Query the topological relationship of the filled entity boundary


         (xdrx_get_topology ent)

         Returns the topology structure table of the boundary LOOP, such as:

Command: (xdrx_get_topology (car (entsel)))
Select objects: ((0 (1) (2 (3))) (4 (5 (6))) (7 (8)) (9 (10) (11 (12))))

15.
HATCH area (The HATCH area without HATCH area attribute area is 0 can be calculated)


       (xdrx_get_area ent)
       (xdrx_getpropertyvalue ent "area")

General entity attribute query function xdrx_getpropertyvalue about HATCH:

(xdrx_getpropertyvalue (car (entsel)))
Select object:
Class AcDbHatch:

     ├─Area
     ├─AssocObjIds
     ├─Detach
     ├─DetachLoopAt (Point)
     ├─ExtractLoopAt (Point)
     ├─Length
     ├─ShadeTintValue
     ├─GradientShift
     ├─GradientAngle
     ├─GradientName
     ├─GradientType
     ├─HatchLines
     ├─HatchObjectType
     ├─IsGradient
     ├─IsHatch
     ├─IsSolidFill
     ├─Elevation
     ├─HatchStyle
     ├─Normal
     ├─NumPatternDefinitions
     ├─PatternAngle
     ├─PatternScale
     ├─PatternSpace
     ├─PatternName
     ├─PatternDouble
     ├─PatternType
     ├─NumHatchLines
     ├─LoopIndexAt
     ├─loopTypeAt ├─LineGenerationEnabled(2007+)
     ├─OriginPoint(2007+)


Loops Class:
     ├─ClosestLoopTo
     ├─GetLoops
     ├─GetLoopAt
     ├─NumLoops
     ├─RootLoop
     ├─RootLoops
     ├─ParentLoop
     ├─ChildLoops

General entity attributes about HATCH editing function xdrx_setpropertyvalue

Command: (xdrx_setpropertyvalue (car (entsel)))

Select objects:
Class AcDbHatch:

   ├─ShadeTintValue(Real)
   ├─GradientShift(Real)
   ├─GradientAngle(Real)
   ├─GradientName(STR)
   ├─GradientType
   ├─HatchObjectType(0 or 1)
   ├─Gradient(0 or 1 and STR)
   ├─Elevation(Real or Int)
   ├─HatchStyle(0 or 1 or 2)
   ├─Normal(Vector)
   ├─PatternAngle(Real)
   ├─PatternScale(Real)
   ├─PatternSpace(Real)
   ├─PatternName(0 or 1 or 2 and STR)
   ├─PatternDouble(T or Nil)
   ├─PatternType(0 or 1 or 2)
   ├─appendLoop (looptype (ent1,ent2...pickset))
   ├─removeLoopAt (loopinx)
   ├─LineGenerationEnabled(T or Nil)(2007+)
   ├─OriginPoint(Point)(2007+)

=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
« Last Edit: November 17, 2023, 10:17:08 AM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net