Author Topic: selection (ssget)?  (Read 2554 times)

0 Members and 1 Guest are viewing this topic.

iradic

  • Guest
selection (ssget)?
« on: September 25, 2006, 11:39:53 AM »
Hi...

I modified existing - old lisp ... to join lines arcs and plines.

It uses ssget to get objects to join. Now how do I check what happened to objects in selection set (how many objects joined)? My guess is if they are still in drawing then they are not joined right?

Here is the code...
Code: [Select]
;;;   PJOIN.LSP  V1.1 by Zoltan Toth
;;;
;;;   Description:
;;;   This program takes any number of LINES, ARCS and/or
;;;   LWPOLYLINES and joins
;;;   them into a single LWPOLYLINE if the objects are contiguous.
;;;

;; define program name & localize variables
(defun c:pjoin (/ sfirst sset ename etype
                 *error* oldcmd
                 )
  (defun *error* (s / enum)
    (setq enum (itoa (getvar "errno")))
    (command)(command)
    (command "._undo" "_end")
    (if (not (member s '(nil "console break" "Function canelled" "quit / exit abort")))
      (progn
        (princ (strcat "\nError: # " enum " - " s
                       "\nUndoing..."))
        (command "._undo" "1")
        )
      )
    (if oldcmd (setvar "cmdecho" oldcmd))
    )

  (setq oldcmd (getvar "CMDECHO")) ;save current command echo status
  (setvar "cmdecho" 0) ;turn off command echoing
  (command "._undo" "_group") ;start undo group

  ;; get objects to join into a single LWPOLYLINE
  (prompt "\nSelect first object:")
  (setq sfirst nil)
  (while (not sfirst)
         (if (not (setq sfirst (ssget "_:S" '((-4 . "<OR")
                                              (0 . "LINE")
                                              (0 . "LWPOLYLINE")
                                              (0 . "ARC")
                                              (-4 . "OR>")))))
           (princ "\nSelect LINE, LWPOLINE or ARC...")
           )
         )
  (prompt "\nSelect objects to join into a polyline:")
  (setq sset
        (ssget '((-4 . "<OR")
                 (0 . "LINE")
                 (0 . "LWPOLYLINE")
                 (0 . "ARC")
                 (-4 . "OR>")))
        )
  (if (and sset sfirst)
    (progn
      (setq ename (ssname sfirst 0)) ;get name of first object
      (setq etype (cdr (assoc 0 (entget ename)))) ;get object type
      (ssadd ename sset)

      ;; if first object is a LWPOLYLINE ...
      (if (= "LWPOLYLINE" etype)
        ;; then: join objects into POLYLINE
        (command "._PEDIT" ename "_J" sset "" "")
        ;; else: convert object and join them
        (command "._PEDIT" ename  "_Y" "_J" sset "" "")
        )
      )
    (prompt "\nNo objects selected.")
    )

  (*error* nil)
  (princ)
  )

daron

  • Guest
Re: selection (ssget)?
« Reply #1 on: September 25, 2006, 02:13:49 PM »
You're joining them through command options. Autocad is taking care of removing the old objects for you, so no, they are not still in the drawing. They've been removed. However, if what you're asking is how to know how many objects are joined in order to princ that to the command line at the end, place a (setq amount (sslength ssget)) before the first if statement and a (princ (strcat "\n" (itoa amount) " objects joined")) just before the *error* portion or somewhere in there.

iradic

  • Guest
Re: selection (ssget)?
« Reply #2 on: September 25, 2006, 02:47:13 PM »
Thanks...

But I don't think it will return number of joined objects ... just the number of object in sset - that doesn't mean they are joined.
It seems they are still in sset after command "pedit" is done no matter they are not in the drawing anymore...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: selection (ssget)?
« Reply #3 on: September 25, 2006, 03:08:46 PM »
Maybe check the amount of vertices before you issue the pedit command for the pline you are going to select, and then check it after.  If it had two before, and three after, then one got joined.

/idea
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: selection (ssget)?
« Reply #4 on: September 25, 2006, 03:49:26 PM »
Maybe this.

Code: [Select]
;;;   PJOIN.LSP  V1.1 by Zoltan Toth
;;;
;;;   Description:
;;;   This program takes any number of LINES, ARCS and/or
;;;   LWPOLYLINES and joins
;;;   them into a single LWPOLYLINE if the objects are contiguous.
;;;

