Recent Posts

Pages: [1] 2 3 ... 10
1
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

2
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by w64bit on Today at 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.
3
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)
)









4
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by ribarm on Today at 12:27:47 PM »
Have you tried : (while (= 1 (logand 1 (getvar 'cmdactive))) (command ""))
5
.NET / Re: Losing Block Name
« Last post by Jeff H on Today at 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.

6
.NET / Losing Block Name
« Last post by kshitij.jadhav@cctech.co. on Today at 10:56:57 AM »
While developing an AutoCAD plugin in .NET, I encountered an issue where creating two new visibility states and setting this visibility to a block reference causes the block name to change to a format like UXXX (where X represents any digit). Although I can retrieve the original name from the dynamic table record, is there an alternative approach to prevent the block name from changing?
7
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by w64bit on Today at 10:38:50 AM »
For selection it's OK now, for closing the command, not.
Code: [Select]
(command "SOLIDEDIT" "F" "O" "X" "X")
(while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))
8
Use a hash table to quickly delete completely overlapping entities

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

What is a Hash Table?

A hash table (or hash map) is a data structure that provides a mechanism for storing key-value pairs, allowing for fast data retrieval. Each key is processed through a hash function, which computes an index (or hash code) into an array of buckets or slots. The key-value pair is then stored in the corresponding bucket. The fundamental operations of a hash table, such as insertion, deletion, and search, typically have an average time complexity of O(1), making them very efficient.

Why is Using a Hash Table to Delete Identical Entities in ARX Highly Efficient?

1. Fast Lookups:
  • The primary strength of a hash table is its ability to perform quick lookups. When deleting duplicate entities, you can compute a hash for each entity and check if that hash already exists in the table.
  • If the hash already exists, it means the entity is a duplicate and can be marked for deletion.
  • If the hash does not exist, the entity is added to the table.

2. Efficient Handling of Collisions:

  • In a hash table, collisions occur when two different entities produce the same hash code. Advanced hash table implementations efficiently handle collisions using techniques like chaining (where each bucket is a linked list of entries) or open addressing (where a collision triggers a search for the next available slot).
  • Proper handling of collisions ensures that even with duplicate entities, the overall performance remains optimal.

3. Scalability:

  • Hash tables scale well with the number of entities. As more entities are added, a well-implemented hash table can resize itself to maintain performance, ensuring that operations remain O(1) on average.
  • This scalability is crucial when dealing with large datasets or complex drawings in ARX.

ARX and Hash Tables

In the context of ARX (AutoCAD Runtime Extension), using a hash table to manage and delete duplicate entities is beneficial due to the following reasons:

1.Unique Identification:
  • Each entity can be uniquely identified using a hash value that combines various properties (such as geometry, layer, color, etc.).
  • This unique identification ensures that only truly identical entities are considered duplicates.

2.Performance:

  • AutoCAD drawings can contain thousands or even millions of entities. Using a hash table to manage duplicates ensures that the process remains efficient and does not degrade performance.
  • This efficiency is especially important in complex CAD environments where users require quick and responsive operations.

Sample Code for Removing Duplicate Entities Using a Hash Table
Here’s a corrected and complete code sample in ARX for removing duplicate entities using a hash table:

Code - C++: [Select]
  1. /**
  2.  * @brief Removes duplicate entities, keeping only unique ones.
  3.  *
  4.  * @param objectIdArray Array of entity object IDs
  5.  * @param param Bitmask parameter used for selectively calculating the hash value:
  6.  *  - 1: Use the entity's dxfName
  7.  *  - 2: Use the entity's layerName
  8.  *  - 4: Use the entity's colorIndex
  9.  *  - 8: Use the entity's linetypeName
  10.  *  - 16: Use the entity's linetypeScale
  11.  *  - 32: Use the entity's lineWidth
  12.  *  - 64: Use the entity's GRIP Point array (nStretchPts)
  13.  *  - 128: Use the entity's bounding box (box)
  14.  *  - 256: Use the entity's centroid
  15.  *  - 512: Use the entity's description (entity->desc())
  16.  */
  17. void XdDbUtils::RemoveDuplicateEntities(AcDbObjectIdArray& objectIdArray, int param)
  18. {
  19.     std::unordered_map<size_t, AcDbObjectId> entityHashmap;
  20.     AcDbObjectIdArray remainingObjects;
  21.  
  22.     // Iterate through the entity object array
  23.     for (int i = 0; i < objectIdArray.length(); ++i) {
  24.         AcDbObjectId objectId = objectIdArray[i];
  25.         AcDbEntity* pEntity = nullptr;
  26.         if (acdbOpenAcDbEntity(pEntity, objectId, AcDb::kForRead) == Acad::eOk && pEntity) {
  27.             // Calculate the hash value of the entity
  28.             size_t hash = XdDbUtils::CalculateHash(pEntity, param);
  29.  
  30.             // Check if the hash value already exists in the hash table
  31.             if (entityHashmap.find(hash) == entityHashmap.end()) {
  32.                 // The hash value does not exist, add to the hash table and remainingObjects array
  33.                 entityHashmap[hash] = objectId;
  34.                 remainingObjects.append(objectId);
  35.             }
  36.             // Close the entity
  37.             pEntity->close();
  38.         }
  39.     }
  40.  
  41.     // Replace the original objectIdArray with the remainingObjects array
  42.     objectIdArray = remainingObjects;
  43. }
  44.  

Conclusion

Using a hash table to delete duplicate entities in ARX is highly efficient due to the hash table's fast lookup, insertion, and deletion operations. This efficiency is crucial for maintaining performance in complex AutoCAD environments, ensuring that even large datasets are processed quickly and accurately.

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


Code: [Select]
(defun c:xdtb_removeovents (/ ss len ret)
  (xdrx-begin)
  (if (setq ss (xdrx-ssget
(xdrx-string-multilanguage
   "\n选择要处理的对象<退出>:"
   "\nSelect objects to process <Exit>:"
)
       )
      )
    (progn
      (setq len (sslength ss))
      (setq ret (xdrx-entity-removeduplicates ss 129))
      (xdrx-prompt
(xdrx-string-formatex
  (xdrx-string-multilanguage
    "\n共删除了 %d 个重复的实体."
    "\nA total of %d duplicate entities have been removed."
  )
  (- len ret)
)
      )
    )
  )
  (xdrx-end)
  (princ)
)
9
Hey all,

looking for away to set layers on/off/freeze/thaw  bij filter name.
After alot of searching, i have noluck :-(

the next thing is, try to find the layers that are in a layer filter.

At this moment i'm stuck at the point that ik have the filter names, but no layers.
I have tried to look in to de dxf code's, i just can't find it.

The reason i need this is,  to run a lot of drawings.
And i need the layers on/off by filtername.

thx for the help, John

Code: [Select]
(defun :LayerFilterList (/ :SubFilterList)

  (defun :SubFilterList (dict / ent lst)
    (foreach ent (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 350)) dict))
      (setq lst (append lst
                        (cons ent (if (assoc 360 (entget ent))
                                    (:SubFilterList (entget (cdr (assoc 360 (entget (cdr (assoc 360 (entget ent)))))))))))))
    lst)

  (mapcar '(lambda (x) (cdr (assoc 300 (entget x))))
          (:SubFilterList (dictsearch
                            (vlax-vla-object->ename
                              (vla-getextensiondictionary
                                (vla-get-layers
                                  (vla-get-activedocument
                                    (vlax-get-acad-object)))))
                            "ACLYDICTIONARY"))))


(:LayerFilterList)
10
AutoLISP (Vanilla / Visual) / Re: Solid to surface
« Last post by EnM4st3r on Today at 03:25:38 AM »
you mean like CONVTOSURFACE?
Pages: [1] 2 3 ... 10