Recent Posts

Pages: [1] 2 3 ... 10
1
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. )
2
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)
)


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

5
.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.
6
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. )
7
AutoLISP (Vanilla / Visual) / Re: Solid to surface
« Last post by ScottMC on May 24, 2024, 05:33:54 PM »
Is it a region? Another option Amarulu would be solidedit/face/copy and pick on the edge of the inner segment...
8
>>>>>
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




Yes, unfortunate is an understatement.  I'm baffled why AutoDesk can't provide a valid round-trip mechanism for values.

Really, really frustrating not being able to maintain the integrity of data.
9
AutoLISP (Vanilla / Visual) / Re: Turn all layout viewports ON-OFF in a drawing
« Last post by Ndruu on May 24, 2024, 12:04:26 PM »
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. )
10
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


Pages: [1] 2 3 ... 10