• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Mentor
    Posts: 337
    Registered: ‎07-25-2006
    Accepted Solution

    Insert block at intersection

    937 Views, 6 Replies
    06-22-2011 08:10 AM

    Does anyone know of a lisp that will insert a block at the intersection points of multiple lines or polylines? Basically it would ask you to select polylines or lines, then check to see where their intersections are with each other and insert a block at those points. See the attached image for what I am looking for.

    Please use plain text.
    Mentor
    Posts: 769
    Registered: ‎12-26-2005

    Re: Insert block at intersection

    06-22-2011 02:09 PM in reply to: jbear0000

    Two ways, starting with ssget "c" or "f":

     

    1. Close the pline, by pedit if the ends are close enough, or add a pline to do so, and use it to ssget the crossing 'yellow' lines, and find the on-seg intersections of them with the pline; or

     

    2. process each segment of the pline with a narrow ssget to find the crossing lines in that segment, so on.

    S
    Please use plain text.
    Mentor
    Posts: 247
    Registered: ‎12-04-2009

    Re: Insert block at intersection

    06-22-2011 05:02 PM in reply to: jbear0000
    Please , you attach here drawing file
    one demonstration...
    I use this file ( who attached) for make you program requested LISP/ARX..
    Thanks...........
    Please use plain text.
    Valued Mentor
    Posts: 633
    Registered: ‎08-30-2005

    Re: Insert block at intersection

    06-23-2011 12:53 AM in reply to: jbear0000

    How's about this? Pick the main line (red), pick the crossing lines (yellow) and Bob's your aunty.

     

    S

     

    (defun c:sbx ( / )
      (progn
        (setq ent (car (entsel "\nSelect main line: ")))
        (if ent
          (progn
     (princ "\nSelect crossing line(s): ")
     (if (setq ss (ssget))
       (progn
         (setq count 0
        obj (vlax-ename->vla-object ent)
        pointlist nil
        )
         (repeat (sslength ss)
           (setq xent (ssname ss count)
          xobj (vlax-ename->vla-object xent)
          )
           (if (setq int (vla-IntersectWith obj xobj acExtendNone))
      (progn
        (setq int (vlax-safearray->list (vlax-variant-value int))
       pointlist (append pointlist (list int))
       )
        )
      )
           (setq count (1+ count))
           )
         (if (null (tblobjname "BLOCK" "SBblock"))
           (progn
      (entmake (list (cons 0 "BLOCK") (cons 2 "SBblock") (cons 70 0) (list 10 0.0 0.0 0.0)))
      (entmake '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (8 . "0") (100 . "AcDbPolyline") (90 . 2) (70 . 1) (43 . 1.0) (38 . 0.0) (39 . 0.0)
          (10 2.5 0.0) (40 . 1.0) (41 . 1.0) (42 . 1.0) (91 . 0)
          (10 -2.5 0.0) (40 . 1.0) (41 . 1.0) (42 . 1.0) (91 . 0)
          (210 0.0 0.0 1.0)
          )
        )
      (setq blockname (entmake '((0 . "ENDBLK"))))
      )
           )
         (foreach pt_nth pointlist
           (entmake (append
        '((0 . "INSERT") (100 . "AcDbEntity") (8 . "0") (100 . "AcDbBlockReference") (2 . "SBblock"))
        (list (cons 10 pt_nth))
        '((41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
        )
             )
           )
         )
       )
     )
          )
        )
      (princ)
      )

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,371
    Registered: ‎10-08-2008

    Re: Insert block at intersection

    06-23-2011 05:18 AM in reply to: scottbolton

    Good work,

    Just forgot to add

    (vl-load-com) at the start of code,

    do edition, please,

     

    Regards

    :smileyhappy:

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Mentor
    Posts: 337
    Registered: ‎07-25-2006

    Re: Insert block at intersection

    06-23-2011 05:34 AM in reply to: scottbolton

    Thanks scottbolton, that works great. I simiply changed the block name in the lisp and added (vl-load-com) to the beginning as Hallex pointed out and it worked. Thanks for the help.

    Please use plain text.
    Valued Mentor
    Posts: 633
    Registered: ‎08-30-2005

    Re: Insert block at intersection

    06-23-2011 05:38 AM in reply to: jbear0000

    You're welcome.

     

    I use many vl-commands in many routines and so I have (vl-load-com) in my acaddoc.lsp.

     

    S

    Please use plain text.