Recent Posts

Pages: [1] 2 3 ... 10
1
AutoLISP (Vanilla / Visual) / Lisp to count text in drawing
« Last post by Mjf1999 on Today at 09:15:52 AM »
Hello

I saw the below lisp by Tharwat Al Choufi, it works very well, but it counts all the texts, can it be modified to find/search for a specific text or part of a text (i.e. GL1A or GL1A*)

The link for the lisp is
https://www.theswamp.org/index.php?topic=57209.msg607461#msg607461


Thank you



(defun c:Test (/ s i e l g p b c r)
  ;; Tharwat Al Choufi - Date : 13.Dec.2021     ;;
  (and (setq s (ssget "_X" '((0 . "TEXT,MTEXT"))))
       (repeat (setq i (sslength s))
         (setq i (1- i)
               e (entget (ssname s i))
               l (list (cdr (assoc 1 e)) (cdr (assoc 8 e)))
         )
         (or (and (vl-some (function (lambda (q)
                                       (and (= (car q) (car l))
                                            (= (cadr q) (cadr l))
                                            (setq r q)
                                       )
                                     )
                           )
                           g
                  )
                  (setq g (vl-remove r g)
                        g (cons (append l (list (1+ (caddr r)))) g)
                  )
             )
             (setq g (cons (append l (list 1)) g))
         )
       )
       (setq p (getpoint "\nTable insertion point :"))
       (setq r 1
             b (vla-addtable
                 (vla-get-block
                   (vla-get-activelayout
                     (vla-get-activedocument (vlax-get-acad-object))
                   )
                 )
                 (vlax-3d-point p)
                 (+ 2 (length g))
                 3
                 635
                 3100
               )
       )
       (progn
         (vla-put-RegenerateTableSuppressed b :vlax-true)
         (vla-setcolumnwidth b 2 1300)
         (mapcar '(lambda (r_ c_ s_)
                    (set:text_ b r_ c_ 350 s_)
                  )
                 '(0 1 1 1)
                 '(0 0 1 2)
                 '("STRING COUNT" "String" "Layer" "QTY")
         )
         (foreach s (vl-sort g '(lambda (j k) (< (cadr j) (cadr k))))
           (setq r (1+ r))
           (mapcar '(lambda (c s) (set:text_ b r c 300 s))
                   '(0 1 2)
                   s
           )
         )
         (vla-put-RegenerateTableSuppressed b :vlax-false)
       )
  )
  (princ)
)
(vl-load-com)
;;                              ;;
(defun set:text_ (obj row col hgt str)
  (vla-settext obj row col str)
  (vla-setcelltextheight obj row col hgt)
  (vla-setcellalignment obj row col acmiddlecenter)
)
 
2
Thanks Al, sorry for late reply.. was on the beach all weekend. Works great, I could always filter the midpoints if I wanted to.
3
Nice find!
I was going to say to reverse the polyline and check the paramatpoint again, but the code you found seems to work great.
5
Thanks.

Yes, your code helps if I want to find the intersection point(s). Note: I also have that code and use it often for other purposes but my questions is how can I find its stations/distance from the beginning of polyline. My Task: I need to mark the stations on a profile and my code will only provide the shortest station only.

Here is some code to get a list of intersections.
These are the locations you need to add the extra number.
Hope it's helpful!
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. ; Get Intersections - dexus
  3. ; Returns a list of intersecting points in a polyline
  4. ; @Param poly Ename or vla-object of polyline
  5. ; @Returns List of intersecting points
  6. |;
  7. (defun getIntersections (poly / cords)
  8.   (if
  9.     (and
  10.       (setq poly ; Get (list ename vla-object) of selected object
  11.         (cond
  12.            ((= (type poly) 'vla-object) (list (vlax-vla-object->ename poly) poly))
  13.            ((= (type poly) 'ename) (list poly (vlax-ename->vla-object poly)))
  14.         )
  15.       )
  16.       (vl-position (cdr (assoc 0 (entget (car poly)))) '("POLYLINE" "LWPOLYLINE"))
  17.       (setq cords (getcoords (car poly)))
  18.     )
  19.     (vl-remove-if ; Return list of intersections
  20.       (function (lambda (i) (vl-member-if (function (lambda (cord) (equal cord i 1e-9))) cords))) ; Remove coordinates (vertices)
  21.       (LM:group-n (gc:VariantToLispData (vla-intersectwith (cadr poly) (cadr poly) acExtendNone)) 3) ; Get all intersections
  22.     )
  23.   )
  24. )
  25.  
  26. ;; CAB 08/25/06 - revised 07.25.07
  27. ;; get pline vertex list for any
  28. (defun getcoords (ent / endp idx pt result)
  29.   (setq idx 0
  30.         endp (vlax-curve-getEndParam ent))
  31.   (while (< (setq idx (1+ idx)) endp)
  32.     (setq pt (vlax-curve-getpointatparam ent idx)
  33.           result (cons pt result))
  34.   )
  35.   (reverse (cons (vlax-curve-getendpoint ent) result))
  36. )
  37.  
  38. ;; gc:VariantToLispData - gile
  39. ;; Converts a variant or a safearray into an AutoLISP data
  40. ;; input var = variant or safearray
  41. (defun gc:VariantToLispData (var)
  42.   (cond
  43.     ((= (type var) 'variant)
  44.       (gc:VariantToLispData (vlax-variant-value var)))
  45.     ((= (type var) 'safearray)
  46.       (if (< -1 (vlax-safearray-get-u-bound var 1))
  47.         (mapcar 'gc:VariantToLispData (vlax-safearray->list var))
  48.       )
  49.     )
  50.     (t var)
  51.   )
  52. )
  53.  
  54. ;; Group by Number  -  Lee Mac
  55. ;; Groups a list 'l' into a list of lists, each of length 'n'
  56. (defun LM:group-n ( l n / r )
  57.     (if l
  58.         (cons
  59.             (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
  60.             (LM:group-n l n)
  61.         )
  62.     )
  63. )
6
Here is some code to get a list of intersections.
These are the locations you need to add the extra number.
Hope it's helpful!
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. ; Get Intersections - dexus
  3. ; Returns a list of intersecting points in a polyline
  4. ; @Param poly Ename or vla-object of polyline
  5. ; @Returns List of intersecting points
  6. |;
  7. (defun getIntersections (poly / cords)
  8.   (if
  9.     (and
  10.       (setq poly ; Get (list ename vla-object) of selected object
  11.         (cond
  12.            ((= (type poly) 'vla-object) (list (vlax-vla-object->ename poly) poly))
  13.            ((= (type poly) 'ename) (list poly (vlax-ename->vla-object poly)))
  14.         )
  15.       )
  16.       (vl-position (cdr (assoc 0 (entget (car poly)))) '("POLYLINE" "LWPOLYLINE"))
  17.       (setq cords (getcoords (car poly)))
  18.     )
  19.     (vl-remove-if ; Return list of intersections
  20.       (function (lambda (i) (vl-member-if (function (lambda (cord) (equal cord i 1e-9))) cords))) ; Remove coordinates (vertices)
  21.       (LM:group-n (gc:VariantToLispData (vla-intersectwith (cadr poly) (cadr poly) acExtendNone)) 3) ; Get all intersections
  22.     )
  23.   )
  24. )
  25.  
  26. ;; CAB 08/25/06 - revised 07.25.07
  27. ;; get pline vertex list for any
  28. (defun getcoords (ent / endp idx pt result)
  29.   (setq idx 0
  30.         endp (vlax-curve-getEndParam ent))
  31.   (while (< (setq idx (1+ idx)) endp)
  32.     (setq pt (vlax-curve-getpointatparam ent idx)
  33.           result (cons pt result))
  34.   )
  35.   (reverse (cons (vlax-curve-getendpoint ent) result))
  36. )
  37.  
  38. ;; gc:VariantToLispData - gile
  39. ;; Converts a variant or a safearray into an AutoLISP data
  40. ;; input var = variant or safearray
  41. (defun gc:VariantToLispData (var)
  42.   (cond
  43.     ((= (type var) 'variant)
  44.       (gc:VariantToLispData (vlax-variant-value var)))
  45.     ((= (type var) 'safearray)
  46.       (if (< -1 (vlax-safearray-get-u-bound var 1))
  47.         (mapcar 'gc:VariantToLispData (vlax-safearray->list var))
  48.       )
  49.     )
  50.     (t var)
  51.   )
  52. )
  53.  
  54. ;; Group by Number  -  Lee Mac
  55. ;; Groups a list 'l' into a list of lists, each of length 'n'
  56. (defun LM:group-n ( l n / r )
  57.     (if l
  58.         (cons
  59.             (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
  60.             (LM:group-n l n)
  61.         )
  62.     )
  63. )
7
If an alignment is a self intersecting polyline, how can I get the 2 stations number at the point of intersection?
Picture bellow will give a better explanation.

Note: My code will only get the first station number:

Code: [Select]
(defun c:Foo ()

  (vl-load-com)
  (setq obj (vlax-ename->vla-object (car (entsel "\n. Select an alignment:"))))
  (while (setq pt  (getpoint "\n. Select point at Alignment: \n"))
    (setq ptis  (vlax-curve-getClosestPointTo obj (vlax-curve-getClosestPointTo obj pt T) T))
    (setq stais (vlax-curve-getDistAtPoint obj ptis))
    (princ (strcat "\n. STA = " (rtos stais 2 3)))
   );end of while
   (princ)
)


8
XDRX-API / [XDrX-PlugIn(166)] Handling self-intersecting polylines
« Last post by xdcad on May 28, 2024, 10:51:21 AM »
Code: [Select]
(defun c:xdtb_plreselfcross (/ ss)
  (if (setq ss (xdrx-ssget
(xdrx-string-multilanguage
   "\n选择要处理的多段线<退出>:"
   "\nSelect polylines to process <Exit>:"
)
'((0 . "*polyline"))
       )
      )
    (progn
      (xdrx-polyline-removeselfcrossing ss)
    )
  )
  (princ)
)
9
.NET / Re: How to add breaklines to Civil-3D surface in C#.NET?
« Last post by eddybeerke on May 27, 2024, 03:19:12 AM »
...
Verry intresting topic.

I took some code from it to build my own solution to add multiple breaklines:

Code: [Select]
SelectionSet res = getSelectionSet();
if (res != null)
{
    PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");
    pKeyOpts.Message = "\nEnter the type of breakline to create: ";
    pKeyOpts.Keywords.Add("Standard");
    pKeyOpts.Keywords.Add("Non-Destructive");
    pKeyOpts.Keywords.Add("Proximity");
    pKeyOpts.Keywords.Default = "Standard";
    pKeyOpts.AllowNone = true;
    PromptResult pKeyRes = editor.GetKeywords(pKeyOpts);
    ObjectId[] lines;

    try
    {
        switch (pKeyRes.StringResult)
        {
            case "Non-Destructive":

                // Step through the objects in the selection set
                foreach (ObjectId acSSObj in res.GetObjectIds())
                {
                    lines = new ObjectId[] { acSSObj };
                    oSurface.BreaklinesDefinition.AddNonDestructiveBreaklines(new ObjectIdCollection(lines), 1);
                }
                break;
            case "Proximity":

                // Step through the objects in the selection set
                foreach (ObjectId acSSObj in res.GetObjectIds())
                {
                    lines = new ObjectId[] { acSSObj };
                    oSurface.BreaklinesDefinition.AddProximityBreaklines(new ObjectIdCollection(lines), 1);
                }
                break;
            case "Standard":
            default:
                // Step through the objects in the selection set
                foreach (ObjectId acSSObj in res.GetObjectIds())
                {
                    lines = new ObjectId[] { acSSObj };
                    //oSurface.BreaklinesDefinition.AddStandardBreaklines(new ObjectIdCollection(lines), 10, 5, 5, 0);
                    oSurface.BreaklinesDefinition.AddStandardBreaklines(new ObjectIdCollection(lines), 0.01, 2, 5, 0);
                }
                break;
        }
    }

    catch (System.Exception e)
    {
        editor.WriteMessage("Operation failed: {0}", e.Message);
    }

    // commit the transaction
    ts.Commit();
}
Code: [Select]
public SelectionSet getSelectionSet()
{
    //CivilDocument doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

    // Request for objects to be selected in the drawing area
    PromptSelectionResult acSSPrompt = ed.GetSelection();

    // If the prompt status is OK, objects were selected
    if (acSSPrompt.Status == PromptStatus.OK)
    {
        SelectionSet acSSet = acSSPrompt.Value;
        return acSSet;

    }
    return null;
}

10
.NET / Re: Losing Block Name
« Last post by retsameht on May 27, 2024, 01:10:44 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?

Your question was answered on the Autodesk .NET forum.  You can't prevent the block name from changing, and you shouldn't be relying on the names of anonymous blocks to start with.
Pages: [1] 2 3 ... 10