Silent Pedit

Silent Pedit

hmsilva
Mentor Mentor
5,842 Views
51 Replies
Message 1 of 52

Silent Pedit

hmsilva
Mentor
Mentor
I'm trying to execute a pedit command in a lisp routine, without echoing, with no luck...

cmdecho and nomutt dont resolve my problem...

Can somebody points me the right way please...

Any help would be most appreciated.

Cheers

Henrique

EESignature

0 Likes
5,843 Views
51 Replies
Replies (51)
Message 41 of 52

danielrT8PHL
Participant
Participant

Hi, still not seeing anything different....

Command: pj
To join objects into Polyline(s) [pick 1 to join all possible to it],
Select objects: 1 found
Select objects:
Yes or No, please.
Yes or No, please.
; error: An error has occurred inside the *error* functionFunction cancelled
Do you want to turn it into one? <Y> *Cancel*

0 Likes
Message 42 of 52

ВeekeeCZ
Consultant
Consultant

You should have set CMDECHO sysvar to 1 before you run Kent's routine.

 

Anyway, I made little adjustment following Kent's idea of joining to all objects and now the routine should work both ways... either for a single election, window selection, or even for pre-selection.

 

(defun c:pljoin (/ ss convert single)
  (if (setq ss (ssget "_:L:S" '((0 . "LINE,ARC,LWPOLYLINE"))))
    (progn
      (setq convert (ssget "_P" '(( 0 . "LINE,ARC"))))
      (setq single (= (sslength ss) 1))
      
      (if single
        (command "_pedit" (ssname ss 0))
        (command "_pedit" "_m" ss ""))
      (if convert
        (command "_y"))
      (if single
        (command "_j" "_all" "" "")
        (command "_j" 0 ""))
      ))
  (princ)
  )
0 Likes
Message 43 of 52

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

You should have set CMDECHO sysvar to 1 before you run Kent's routine.

....


 

Yes, I should have added that one element in Message 40:  comment out the suppression of command echoing, save and re-load the .lsp file, set CMDECHO to 1, and run it again.

Kent Cooper, AIA
0 Likes
Message 44 of 52

danielrT8PHL
Participant
Participant

SUCCESS from advice on messages 42 and 43!!!!

Wow, nice work! Thanks so much, guys!!!!
D

0 Likes
Message 45 of 52

3dwannab
Advocate
Advocate

Hi John, thanks for this. I noticed that when I pick an already closed polyline it throws up the polyline command mid way.

 

I am currently trying to implement the following into the routine but struggling a bit, but I'll get there. 

 

  • To select more than one polyline instead of just a single enitity with entget.
  • To grip select the items after the joins have been done.
Message 46 of 52

john.uhden
Mentor
Mentor

This is a little better (read the remarks)...

(defun C:QJOIN ( / *error* @Anonymous vars vals |e |ok |ent |etyp |make |ss |ssl |layer
                   |obsel$ |j |elev |space |ans)
   ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   ;*                                                                           *
   ;*         QJOIN.LSP   by    John F. Uhden                                   *
   ;*                           2 Village Road                                  *
   ;*                           Sea Girt, NJ  08750                             *
   ;*                                                                           *
   ;* * * * * * * * * * * *  Do not delete this heading!  * * * * * * * * * * * *

   ; Program automatically joins to one selected line, arc, or polyline
   ; all possible lines, arcs, and polylines on the same layer and elevation.

   ; v3.0 (10-21-97) added support for R14 LWPOLYLINEs
   ; v15.00 (04-07-00) for R15
   ; v15.01 (10-14-02) fixed missing |elev for LWPOLYLINE
   ; v15.02 (08-07-04) added "peditaccept" for R16+
   ; v16.0  (12-19-19) converted to freeware for Challoner, and modernized
   ; v16.01 (08-08-22) added prompt if polyline is closed, added sssetfirst

   (gc)
   (prompt "\nQJOIN v16.01 (c)1994-2022, John F. Uhden")

   (defun *error* (|err)
      (@reset)
      (if (wcmatch (strcase |err) "*CANCEL*,*QUIT*")
         (vl-exit-with-error "\r                                              ")
         (vl-exit-with-error (strcat "\r*ERROR*: " |err))
      )
   )
   (defun @Anonymous ()
      (mapcar 'setvar vars vals)
      (vla-endundomark *doc*)
      (princ)
   )
   ;;-------------------------------------------
   ;; Initialize drawing and program variables:
   ;;
   (setq *acad* (vlax-get-acad-object))
   (setq *doc* (vlax-get *acad* 'ActiveDocument))
   (setq vars '("cmdecho" "highlight"))
   (setq vals (mapcar 'getvar vars))
   (setq |obsel$ "  Object selected is a(n) "
         |ok nil
         |e nil
         |ss nil
   )
   (vla-endundomark *doc*)
   (vla-startundomark *doc*)
   (mapcar 'setvar vars '(0 1))

   (if (setq |e (entsel "\nSelect arc, line, or polyline: "))
      (progn
         (setq |e (car |e)
               |ent (entget |e)
               |etyp (cdr (assoc 0 |ent))
               |layer (cdr (assoc 8 |ent))
               |elev (last (cdr (assoc 10 |ent)))
         )
         (if (setq |space (assoc 67 |ent))
            (setq |space (cdr |space))
            (setq |space 0)
         )
         (cond
            ((= |etyp "ARC")(setq |make 1 |ok 1))
            ((= |etyp "LINE")
               (if (= (last (cdr (assoc 10 |ent)))(last (cdr (assoc 11 |ent))))
                  (setq |make 1 |ok 1)
                  (prompt (strcat |obsel$ "3DLINE."))
               )
            )
            ((= |etyp "LWPOLYLINE")
               (if (= (boole 1 1 (cdr (assoc 70 |ent))) 0)
                  (setq |ok 1 |make nil |elev (cdr (assoc 38 |ent)))
                  (prompt "  Polyline is closed.")
               )
            )
            ((= |etyp "POLYLINE")
               (cond
                  ((> (boole 1 8 (cdr (assoc 70 |ent))) 0)
                     (prompt (strcat |obsel$ "3DPOLY."))
                  )
                  ((> (boole 1 16 (cdr (assoc 70 |ent))) 0)
                     (prompt (strcat |obsel$ "3DMESH."))
                  )
                  (1 (if (= (boole 1 1 (cdr (assoc 70 |ent))) 0)
                        (setq |ok 1 |make nil)
                        (prompt "  Polyline is closed.")
                     )
                  )
               )
            )
            (1 (prompt (strcat |obsel$ |etyp ".")))
         )
      )
   )
   (if (and |e (= 4 (logand (cdr (assoc 70 (tblsearch "LAYER" |layer))) 4)))
      (setq |ok (prompt (strcat "\nLayer " |layer " is LOCKED!")))
   )
   (if (and |e |ok)
      (setq |ss (ssget "X"
         (list
            (cons 8 |layer)
            (cons 67 |space)
            (cons -4 "<OR")
               (cons -4 "<AND")
                  (cons 0 "LINE")
                  (cons -4 "*,*,=")(cons 10 (list 0.0 0.0 |elev))
                  (cons -4 "*,*,=")(cons 11 (list 0.0 0.0 |elev))
               (cons -4 "AND>")
               (cons -4 "<AND")
                  (cons 0 "ARC")
                  (cons -4 "*,*,=")(cons 10 (list 0.0 0.0 |elev))
               (cons -4 "AND>")
               (cons -4 "<AND")
                  (cons 0 "POLYLINE")
                  (cons -4 "<NOT")
                  (cons -4 "&")(cons 70 (+ 1 8 16 32 64))
                  (cons -4 "NOT>")
                  (cons -4 "*,*,=")(cons 10 (list 0.0 0.0 |elev))
               (cons -4 "AND>")
               (cons -4 "<AND")
                  (cons 0 "LWPOLYLINE")
                  (cons -4 "<NOT")
                  (cons -4 "&")(cons 70 1)
                  (cons -4 "NOT>")
                  (cons -4 "=")(cons 38 |elev)
               (cons -4 "AND>")
            (cons -4 "OR>")
         ))
      )
      (setq |ss nil)
   )
   (if (and |ss (> (setq |ssl (sslength |ss)) 1))
      (progn
         (mapcar 'setvar vars '(0 0))
         (command "_.pedit" |e)
         ;; added "peditaccept" (08-07-04)
         (if (and |make (/= (getvar "peditaccept") 1))(command "_Y"))
         (command "_J" |ss "")
         (if (= (getvar "plinegen") 1)(command "_LT" "_ON"))
         (command "_X")
         (if (setq |ss (ssget "P"))
            (setq |j (- |ssl (sslength |ss)))
            (setq |j |ssl)
         )
         (if |make (setq |e (entlast)))
         (sssetfirst nil (ssadd |e))
         ;; (if (= (getvar "highlight") 0)
           ;; (prompt "\nIf you saw nothing happen, it's because HIGHLIGHT is OFF.")
         ;; )
         (prompt (strcat "\nJoined " (itoa |j) " entities."))
      )
      (if (and |e |ok)(prompt "\nNo entities found to join."))
   )
   (@reset)
)
(defun c:QJ ()(c:QJOIN))

John F. Uhden

Message 47 of 52

3dwannab
Advocate
Advocate

Thanks John, I didn't end up getting time to look at doing what I was supposed to. I'm after getting multiple selection added there now but I cannot get the grips to appear correctly. I've tried to put a regen command in there but to no avail.

 

Here's my edit (I hope you don't mind)

(defun C:QJOIN (/ *error* @Anonymous vars vals e ok ent etyp make ss ss1 selme i ssl layer obsel$ j elev space ans)
  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  ;*                                                                           *
  ;*         QJOIN.LSP   by    John F. Uhden                                   *
  ;*                           2 Village Road                                  *
  ;*                           Sea Girt, NJ  08750                             *
  ;*                                                                           *
  ;* * * * * * * * * * * *  Do not delete this heading!  * * * * * * * * * * * *

  ; Program automatically joins to one selected line, arc, or polyline
  ; all possible lines, arcs, and polylines on the same layer and elevation.

  ; v3.0        (10-21-97) added support for R14 LWPOLYLINEs
  ; v15.00      (04-07-00) for R15
  ; v15.01      (10-14-02) fixed missing elev for LWPOLYLINE
  ; v15.02      (08-07-04) added "peditaccept" for R16+
  ; v16.0       (12-19-19) converted to freeware for Challoner, and modernized
  ; v16.01      (08-08-22) added prompt if polyline is closed, added sssetfirst
  ; v16.01_edit (08-08-22) 3dwannab edit to select more than one entity using ssget, tweak sssetfirst to work with change.

  (gc)
  (prompt "\nQJOIN v16.01 (c)1994-2022, John F. Uhden")

  (defun *error* (err)
    (@reset)
    (if (wcmatch (strcase err) "*CANCEL*,*QUIT*")
      (vl-exit-with-error "\r                                              ")
      (vl-exit-with-error (strcat "\r*ERROR*: " err))
    )
  )
  (defun @Anonymous ()
    (mapcar 'setvar vars vals)
    (vla-endundomark *doc*)
    (princ)
  )
  ;;-------------------------------------------
  ;; Initialize drawing and program variables:
  ;;
  (setq *acad* (vlax-get-acad-object))
  (setq *doc* (vlax-get *acad* 'ActiveDocument))
  (setq vars '("cmdecho" "highlight"))
  (setq vals (mapcar 'getvar vars))
  (setq obsel$ "  Object selected is a(n) "
        ok     nil
        e      nil
        ss     nil
  )
  (vla-endundomark *doc*)
  (vla-startundomark *doc*)
  (mapcar 'setvar vars '(0 1))

  (setq selme (ssadd)) ; 2022.08.08 3dwannab

  (if (setq ss1 (ssget "_:L"))  ; 2022.08.08 3dwannab

    (progn

      ;; Added by 3dwannab 2022.08.08
      (repeat (setq i (sslength ss1))
        (setq e (ssname ss1 (setq i (1- i))))
        (setq ent (entget e))
        (setq etyp (cdr (assoc 0 ent)))
        (setq layer (cdr (assoc 8 ent)))
        (setq elev (last (cdr (assoc 10 ent))))
        ;; end 3dwannb edit

        (if (setq space (assoc 67 ent))
          (setq space (cdr space))
          (setq space 0)
        )

        (progn

          (cond
            ((= etyp "ARC")
             (setq make 1
                   ok   1
             )
            )
            ((= etyp "LINE")
             (if (= (last (cdr (assoc 10 ent))) (last (cdr (assoc 11 ent))))
               (setq make 1
                     ok   1
               )
               (prompt (strcat obsel$ "3DLINE."))
             )
            )
            ((= etyp "LWPOLYLINE")
             (if (= (boole 1 1 (cdr (assoc 70 ent))) 0)
               (setq ok   1
                     make nil
                     elev (cdr (assoc 38 ent))
               )
               (prompt "  Polyline is closed.")
             )
            )
            ((= etyp "POLYLINE")
             (cond
               ((> (boole 1 8 (cdr (assoc 70 ent))) 0)
                (prompt (strcat obsel$ "3DPOLY."))
               )
               ((> (boole 1 16 (cdr (assoc 70 ent))) 0)
                (prompt (strcat obsel$ "3DMESH."))
               )
               (1
                (if (= (boole 1 1 (cdr (assoc 70 ent))) 0)
                  (setq ok   1
                        make nil
                  )
                  (prompt "  Polyline is closed.")
                )
               )
             )
            )
            (1 (prompt (strcat obsel$ etyp ".")))
          )
        ) ;; progn end

        (if (and e (= 4 (logand (cdr (assoc 70 (tblsearch "LAYER" layer))) 4)))
          (setq ok (prompt (strcat "\nLayer " layer " is LOCKED!")))
        ) ;; if layer exists and not locked end

        (if (and e ok)
          (setq ss (ssget "X"
                          (list
                            (cons 8 layer)
                            (cons 67 space)
                            (cons -4 "<OR")
                            (cons -4 "<AND")
                            (cons 0 "LINE")
                            (cons -4 "*,*,=")
                            (cons 10 (list 0.0 0.0 elev))
                            (cons -4 "*,*,=")
                            (cons 11 (list 0.0 0.0 elev))
                            (cons -4 "AND>")
                            (cons -4 "<AND")
                            (cons 0 "ARC")
                            (cons -4 "*,*,=")
                            (cons 10 (list 0.0 0.0 elev))
                            (cons -4 "AND>")
                            (cons -4 "<AND")
                            (cons 0 "POLYLINE")
                            (cons -4 "<NOT")
                            (cons -4 "&")
                            (cons 70 (+ 1 8 16 32 64))
                            (cons -4 "NOT>")
                            (cons -4 "*,*,=")
                            (cons 10 (list 0.0 0.0 elev))
                            (cons -4 "AND>")
                            (cons -4 "<AND")
                            (cons 0 "LWPOLYLINE")
                            (cons -4 "<NOT")
                            (cons -4 "&")
                            (cons 70 1)
                            (cons -4 "NOT>")
                            (cons -4 "=")
                            (cons 38 elev)
                            (cons -4 "AND>")
                            (cons -4 "OR>")
                          )
                   )
          )
          (setq ss nil)
        ) ;; if e and ok end

        (if (and ss (> (setq ssl (sslength ss)) 1))
          (progn
            (mapcar 'setvar vars '(0 0))
            (command "_.pedit" e)
            ;; added "peditaccept" (08-07-04)
            (if (and make (/= (getvar "peditaccept") 1)) (command "_Y"))
            (command "_J" ss "")
            (if (= (getvar "plinegen") 1) (command "_LT" "_ON"))
            (command "_X")
            (if (setq ss (ssget "P"))
              (setq j (- ssl (sslength ss)))
              (setq j ssl)
            )
            (if make (ssadd (entlast) selme)) ; 2022.08.08 3dwannab, to add to the selme selection set.
            ;; (if (= (getvar "highlight") 0)
            ;; (prompt "\nIf you saw nothing happen, it's because HIGHLIGHT is OFF.")
            ;; )

            (prompt (strcat "\nJoined " (itoa j) (if (> j 1) " entities." " entity."))) ; 2022.08.08 3dwannab, to correct grammer depending on number of items joined.
          )
          (if (and e ok) (prompt "\nNo entities found to join."))
        ) ;; end if ss
      ) ;; repeat end

      (if selme (sssetfirst nil selme)) ; 2022.08.08 3dwannab, to select any created objects after they're created.
      (if ss1 (sssetfirst nil ss1)) ; 2022.08.08 3dwannab, so that any selection is not lost.

      (command "_.regen")

      (princ "\nFinished joining...")
    ) ;; progn end
  ) ;; if end

  (@reset)
)
(defun c:QJ () (c:QJOIN))

 

 

 

 

 
0 Likes
Message 48 of 52

john.uhden
Mentor
Mentor

@3dwannab 

I am having trouble following your logic.  I didn't study your additions really well, but I am left with the following comments/questions:

 

  1. If you are selecting the candidates first <ss1>, some may get joined and some may not.
  2. The ones that are joined might still have valid enames, but surely entget would be nil.
  3. I didn't pick up where you would continue with any leftovers (not joined).
  4. What's the point of sssetfirsting all the joined <selme> and then the original candidates?  If there are leftovers you wouldn't be gripping the selmes long enough to see them.  Maybe you could put the selmes on a "SELME" or "JOINED" layer with a rarely used but striking color like 230 (fuscia).
  5.  At least I like that you eliminated all those annoying | prefixes.  They're left over from the days when locals weren't really local, and you had to set them to nil as part of the reset.

John F. Uhden

0 Likes
Message 49 of 52

3dwannab
Advocate
Advocate

@john.uhden, thanks for your comments.

 

  1. If you are selecting the candidates first <ss1>, some may get joined and some may not. I see that now and I don't know how to fix this.
  2. The ones that are joined might still have valid enames, but surely entget would be nil. I did try to fix this if an (if e (progn ...)) but that didn't work.
  3. I didn't pick up where you would continue with any leftovers (not joined). Not sure how to fix this either. I sort of dug a hole for myself here 😕
  4. What's the point of sssetfirsting all the joined <selme> and then the original candidates?  If there are leftovers you wouldn't be gripping the selmes long enough to see them.  Maybe you could put the selmes on a "SELME" or "JOINED" layer with a rarely used but striking color like 230 (fuscia). I like it when programs don't deselect any preselect items and also if they modify any they are selected after the program has ran. It's easier to do further modifications to them with properties panel or change layers etc.
  5.  At least I like that you eliminated all those annoying | prefixes.  They're left over from the days when locals weren't really local, and you had to set them to nil as part of the reset. At least I did something right. And I meant to ask you what those were about but now I know. Thanks.
0 Likes
Message 50 of 52

john.uhden
Mentor
Mentor

@3dwannab 

I really think you should stop torturing yourself with this self-imposed conundrum.  If I thought it would be useful I would have written it 25-30 years ago.  Please reconsider just using QJOIN for what it does.  The price was right. 🤑

John F. Uhden

Message 51 of 52

3dwannab
Advocate
Advocate

I guess so but I'll leave it the way I modified it for now until I have another stab at it. One saving grace is if I only pick one item as the original one is written it still works pretty much the same.

0 Likes
Message 52 of 52

john.uhden
Mentor
Mentor

@3dwannab 

I wish you the best of luck with that.

John F. Uhden

0 Likes