Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Yes, since arx interprets the list, it’s not reliable to hash.
Example  '(220 220 220 220)

Just tested it
'(220 220 220 220) This kind of data is illegal data. If it cannot be converted into resbuf, an error will be reported. This should be a BUG of AUTOCAD, and there are 221, 222, etc.

Command: (xdrx_entity_hashstring '(220 220 220 220))
error: LsAdsInvoke Internal Error

Command: (xdrx_entity_hashstring '(221 220 220 220))
error: LsAdsInvoke Internal Error

Command: (xdrx_entity_hashstring '(219 220 220 220))
"4355413184637992076"

Command: (xdrx_entity_hashstring '(218 220 220 220))
"6650467817808998717"

Command: (xdrx_entity_hashstring '(223 220 220 220))
error: LsAdsInvoke Internal Error

Command: (xdrx_entity_hashstring '(239 220 220 220))
error: LsAdsInvoke Internal Error

Command: (xdrx_entity_hashstring '(230 220 220 220))
error: LsAdsInvoke Internal Error

Command: (xdrx_entity_hashstring '(10 220 220 220))
"6350337662529562573"

Command: (xdrx_entity_hashstring '(215 220 220 220))
"13560894329457377856"

Code - C++: [Select]
  1. else if ((resType >= 210) && (resType <=239))
  2. {
  3.         return(RT3DPOINT);
  4. }
  5.  

Should be changed to:

Code - C++: [Select]
  1. else if ((resType >= 210) && (resType <=219))
  2. {
  3.         return(RT3DPOINT);
  4. }
  5.  
12
No, I don’t think I hashed the restype, just the value, but the value you get back can also be modified

vlia_k_v (‘(10 10 10) ‘(10 10))
or
vlia_k_v ‘(10 10 10) ‘'(220 220 220 220)

so it’s not really possible to build a generic unordered_map for lisp,  because there is some probability of a ;LsAdsInvoke Internal Error, or worse, corrupt data

13
Yes, since arx interprets the list, it’s not reliable to hash.
Example  '(220 220 220 220)

'(220 220 220 220)
ARX's resbuf will be parsed into 3D points, but restype=220, not RT3DPOINT,

  So when you calculate the hash value, don’t you include the restype to make it unique?

Code - C++: [Select]
  1. size_t XdDbUtils::CalculateHash(const AcGePoint3d& point) {
  2.         size_t hash = 0;
  3.         hash ^= std::hash<double>{}(point.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
  4.         hash ^= std::hash<double>{}(point.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
  5.         hash ^= std::hash<double>{}(point.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
  6.  
  7.         return hash;
  8. }

Code - C++: [Select]
  1. int XDGetHash()
  2. {
  3.         resbuf* rb = ads_getargs();
  4.         size_t hash = 0;
  5.         while(rb)
  6.         {
  7.                 int restype = XdRbUtils::dxfCodeToDataType(rb->restype);
  8.                 hash ^= XdDbUtils::CalculateHash(rb->restype);
  9.                 switch (restype)
  10.                 {
  11.                 case RTENAME:
  12.                 {
  13.                         AcDbObjectId id;
  14.                         if (acdbGetObjectId(id, rb->resval.rlname) == eOk)
  15.                         {
  16.                                 AcDbEntity* pEnt;
  17.                                 if (acdbOpenObject(pEnt, id, kForRead) == eOk)
  18.                                 {
  19.                                         int param = 511;
  20.                                         if (rb->rbnext && rb->rbnext->restype == RTSHORT)
  21.                                         {
  22.                                                 param = rb->rbnext->resval.rint;
  23.                                         }
  24.                                         hash ^= XdDbUtils::CalculateHash(pEnt, param);
  25.                                         pEnt->close();
  26.                                 }
  27.                         }
  28.                 }
  29.                         break;
  30.                 case RT3DPOINT:
  31.                 {
  32.                         hash ^= XdDbUtils::CalculateHash(asPnt3d(rb->resval.rpoint));
  33.                 }
  34.                         break;
  35.                 case RTSTR:
  36.                 {
  37.                         hash ^= XdDbUtils::CalculateHash(rb->resval.rstring);
  38.                 }
  39.                         break;
  40.                 case  RTREAL:
  41.                 {
  42.                         hash ^= XdDbUtils::CalculateHash(rb->resval.rreal);
  43.                 }
  44.                         break;
  45.                 case  RTSHORT:
  46.                 {
  47.                         hash ^= XdDbUtils::CalculateHash(rb->resval.rint);
  48.                 }
  49.                         break;
  50.                 case RTLONG:
  51.                 {
  52.                         hash ^= XdDbUtils::CalculateHash(rb->resval.rlong);
  53.                 }
  54.                         break;
  55.                 default:
  56.                         break;
  57.                 }              
  58.                 rb = rb->rbnext;
  59.         }
  60.         // &#23558;&#21704;&#24076;&#20540;&#36716;&#25442;&#20026;&#23383;&#31526;&#20018;
  61.         std::string hashString = std::to_string(hash);
  62.         ads_retstr(CMyString::StringToTCHAR(hashString));
  63.         return RSRSLT;
  64. }
14
Yes, since arx interprets the list, it’s not reliable to hash.
Example  '(220 220 220 220)
15
Cool, I always thought it would be really cool to have hashmaps in Autolisp.
I had imagined using hash_combine generating hashes from lists, so lisp users could create generic hash maps

Code - Auto/Visual Lisp: [Select]
  1. (vlia_k_v '(100.0 100.0 10.0) '((-1 . <Entity name: 23873ab8490>) (0 . LWPOLYLINE)...))
  2.  

I toyed with it here, but passing data between autolisp and arx is just not reliable..
so bleh @ autodesk, there's really no good way to extend autolisp.

https://www.theswamp.org/index.php?topic=57894.0

Group code 10, ARX is treated as 3D point,
So for lwpolyline, after lisp is passed to arx for processing, the two-dimensional points will become three-dimensional points.
16
Cool, I always thought it would be really cool to have hashmaps in Autolisp.
I had imagined using hash_combine generating hashes from lists, so lisp users could create generic hash maps

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (vlia_k_v '(100.0 100.0 10.0) '((-1 . <Entity name: 23873ab8490>) (0 . LWPOLYLINE)...))
  3.  

I toyed with it here, but passing data between autolisp and arx is just not reliable..
so bleh @ autodesk, there's really no good way to extend autolisp.

https://www.theswamp.org/index.php?topic=57894.0

thanks,
In addition to the xdrx-entity-removeduplicates provided above, the XDRX API
Functions for calculating the hash value of an entity are also provided:
xdrx-entity-hashstring

Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. @param param Bitmask parameter used for selectively calculating the hash value:
  3.  *  - 1: Use the entity's dxfName
  4.  *  - 2: Use the entity's layerName
  5.  *  - 4: Use the entity's colorIndex
  6.  *  - 8: Use the entity's linetypeName
  7.  *  - 16: Use the entity's linetypeScale
  8.  *  - 32: Use the entity's lineWidth
  9.  *  - 64: Use the entity's GRIP Point array (nStretchPts)
  10.  *  - 128: Use the entity's bounding box (box)
  11.  *  - 256: Use the entity's centroid
  12.  *  - 512: Use the entity's description (entity->desc())
  13. |;
  14. Command: (xdrx-entity-hashstring (entlast) 1)
  15. "1078249248256508798"
  16. Command: (xdrx-entity-hashstring (entlast) 3)
  17. "11643239585821548497"
  18. Command: (xdrx-entity-hashstring (entlast) 129)
  19. "3826409512706688743"
  20.  
17
Try this yes does add a midpoint on lines but if its not a problem use it.

Code: [Select]
; By Kent Cooper
; March 2014

(setq
  pl (car (entsel "\nSelect Polyline: "))
  endpar (fix (vlax-curve-getEndParam pl))
  step 0
  ptlist (list (vlax-curve-getStartPoint pl))
)
(repeat
  (if (vlax-curve-isClosed pl)
    (1- (* endpar 2))
    (* endpar 2)
  )
  (setq ptlist
    (cons (vlax-curve-getPointAtParam pl (setq step (+ step 0.5))) ptlist)
  )
)
(setq ptlist (cons (last ptlist) ptlist))

; find left most corner with a sort
; By Dexus NOV 2022

(defun rotate-rectange (lst / corner)
  (setq corner
    (car
      (vl-sort lst
        (function
          (lambda (a b)
            (if (equal (car a) (car b) 1e-4)
              (< (cadr a) (cadr b))
              (< (car a) (car b))
            )
          )
        )
      )
    )
  )
  (while (/= (car lst) corner) ; rotate until corner is the first item
    (setq lst (append (cdr lst) (list (car lst))))
  )
  lst
)
 
(setq lst2 (rotate-rectange ptlist))
18
Cool, I always thought it would be really cool to have hashmaps in Autolisp.
I had imagined using hash_combine generating hashes from lists, so lisp users could create generic hash maps

Code - Auto/Visual Lisp: [Select]
  1. (vlia_k_v '(100.0 100.0 10.0) '((-1 . <Entity name: 23873ab8490>) (0 . LWPOLYLINE)...))
  2.  

I toyed with it here, but passing data between autolisp and arx is just not reliable..
so bleh @ autodesk, there's really no good way to extend autolisp.

https://www.theswamp.org/index.php?topic=57894.0

19
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by w64bit on May 23, 2024, 04:22:52 PM »
Selection it's OK.
But after the faces offset the command is not closed. It remains opened and you have to enter twice to close it.
20
AutoLISP (Vanilla / Visual) / Flexible function for getting vertices of polyline
« Last post by EWCAD on May 23, 2024, 02:03:53 PM »
I have been trying to create a function that will get the vertices of a polyline that has an arc top and sort them clockwise starting from the bottom left. I have on that I use for rectangles but I cant quite wrap my head around how to reliably get the middle "vertice" of the arc segment at the top. I have gotten it to work for certain configurations but when you mirror the shape, it no longer works... I've been at this all day and at this point I think I'm probably over complicating it. For reference I have attached a screen cap with the shapes I'm working with and the points I am wanting to get a list of. (center of arc is a bonus, really only need the middle grip)

Here is my (probably overly complicated) bits of code.

Code: [Select]
(defun sort-vertices (verts)
  (vl-sort verts
           '(lambda (a b)
              (or (< (cadr a) (cadr b))
                  (and (= (cadr a) (cadr b)) (< (car a) (car b))))))
)

(defun order-vertices (sorted-verts / bl br top-verts tl tr)
  ;; Bottom-left and bottom-right vertices
  (setq bl (car sorted-verts))
  (setq br (car (vl-sort (cdr sorted-verts)
                         '(lambda (a b) (> (car a) (car b))))))

  ;; Extract top vertices by removing bottom vertices
  (setq top-verts (vl-remove bl sorted-verts))
  (setq top-verts (vl-remove br top-verts))

  ;; Top-left and top-right vertices
  (setq tl (car (vl-sort top-verts
                         '(lambda (a b) (< (car a) (car b))))))
  (setq tr (car (vl-remove tl top-verts)))

  (list bl tl tr br)
)

(defun midpoint-of-arc (curve-obj start-pt end-pt bulge / start-param end-param mid-param param-range)
  (if (/= bulge 0.0)
    (progn
      (setq start-param (vlax-curve-getParamAtPoint curve-obj start-pt))
      (setq end-param (vlax-curve-getParamAtPoint curve-obj end-pt))
      ;; Handle wrapping around for closed polylines
      (if (> start-param end-param)
        (setq end-param (+ end-param (vlax-curve-getEndParam curve-obj))))
      (setq mid-param (/ (+ start-param end-param) 2))
      (vlax-curve-getPointAtParam curve-obj mid-param))
    nil)
)



(defun c:SortPolylineVertices (/ ent entType verts midpoints sorted-verts ordered-verts pt index next-pt bulge coords bulges entData numVerts closed tl tr midpoint)
  (setq ent (car (entsel "\nSelect polyline: ")))
  (setq entType (cdr (assoc 0 (entget ent))))
  (if (or (eq entType "LWPOLYLINE") (eq entType "POLYLINE"))
    (progn
      (setq verts '())
      (setq midpoints '())
      (setq closed nil)
      (setq entObj (vlax-ename->vla-object ent))
      (if (eq entType "LWPOLYLINE")
        (progn
          (setq coords (vlax-get entObj 'Coordinates))
          (setq entData (entget ent))
          (setq closed (= 1 (logand (cdr (assoc 70 (entget ent))) 1))) ; Check if polyline is closed
          (setq numVerts (/ (length coords) 2))
          (setq bulges
                (mapcar 'cdr
                        (vl-remove-if-not
                         '(lambda (x) (eq (car x) 42))
                         entData)))
          (setq index 0)
          (while (< index numVerts)
            (setq pt (list (nth (* index 2) coords) (nth (+ 1 (* index 2)) coords)))
            (setq verts (cons pt verts))
            (setq index (1+ index))
          )
          (setq verts (reverse verts))
        )
        (progn
          (setq entData (entget ent))
          (setq verts
                (mapcar 'cdr
                        (vl-remove-if-not
                         '(lambda (x) (eq (car x) 10))
                         entData)))
          (setq bulges
                (mapcar 'cdr
                        (vl-remove-if-not
                         '(lambda (x) (eq (car x) 42))
                         entData)))
          (setq closed (= 1 (logand (cdr (assoc 70 (entget ent))) 1))) ; Check if polyline is closed
        )
      )
      (setq sorted-verts (sort-vertices verts))
      (setq ordered-verts (order-vertices sorted-verts))
      (setq tl (nth 1 ordered-verts)) ; Top-left vertex
      (setq tr (nth 2 ordered-verts)) ; Top-right vertex

      ;; Check bulge for the segment from top-left to top-right
      (setq index (1+ (vl-position tl sorted-verts)))
      (setq bulge (if (< index (length bulges)) (nth index bulges) 0.0))

      ;; Calculate the midpoint of the arc
      (setq midpoint (midpoint-of-arc entObj tl tr bulge))
      (setq midpoints (list midpoint))

      (princ "\nOrdered Vertices: ")
      (mapcar '(lambda (pt) (princ (strcat "\n" (rtos (car pt) 2 2) ", " (rtos (cadr pt) 2 2)))) ordered-verts)
      (princ "\nMidpoints of Arcs: ")
      (mapcar '(lambda (pt) (if pt (princ (strcat "\n" (rtos (car pt) 2 2) ", " (rtos (cadr pt) 2 2))))) midpoints)
    )
    (princ "\nSelected entity is not a polyline.")
  )
  (princ)
)









Pages: 1 [2] 3 4 ... 10