Recent Posts

Pages: [1] 2 3 ... 10
1
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 (rb->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. }
2
Yes, since arx interprets the list, it’s not reliable to hash.
Example  '(220 220 220 220)
3
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.
4
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.  
5
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))
6
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

7
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.
8
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)
)









9
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by ribarm on May 23, 2024, 12:27:47 PM »
Have you tried : (while (= 1 (logand 1 (getvar 'cmdactive))) (command ""))
10
.NET / Re: Losing Block Name
« Last post by Jeff H on May 23, 2024, 11:19:32 AM »
When you insert blocks(BlockReference) they can only vary by position, rotation, and scaling from its definition(BlocktableRecord). So you really can not have a block that has different entities or representations of itself and have the ability to be dynamic.
AutoCAD does this by creating anonymous definitions(BlockTableRecords) naming them *UXXX for each of the dynamic states needed for all the references inserted in a drawing.

Pages: [1] 2 3 ... 10