Jump to content

Help with modification of lisp (filter out closed polylines)


Radu Iordache

Recommended Posts

The attached lisp selects all polylines in a drawing (open or closed) and writes a coordinate list for each one in a file. I need to modify the lisp so it will do the job for open polylines only. The closed polylines should be filtered out (not included in the output file). Can anybody help?

Thanks in advance!

coolist.lsp

Link to comment
Share on other sites

HI

TRY

POLYLINE DXF Group code 70

 

;;;==================================================


(vl-load-com) ; initialization 

(defun getcoords ( en / coordslst )
  (setq coordslst (list))
  (setq enlst (entget en))
  (foreach x enlst
    (if (= (car x) 10)
      (setq coordslst (append coordslst (list (cdr x))))
    ) ; end if
  ) ; end foreach
 coordslst
)

;;;==================================================


(defun c:coolist (/ xml file)

  (setq fname "D:/coo.xml")

  (setq file (open fname "w"))

  (cgpolydesc)

  (close file)
  
  (startapp "notepad.exe" fname)
  
) ;_ end of defun


;;;==================================================


(defun cgpolydesc (/ lst ss i en obj)
  (and (setq ss (ssget "X"
          '((0 . "LWPOLYLINE") ; object Name
            (-4 . "&=") ; bit coded
            (70 . 1) ; polylines are OPEN OR CLOSED
           )
          ) 
        )
        
  (repeat (setq i (sslength ss))
    (setq en  (ssname ss (setq i (1- i)))
      obj (vlax-ename->vla-object en)
    )

      ;----

      (setq lst (getcoords en))
      (setq idx 0)
      (setq xy "")
      (repeat (length lst)

        (setq xy (strcat xy (rtos (cadr (nth idx lst)) 2 8) "," (rtos (car (nth idx lst)) 2 8) " "))

        (setq idx (+ 1 idx))
      )
      (write-line (strcat (vl-string-trim ", " xy)) file)

      ;----

    )
  )
) ;_ end of defun 'cgpolydesc'


;;;==================================================


 

3.jpg

  • Like 1
Link to comment
Share on other sites

19 minutes ago, hosneyalaa said:

HI

TRY

POLYLINE DXF Group code 70

 

;;;==================================================


(vl-load-com) ; initialization 

(defun getcoords ( en / coordslst )
  (setq coordslst (list))
  (setq enlst (entget en))
  (foreach x enlst
    (if (= (car x) 10)
      (setq coordslst (append coordslst (list (cdr x))))
    ) ; end if
  ) ; end foreach
 coordslst
)

;;;==================================================


(defun c:coolist (/ xml file)

  (setq fname "D:/coo.xml")

  (setq file (open fname "w"))

  (cgpolydesc)

  (close file)
  
  (startapp "notepad.exe" fname)
  
) ;_ end of defun


;;;==================================================


(defun cgpolydesc (/ lst ss i en obj)
  (and (setq ss (ssget "X"
          '((0 . "LWPOLYLINE") ; object Name
            (-4 . "&=") ; bit coded
            (70 . 1) ; polylines are OPEN OR CLOSED
           )
          ) 
        )
        
  (repeat (setq i (sslength ss))
    (setq en  (ssname ss (setq i (1- i)))
      obj (vlax-ename->vla-object en)
    )

      ;----

      (setq lst (getcoords en))
      (setq idx 0)
      (setq xy "")
      (repeat (length lst)

        (setq xy (strcat xy (rtos (cadr (nth idx lst)) 2 8) "," (rtos (car (nth idx lst)) 2 8) " "))

        (setq idx (+ 1 idx))
      )
      (write-line (strcat (vl-string-trim ", " xy)) file)

      ;----

    )
  )
) ;_ end of defun 'cgpolydesc'


;;;==================================================


 

3.jpg

Thanks but 70.1 will select only closed polylines. I need the opposite, to select only the ones that are NOT closed. One way would be to select all of them (by 70.0) and then filter out the closed ones (by 70.1) but I don't know how to do that. I am a lisp user, unfortunately not a programmer. 

