Recent Posts

Pages: [1] 2 3 ... 10
1
Thanks Al, sorry for late reply.. was on the beach all weekend. Works great, I could always filter the midpoints if I wanted to.
2
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.
4
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. )
5
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
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)
)


7
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)
)
8
.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;
}

9
.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.
10
Efficiency test, 510 entities, including 505 duplicate entities

Hash table efficiency far exceeds overkill

 

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

Command: tt
Select objects: Specify opposite corner: 510 found

Select objects:

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

Command: (tt1)

CPU:(1x)Intel(R) Xeon(R) E3-1575M v5 @ 3.00GHz 4Cores  / Memory:64G / OS: WIN10 professional workstation version
Benchmarking ......
Current settings: Tolerance=0.000001, Ignore=None, Optimize polylines=Yes, Combine partial overlap=Yes, Combine end-to-end=Yes
505 duplicate(s) deleted
0 overlapping object(s) or segment(s) deleted. done for 16 iterations. Sorted from fastest.
Statement                    Increment  Time(ms)  Normalize  Relative
-------------------------------------------------------------------------------
(xdrx-entity-removeduplic...)       16      1078         1078     28.07 <fastest>
(COMMAND ._-overkill SS  )          1       1891      30256       1.00 <slowest>
-------------------------------------------------------------------------------

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if (setq ss (ssget))
  3.     (progn
  4.      (setq ss1 (xdrx-entity-copy ss))
  5.     )
  6.   )
  7.   (princ)
  8. )
  9. (defun tt1 ()
  10.   (xd::quickbench
  11.     '((command "._-overkill" ss "" "")
  12.       (xdrx-entity-removeduplicates ss1 129)
  13.      )
  14.   )
  15.   (princ)
  16. )
Pages: [1] 2 3 ... 10