Recent Posts

Pages: [1] 2 3 ... 10
1
Thank you all for the great suggestions and sorry for the late reply!
Unfortunately none of it worked for me hundred percent, but after some digging and fiddling I found a way to do it.
Thanks to Andrzej Kalinowski who wrote a description of his app https://autolisps.blogspot.com/p/viewporttools.html

To get the correct Viewport ID, you have to cycle through all layouts, that is unavoidable.
But the process takes more time as the number of layers grow in the drawing.
So the key is to freeze all the layers and then go through each layout. After that you can thaw back the layers with LAYERP.

Final simple code (no error trapping):

Code - Auto/Visual Lisp: [Select]
  1. (defun c:avpoff (/ old-ctab ss count ent llc i)
  2.   (setq old-ctab (getvar "ctab"))
  3.   (setq llc (length (layoutlist)))
  4.   (setq llc0 llc)
  5.   (command "-Layer" "freeze" "*" "")
  6.   (acet-ui-progress-init
  7.     (strcat "In progress ( Nr. of layouts " (rtos llc 2 0) " )")
  8.     llc
  9.   )
  10.   (setq i 0)
  11.   (foreach layout (layoutlist)
  12.     (if
  13.       (and (not (= (strcat layout) "MODEL"))
  14.            (setq ss (ssget "x" (list '(0 . "VIEWPORT") (cons 410 layout))))
  15.            (setvar 'ctab layout)
  16.       )
  17.        (progn
  18.          (setq count -1)
  19.          (setq i (1+ i))
  20.          (while (< (setq count (1+ count)) (1- (sslength ss)))
  21.            (setq ent (vlax-ename->vla-object (ssname ss count)))
  22.            (vla-display ent :vlax-false)
  23.            (vla-put-viewporton ent :vlax-false)
  24.            (acet-ui-progress-safe i)
  25.          )                              ;while
  26.        )
  27.     )                                   ;if
  28.   )                                     ;foreach
  29.   (acet-ui-progress-done)
  30.   (setvar 'ctab old-ctab)
  31.   (command "layerp")
  32.   (princ)
  33.   (setvar 'modemacro "")
  34.   (princ "\nDone!")
  35.   (alert "\nAll viewports are ON")
  36.   (princ)
  37. )
  38.  
  39. (defun c:avpon  (/ old-ctab ss count ent llc i)
  40.   (setq old-ctab (getvar "ctab"))
  41.   (setq llc (length (layoutlist)))
  42.   (setq old-layer (getvar 'clayer))
  43.   (command "-Layer" "freeze" "*" "")
  44.   (acet-ui-progress-init
  45.     (strcat "In progress ( Nr. of layouts: "
  46.             (rtos llc 2 0)
  47.             " )"
  48.     )
  49.     llc
  50.   )
  51.   (setq i 0)
  52.   (foreach layout (layoutlist)
  53.     (if
  54.       (and (not (= (strcat layout) "MODEL"))
  55.            (setq ss (ssget "x" (list '(0 . "VIEWPORT") (cons 410 layout))))
  56.            (setvar 'ctab layout)
  57.       )
  58.        (progn
  59.          (setq count -1)
  60.          (setq i (1+ i))
  61.          (while (< (setq count (1+ count)) (1- (sslength ss)))
  62.            (setq ent (vlax-ename->vla-object (ssname ss count)))
  63.            (vla-display ent :vlax-false)
  64.            (vla-put-viewporton ent :vlax-true)
  65.            (acet-ui-progress-safe i)
  66.          )                              ;while
  67.        )
  68.     )                                   ;if
  69.   )                                     ;foreach
  70.   (acet-ui-progress-done)
  71.   (setvar 'ctab old-ctab)
  72.   (command "layerp")
  73.   (princ)
  74.   (setvar 'modemacro "")
  75.   (princ "\nDone!")
  76.   (alert "\nAll viewports are ON")
  77.   (princ)
  78. )
2
Misunderstanding? Let’s say I have a key that’s a string, and a value that starts with a DXF code
(‘(“A”), ‘(11 11))
  Key       Value

Now I want to retrieve the value of ‘(“A”), I will get back (11.0 11.0 0.0). The value is wrong
I wanted two integers back, but I get back 3 doubles

Here’s another example of a valiant attempt to extend lisp
https://www.theswamp.org/index.php?topic=45841.msg618986#msg618986

It’s very unfortunate


3
My point is, you can’t use certain lists in the ‘value’ part of the map either, because what you put in, is not the same as what you get out

MapInsert ('(KEY) ‘(10 10)) may return ‘(10 10 0)
MapInsert ('(KEY) ‘(220 220 220 220))  LsAdsInvoke Internal Error

‘(220 220 220 220) This kind, because it is a BUG, cannot be passed from LISP to ARX at all, let’s not discuss it first.
'(10 10), when passed to ARX, will become a 3D point of '(10.0 10.0 0.0),
Insert into MAP, so '(10 10) under LISP can also query the index position INDEX through '(10.0 10.0 0.0), and then return the index to LISP for processing'(10 10)
4
My point is, you can’t use certain lists in the ‘value’ part of the map either, because what you put in, is not the same as what you get out

MapInsert ('(KEY) ‘(10 10)) may return ‘(10 10 0)
MapInsert ('(KEY) ‘(220 220 220 220))  LsAdsInvoke Internal Error
5
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

'(220.0 220.0 220.0) and  '(210 220.0 220.0 220.0)

What I said about adding restype to hash calculation is to address the above points.
Within ARX, they are all considered to be 3D points. If calculated directly, their hash values will be the same.

======

Command: (xdrx_entity_hashstring '(220.0 220.0 220.0))
"17095823065452309527"
Command: (xdrx_entity_hashstring '(210 220.0 220.0 220.0))
"6635585597989606581"
6
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.  
7
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

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