;; define program name & localize variables
(defun c:pjoin (/ sfirst sset ename etype
                 *error* oldcmd
                 )
  (defun *error* (s / enum)
    (setq enum (itoa (getvar "errno")))
    (command)(command)
    (command "._undo" "_end")
    (if (not (member s '(nil "console break" "Function canelled" "quit / exit abort")))
      (progn
        (princ (strcat "\nError: # " enum " - " s
                       "\nUndoing..."))
        (command "._undo" "1")
        )
      )
    (if oldcmd (setvar "cmdecho" oldcmd))
    )

  (setq oldcmd (getvar "CMDECHO")) ;save current command echo status
  (setvar "cmdecho" 0) ;turn off command echoing
  (command "._undo" "_group") ;start undo group

  ;; get objects to join into a single LWPOLYLINE
  (prompt "\nSelect first object:")
  (setq sfirst nil)
  (while (not sfirst)
         (if (not (setq sfirst (ssget "_:S" '((-4 . "<OR")
                                              (0 . "LINE")
                                              (0 . "LWPOLYLINE")
                                              (0 . "ARC")
                                              (-4 . "OR>")))))
           (princ "\nSelect LINE, LWPOLINE or ARC...")
           )
         )
  (prompt "\nSelect objects to join into a polyline:")
  (setq sset
        (ssget '((-4 . "<OR")
                 (0 . "LINE")
                 (0 . "LWPOLYLINE")
                 (0 . "ARC")
                 (-4 . "OR>")))
        )
  (if (and sset sfirst)
    (progn
      (setq ename (ssname sfirst 0)) ;get name of first object
      (setq etype (cdr (assoc 0 (entget ename)))) ;get object type
      (ssadd ename sset)
      (setq cnt 0)

      ;; if first object is a LWPOLYLINE ...
      (if (= "LWPOLYLINE" etype)
        (progn
          (setq cnt (1+ cnt))
        ;; then: join objects into POLYLINE
        (command "._PEDIT" ename "_J" sset "" "")
        )
        ;; else: convert object and join them
        (command "._PEDIT" ename  "_Y" "_J" sset "" "")
        )
      ;;  check for deleted enames
       (setq i -1)
       (while (setq ename (ssname sset (setq i (1+ i))))
         (or (entget ename) (setq cnt (1+ cnt)))
       )
      (prompt (strcat "\nNumber of objects joined is " (itoa cnt) ))
      )
    (prompt "\nNo objects selected.")
    )

  (*error* nil)
  (princ)
  )
« Last Edit: September 25, 2006, 03:52:56 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

sinc

  • Guest
Re: selection (ssget)?
« Reply #5 on: September 25, 2006, 04:27:39 PM »
As near as I can make out, the only purpose of this routine is to suppress the message that asks you "Object is not a polyline; do you want to turn it into one?" when you have lines or arcs in your selection set.  Is that the case?

If so, you can get the same effect by just setting PEDITACCEPT to 1.  Then the behavior of PEDIT JOIN is same as in this routine, and this routine is not needed.

iradic

  • Guest
Re: selection (ssget)?
« Reply #6 on: September 25, 2006, 05:08:14 PM »
Thanks for the solution ... and the tip...

'cnt' should be initialized too...

Thanks again

iradic

  • Guest
Re: selection (ssget)?
« Reply #7 on: September 26, 2006, 03:51:34 AM »
Here is the final version:

Code: [Select]
;;;   Based on PJOIN.LSP v1.1 by Zoltan Toth
;;;
;;;   Description:
;;;   This program takes any number of LINES, ARCS and/or LWPOLYLINES,
;;;   joins them into a single LWPOLYLINE if the objects are contiguous
;;;   and reports number of joined objects.
;;;

;;; define program name & localize variables
(defun c:pjoin (/ sfirst sset ename etype i cnt)

  ;; get objects to join into a single LWPOLYLINE
  (prompt "\nSelect first object:")
  (setq sfirst nil)
  (while (not (setq sfirst
                    (ssget "_:S" '((-4 . "<OR")
                                   (0 . "LINE")
                                   (0 . "LWPOLYLINE")
                                   (0 . "ARC")
                                   (-4 . "OR>")))))
         (princ " Select LINE, LWPOLINE or ARC...")
         )

  (setq ename (ssname sfirst 0)) ;get name of first object
  (redraw ename 3)

  (prompt "\nSelect objects to join into a polyline:")
  (while (not (setq sset
                    (ssget '((-4 . "<OR")
                             (0 . "LINE")
                             (0 . "LWPOLYLINE")
                             (0 . "ARC")
                             (-4 . "OR>")))))
         (princ "Select LINE, LWPOLINE or ARC...")
         )

  (redraw ename 4)

  (if (and sset sfirst)
    (progn
      (setq etype (cdr (assoc 0 (entget ename)))) ;get object type
      (ssdel ename sset) ;correct report

      ;; if first object is a LWPOLYLINE ...
      (if (= "LWPOLYLINE" etype)
        ;; then: join objects into LWPOLYLINE
        (command "._PEDIT" ename "_J" sset "" "")
        ;; else: convert object and join them
        (command "._PEDIT" ename  "_Y" "_J" sset "" "")
        )

      ;; check for deleted enames and report
      (setq i -1 cnt 0)
      (while (setq ename (ssname sset (setq i (1+ i))))
             (or (entget ename) (setq cnt (1+ cnt))))
      (prompt (strcat (itoa cnt) " joined, "
                      (itoa (- i cnt)) " left"))
      )
    (prompt "\nNo objects selected")
    )
  )

(princ "\nPJOIN - join contiguous plines, lines and arcs")
(princ)

Thanks for your help bye