Link to comment
Share on other sites

43 minutes ago, Radu Iordache said:

Thanks but 70.1 will select only closed polylines. I need the opposite, to select only the ones that are NOT closed. One way would be to select all of them (by 70.0) and then filter out the closed ones (by 70.1) but I don't know how to do that. I am a lisp user, unfortunately not a programmer. 

 

I'm sorry @Radu Iordache

look at this

 

 

Link to comment
Share on other sites

35 minutes ago, hosneyalaa said:

 

I'm sorry @Radu Iordache

look at this

 

 

Thank you. I found some ideas there but finaly solved it like this:

(defun cgpolydesc (/ lst ss i en obj)
  (and (setq ss (ssget "X"
          '((0 . "LWPOLYLINE") ; object Name
            (-4 . "<NOT") (70 . 1) (-4 . "NOT>"); polylines NOT CLOSED
           )
          ) 
        )
        
  (repeat (setq i (sslength ss))
    (setq en  (ssname ss (setq i (1- i)))
      obj (vlax-ename->vla-object en)
    )

 

  • Like 1
Link to comment
Share on other sites

You must prefered the bitwise "&" because you can have the bit typelinegen and closed (70 . 129)

(setq ss
  (ssget "_X"
    '(
      (0 . "LWPOLYLINE")
      (-4 . "<NOT")
        (-4 . "&") (70 . 1)
      (-4 . "NOT>")
    )
  )
)

See the help

Edited by Tsuky
  • Like 1
Link to comment
Share on other sites

3 hours ago, Tsuky said:

You must prefered the bitwise "&" because you can have the bit typelinegen and closed (70 . 129)

(setq ss
  (ssget "_X"
    '(
      (0 . "LWPOLYLINE")
      (-4 . "<NOT")
        (-4 . "&") (70 . 1)
      (-4 . "NOT>")
    )
  )
)

See the help

Thanks, done!

Link to comment
Share on other sites

On 11/3/2023 at 9:18, Radu Iordache said:

¡Gracias, listo!

;
  ; Check for open polylines
  ; (c) 2009 Lee Mac   
  ;
(defun c:GetLwClsd  (/ ss) ; Notice that *flag_def* is not localised, as it is a global variable
 
  (or *flag_def* (setq *flag_def* "Open")) ;; Set first-time default
 
  (initget "Open Closed") ; Only allow these values, allow enter also
 
  (setq *flag_def*
    (cond ((getkword
             (strcat "\nLooking for [O]pen or [C]losed LWPolylines? <" *flag_def* "> : ")))
          ;; Either a keyword has been entered, hence set it as the new default
         
          (t *flag_def*))) ;; Else use the original default
 
  (if (setq ss
        (ssget "_X"
          (list (cons 0 "LWPOLYLINE")
                (cons 8 (getvar "CLAYER"))
                (cons -4 "<OR")
                (cons 70 (cond ((eq *flag_def* "Open") 0)   (t 1)))
                (cons 70 (cond ((eq *flag_def* "Open") 128) (t 129)))
                (cons -4 "OR>"))))
   
    (progn
      (foreach ent  (mapcar 'cadr (ssnamex ss))
        (setq lay (tblsearch "LAYER" (cdr (assoc 8 (entget ent)))))
        (if (or (eq 1 (logand 1 (cdr (assoc 70 lay))))
                (eq 4 (logand 4 (cdr (assoc 70 lay)))))
          (ssdel ent ss)))
      (princ (strcat "\n" (itoa (sslength ss)) " found."))
      (sssetfirst nil ss))
    (princ "\n<< nothing found >>"))
  (princ))
(textscr) ; bring text-window to front and inform user
(princ "\nSearching LW-Polylines at curent layer.
          Note: splines, curved fit, and 3D plines
          will not work\nStart with mit << GetLwClsd >>")

Edited by DAVID_OJEDA
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...