Recent Posts

Pages: [1] 2 3 ... 10
1
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. void XdDbUtils::RemoveDuplicateEntities(AcDbObjectIdArray& objectIdArray, int param)
  2. {
  3.     std::unordered_map<size_t, AcDbObjectId> entityHashmap;
  4.     AcDbObjectIdArray remainingObjects;
  5.  
  6.     // Iterate through the entity object array
  7.     for (int i = 0; i < objectIdArray.length(); ++i) {
  8.         AcDbObjectId objectId = objectIdArray[i];
  9.         AcDbEntity* pEntity = nullptr;
  10.         if (acdbOpenAcDbEntity(pEntity, objectId, AcDb::kForRead) == Acad::eOk && pEntity) {
  11.             // Calculate the hash value of the entity
  12.             size_t hash = XdDbUtils::CalculateHash(pEntity, param);
  13.  
  14.             // Check if the hash value already exists in the hash table
  15.             if (entityHashmap.find(hash) == entityHashmap.end()) {
  16.                 // The hash value does not exist, add to the hash table and remainingObjects array
  17.                 entityHashmap[hash] = objectId;
  18.                 remainingObjects.append(objectId);
  19.             }
  20.             // Close the entity
  21.             pEntity->close();
  22.         }
  23.     }
  24.  
  25.     // Replace the original objectIdArray with the remainingObjects array
  26.     objectIdArray = remainingObjects;
  27. }
  28.  

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)
)
2
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)
3
AutoLISP (Vanilla / Visual) / Re: Solid to surface
« Last post by EnM4st3r on Today at 03:25:38 AM »
you mean like CONVTOSURFACE?
4
When I was wrapping BrxCvCivil3d for python, I noticed a converter class, I haven't tried it yet

Code - C++: [Select]
  1. void makePyBrxCvCivil3dConverterWrapper()
  2. {
  3.     PyDocString DS("CvCivil3dConverter");
  4.     class_<PyBrxCvCivil3dConverter>("CvCivil3dConverter")
  5.         .def(init<>())
  6.         .def(init<const PyDbDatabase&, PyDbDatabase&, BrxCvCivil3dConverter::Civil3dLabels>(DS.CTOR(ctor)))
  7.         .def("getCivilEntities", &PyBrxCvCivil3dConverter::getCivilEntities, DS.ARGS())
  8.         .def("convert", &PyBrxCvCivil3dConverter::convert, DS.ARGS({ "entitiesToConvert : list" }))
  9.         .def("attachedLabels", &PyBrxCvCivil3dConverter::attachedLabels, DS.ARGS({ "civilEntity: PyBrxCv.CvCivil3dEntityInfo" }))
  10.         .def("unattachedLabels", &PyBrxCvCivil3dConverter::unattachedLabels, DS.ARGS())
  11.         .def("getInsertedEntities", &PyBrxCvCivil3dConverter::getInsertedEntities, DS.ARGS())
  12.         .def("className", &PyBrxCvCivil3dConverter::className, DS.SARGS()).staticmethod("className")
  13.         ;
  14. }
  15.  
It’s probably available in BRX, .NET too. Not sure about lisp, i'm sure there's a command
5
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by BIGAL on May 22, 2024, 10:00:36 PM »
Should you be using SSGET filters ? Or are you asking about SSGET "W" "F" "CP" etc. Not sure why you would need pauses, you can do multiple SSGET and use SSADD to make a final selection set. Say select blocks then select plines using filters.

We are guessing. More detail needed.
6
If I remember correctly, the property set can be found but using a particular CIV3D DLL not sure if Bricscad has the same function. I would join the Bricscad forum they are very helpful and actual Bricscad staff respond at times or put in a support request, again they do answer back.
7
AutoLISP (Vanilla / Visual) / Re: Select all layer change to single layer
« Last post by BIGAL on May 22, 2024, 09:52:34 PM »
This is posted else where and the additional request was don't change "Light Furniture" I think it was Forums/autodesk. Also change all nested blocks.

A nuisance when posted at multiple forums.
8
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by Lee Mac on May 22, 2024, 05:56:11 PM »
You can issue the pause in a loop in which the test expression checks whether the command remains active, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (command "_.pline")
  2. (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))

However, for retrieval of a selection this should not be necessary, as you can simply use (ssget)
9
AutoLISP (Vanilla / Visual) / Solid to surface
« Last post by Amarulu on May 22, 2024, 02:58:58 PM »
Hi,

Question, is there a direct procedure to get a surface form a solid but the obtained surface shall be in the centre of the solid? In. example for a bracket generated as a solid shall be a surface only showing the bracket shape but with the thickness =0.
10
AutoLISP (Vanilla / Visual) / Multiple pause
« Last post by w64bit on May 22, 2024, 01:15:25 PM »
Is there any way to add multiple pause, which should work until I click enter (used when select)?
I am using now 20-30 pause words to cover all situations.
Pages: [1] 2 3 ... 10