Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
jbear0000
Posts: 343
Registered: ‎07-25-2006
Message 1 of 9 (1,953 Views)
Accepted Solution

Insert block at intersection

1953 Views, 8 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.

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)
  )

Valued Mentor
stevor
Posts: 881
Registered: ‎12-26-2005
Message 2 of 9 (1,923 Views)

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
Mentor
diagodose2009
Posts: 263
Registered: ‎12-04-2009
Message 3 of 9 (1,910 Views)

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...........
Distinguished Mentor
scottbolton
Posts: 645
Registered: ‎08-30-2005
Message 4 of 9 (1,890 Views)

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)
  )

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 9 (1,880 Views)

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
Mentor
jbear0000
Posts: 343
Registered: ‎07-25-2006
Message 6 of 9 (1,875 Views)

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.

Distinguished Mentor
scottbolton
Posts: 645
Registered: ‎08-30-2005
Message 7 of 9 (1,873 Views)

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

New Member
saurabhshp05
Posts: 1
Registered: ‎07-06-2014
Message 8 of 9 (477 Views)

Re: Insert block at intersection

07-06-2014 08:36 PM in reply to: scottbolton
sir i am a newbee in autolisp.. can u plz brief me how to use all the vla commands... & what is the use of vlax-safearray-... command. thanks
Distinguished Contributor pli
Distinguished Contributor
pli
Posts: 143
Registered: ‎11-19-2012
Message 9 of 9 (404 Views)

Re: Insert block at intersection

07-14-2014 11:48 AM in reply to: saurabhshp05

You can read up on vla- & vlax- functions by doing a search on-line or in acad help.

So in acad, you can type .HELP and do a search for vlax-safearray

Paul Li
Senior Associate
ALTOON PARTNERS LLP
Los Angeles • Amsterdam • Shanghai
617 West 7th Street • Suite 400 • Los Angeles • California • 90017-3889
D +1 213 225 1944 • T +1 213 225 1900 • www.altoonpartners.com
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post