Jump to content

Pls Help :) Lisp that detects if Polylines (Layer 1, 2, 3) is inside PL (Layer 1)


digitalmapper

Recommended Posts

Hi guys. I've been trying to find a lisp that detects if layer specified polylines are inside another layer specified polyline.

 

I want to check if closed polylines under layers (Layer 1, Layer 2 & Layer 3..) is inside a closed polyline under Layer 4.

 

I hope someone gets what im saying. The best I can do in AutoCAD is creating macros and this cannot be done by that :D

Link to comment
Share on other sites

Hi,

 

Be sure to have the selected polyline's border completely seen in the screen otherwise the program may fail or not detect all polyline objects.

(defun c:test (/ sn ss dis div s in l)
 (princ "\nPick a closed polyline :")
 (if (setq s (ssget "_+.:S:E" '((0 . "*POLYLINE") (8 . "Layer4") (-4 . "&=") (70 . 1))))
   (progn
     (setq sn  (ssname s 0)
           dis (/ (vlax-curve-getdistatparam
                    sn
                    (fix (vlax-curve-getendparam sn))
                  )
                  100.
               )
           div dis
     )
     (repeat 100
       (setq l (cons (vlax-curve-getpointatdist sn dis) l))
       (setq dis (+ div dis))
     )
     (if (setq
           ss (ssget "_WP"
                     l
                     '((0 . "*POLYLINE") (8 . "Layer1,Layer2,Layer3"))
              )
         )
       (sssetfirst nil ss)
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

That was fast Tharwat. :o

 

While the program is good, would it be possible to prompt an error message if any of the polylines under Layer 1, 2 or 3 is not completely inside Layer 4?

Link to comment
Share on other sites

That was fast Tharwat. :o

 

While the program is good, would it be possible to prompt an error message if any of the polylines under Layer 1, 2 or 3 is not completely inside Layer 4?

:)

 

Try this:

(defun c:test (/ lays fnd sn ss dis div s lst lay l)
 ;; Tharwat - 07.Dec.2016 ;;
 (princ "\nPick on closed polyline :")
 (if (setq lays "Layer1,Layer2,Layer3"
           fnd  0
           s    (ssget "_+.:S:E"
                       '((0 . "*POLYLINE") (8 . "Layer4") (-4 . "&=") (70 . 1))
                )
     )
   (progn
     (setq sn  (ssname s 0)
           dis (/ (vlax-curve-getdistatparam
                    sn
                    (fix (vlax-curve-getendparam sn))
                  )
                  100.
               )
           div dis
     )
     (repeat 100
       (setq l (cons (vlax-curve-getpointatdist sn dis) l))
       (setq dis (+ div dis))
     )
     (if (setq
           ss (ssget "_WP" l (list '(0 . "*POLYLINE") (cons 8 lays)))
         )
       (while (and (/= fnd 3)
                   (setq sn (ssname ss 0))
              )
         (and (wcmatch (setq lay (cdr (assoc 8 (entget sn)))) lays)
              (not (member lay lst))
              (setq lst (cons lay lst))
              (setq fnd (length lst))
         )
         (ssdel sn ss)
       )
     )
     (cond
       ((= fnd 3) (princ "\nAll layers are found "))
       ((>= fnd 1)
        (princ
          (strcat
            "\nPolylines' layers ["
            (vl-string-right-trim
              ","
              (apply 'strcat (mapcar '(lambda (u) (strcat u ",")) lst))
            )
            "]."
          )
        )
       )
       ((princ "\nNo polylines found on specified layers <!>"))
     )
   )
 )
 (princ)
)(vl-load-com)

Link to comment
Share on other sites

Works great! Thank you! 8):D

 

One quick question though, how do i change "Select Objects:" to "Select Object:" since I will only be selecting one :)

Link to comment
Share on other sites

Works great! Thank you! 8):D

 

One quick question though, how do i change "Select Objects:" to "Select Object:" since I will only be selecting one :)

 

Use entsel/nentsel instead of ssget, and modify half of the code. :D

Link to comment
Share on other sites

Apparently there is a way to suppress the default ssget prompt (but I don't think it works well in BricsCAD).

(prompt ...)
(setvar 'nomutt 1)
(ssget ...)
(setvar 'nomutt 0)

Link to comment
Share on other sites

I have another concern, when one or more polylines under (Layer1, Layer2, Layer3) are on top of Layer4, I want it to be considered as inside the polyline. It will just exclude it if it is outside.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...