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

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.
2
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.  
3
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))
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. (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

5
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.
6
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)
)









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

9
.NET / Losing Block Name
« Last post by kshitij.jadhav@cctech.co. on May 23, 2024, 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?
10
AutoLISP (Vanilla / Visual) / Re: Multiple pause
« Last post by w64bit on May 23, 2024, 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 "\\"))
Pages: [1] 2 3 ... 10