+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Forum Newbie
    Using
    not specified
    Join Date
    Jun 2005
    Posts
    5

    Default command for polylines ?

    Registered forum members do not see this ad.

    I thought a command for RAPID creation of polylines from lines will be useful but I don't which will be simpler:
    1. either to use the a "version" of the PEDIT command, but without the time consuming options (join/edit/... etc, etc.) since I'm not interested in EDITING a polyline but only to CREATE one: the procedure would be: "command">>enter>>"select objects">>enter>>the polyline is created (or not if not possible)
    2. a version of the BPOLY command which does this (but only for closed entities) but a bpoly which erases the original objects leaving only the new polyline

    I think that the first option is the way to go but I really don't know how to customize this command (or make another command based on it), is it better in LISP, in VBA, simple scripting or it can be done only by switching some system variables?

    thanks

  2. #2
    Senior Member erona's Avatar
    Using
    AutoCAD 2007
    Join Date
    Feb 2005
    Location
    Philippines
    Posts
    306

    Default

    Try PLJOIN. I use this a lot in ACAD 2000 but was removed on ver 2004. So I just load it up in 2004 and still works like a charm. Quite a long script I'd say.

    Code:
    ;;;
    ;;;    PLJOIN.LSP
    ;;;    Copyright © 1999 by Autodesk, Inc.
    ;;;
    ;;;    Your use of this software is governed by the terms and conditions of the
    ;;;    License Agreement you accepted prior to installation of this software.
    ;;;    Please note that pursuant to the License Agreement for this software,
    ;;;    "[c]opying of this computer program or its documentation except as
    ;;;    permitted by this License is copyright infringement under the laws of
    ;;;    your country.  If you copy this computer program without permission of
    ;;;    Autodesk, you are violating the law."
    ;;;
    ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
    ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
    ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
    ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
    ;;;    UNINTERRUPTED OR ERROR FREE.
    ;;;
    ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
    ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
    ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
    ;;;    (Rights in Technical Data and Computer Software), as applicable.
    ;;;
    ;;;  ----------------------------------------------------------------
    
    ;Set global for controling precision of internal point comparison.
    (setq #acet-pljoin-prec 0.0000001)
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun c:pljoin ( / flt ss fuzz st )
    
    (acet-error-init
     (list (list  "cmdecho" 0
                "highlight" (getvar "highlight")
                "plinetype" 2
                 "limcheck" 0
                   "osmode" 0
           )
           0
           '(progn                      ;clean up some temporary entities
             (if (and tmpna
                      (entget tmpna)
                 );and
                 (entdel tmpna)
             );if
             (if (and tmpna2
                      (entget tmpna2)
                 );and
                 (entdel tmpna2)
             );if
            );progn
     );list
    );acet-error-init
    (setq flt (list
                    &#40;list '&#40;&#40;-4 . "<OR"&#41; &#40;0 . "LINE"&#41; &#40;0 . "ARC"&#41; &#40;0 . "*POLYLINE"&#41; &#40;-4 . "OR>"&#41;&#41;
                          "\n1 object was not a line, arc or pline."
                          "\n%1 objects were not lines, arcs or plines."
                    &#41;;list
                    &#40;list '&#40;&#40;-4 . "<OR"&#41; &#40;0 . "LINE"&#41; &#40;0 . "ARC"&#41;
                            &#40;-4 . "<AND"&#41;
                             &#40;0 . "*POLYLINE"&#41;
                             &#40;-4 . "<NOT"&#41; &#40;-4 . "&"&#41; &#40;70 . 1&#41; &#40;-4 . "NOT>"&#41; ;1
                            &#40;-4 . "AND>"&#41;
                            &#40;-4 . "OR>"&#41;&#41;
                          "\n1 object was a closed pline."
                          "\n%1 objects were closed plines."
                    &#41;;list
                    &#40;list '&#40;&#40;-4 . "<OR"&#41; &#40;0 . "LINE"&#41; &#40;0 . "ARC"&#41;
                            &#40;-4 . "<AND"&#41;
                             &#40;0 . "*POLYLINE"&#41;
                             &#40;-4 . "<NOT"&#41; &#40;-4 . "&"&#41; &#40;70 . 88&#41; &#40;-4 . "NOT>"&#41; ;8 16 64
                            &#40;-4 . "AND>"&#41;
                            &#40;-4 . "OR>"&#41;&#41;
                          "\n1 object was a mesh or 3dpoly."
                          "\n%1 objects were 3d plines or meshes."
                    &#41;;list
                    &#40;list "LAYERUNLOCKED"&#41;
                    &#40;list "CURRENTUCS"&#41;
              &#41;;list
    &#41;;setq
    
    &#40;if &#40;and &#40;setq ss &#40;ssget&#41;&#41;
             &#40;setq ss &#40;car &#40;acet-ss-filter &#40;list ss flt T&#41;&#41;&#41;&#41;
        &#41;;and
        &#40;progn
         &#40;setvar "highlight" 0&#41;
         &#40;setq fuzz &#40;acet-pljoin-get-fuzz-and-mode&#41;
                st &#40;cadr fuzz&#41;
               fuzz &#40;car fuzz&#41;
         &#41;;setq
         &#40;acet-pljoin ss st fuzz&#41;
        &#41;;progn then
        &#40;princ "\nNothing valid selected."&#41;
    &#41;;if
    &#40;acet-error-restore&#41;
    &#41;;defun c&#58;pljoin
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin &#40; ss st fuzz / flt &#41;
    
    &#40;princ "\nProcessing pline data...."&#41;
    &#40;setq flt '&#40;&#40;-4 . "<OR"&#41;
                 &#40;0 . "LINE"&#41;
                 &#40;0 . "ARC"&#41;
                 &#40;-4 . "<AND"&#41;
                  &#40;0 . "*POLYLINE"&#41;
                  &#40;-4 . "<NOT"&#41; &#40;-4 . "&"&#41; &#40;70 . 89&#41;  &#40;-4 . "NOT>"&#41; ;1 8 16 64
                 &#40;-4 . "AND>"&#41;
                &#40;-4 . "OR>"&#41;
               &#41;
    &#41;;setq
    &#40;if &#40;and &#40;setq ss &#40;acet-pljoin-do-ss-pre-work ss flt&#41;&#41; ;convert lines/arcs/heavy plines ..etc.
                                                           ;to lighweight plines
             &#40;setq ss &#40;acet-pljoin-1st-pass ss flt&#41;&#41;       ;initial pass with pedit command
        &#41;;and
        &#40;acet-pljoin-2nd-pass ss fuzz st flt&#41; ;where the work is..
    &#41;;if
    
    &#40;princ &#40;acet-str-format "%1 Done.\n" &#40;chr 8&#41;&#41;&#41;
    
    &#41;;defun acet-pljoin
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Try to join as many as possible before performing the
    ;hashing.
    ;
    &#40;defun acet-pljoin-1st-pass &#40; ss flt / na &#41;
    
     &#40;acet-spinner&#41;
    
     &#40;setq na &#40;entlast&#41;&#41;
     &#40;command "_.pedit" &#40;ssname ss 0&#41; "_j" ss "" "_x"&#41;
     &#40;if &#40;not &#40;equal na &#40;entlast&#41;&#41;&#41;
         &#40;progn
          &#40;command "_.select" ss &#40;entlast&#41; ""&#41;
          &#40;setq ss &#40;ssget "_p" flt&#41;&#41;;setq
          &#40;if &#40;and ss
                   &#40;<= &#40;sslength ss&#41; 1&#41;
              &#41;;and
              &#40;setq ss nil&#41;
          &#41;;if
          &#40;setq ss &#40;acet-pljoin-ss-flt ss flt&#41;&#41;
         &#41;;progn then
     &#41;;if
    
     ss
    &#41;;defun acet-pljoin-1st-pass
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-2nd-pass &#40; ss fuzz st flt / g lst lst3 len x lst2 lst4 n a
                                                  tmpe1 tmpe2 tmpna tmpna2 flst
                               &#41;
    
     ;;&#40;print "acet-pljoin-2nd-pass"&#41;
     ;;&#40;print ""&#41;
    
     ;;create a couple of temporary entities for intersection checking
     &#40;setq tmpe1 &#40;list
                    '&#40;0 . "LWPOLYLINE"&#41; '&#40;100 . "AcDbEntity"&#41;
                   '&#40;60 . 1&#41;
                   '&#40;62 . 1&#41;
                   '&#40;100 . "AcDbPolyline"&#41;
                   '&#40;90 . 2&#41; '&#40;70 . 0&#41; '&#40;43 . 0.0&#41; '&#40;38 . 0.0&#41; '&#40;39 . 0.0&#41;
                   '&#40;10 0.0 0.0&#41; '&#40;40 . 0.0&#41; '&#40;41 . 0.0&#41; '&#40;42 . 0.0&#41; '&#40;10 1.0 1.0&#41;
                   '&#40;40 . 0.0&#41; '&#40;41 . 0.0&#41; '&#40;42 . 0.0&#41;
                   &#40;cons 210 &#40;acet-geom-cross-product &#40;getvar "ucsxdir"&#41; &#40;getvar "ucsydir"&#41;&#41;&#41; ;;&#40;210 0.0 0.0 1.0&#41;
                  &#41;
           tmpe2 tmpe1
     &#41;;setq
     &#40;entmake tmpe1&#41;
     &#40;setq tmpna &#40;entlast&#41;
           tmpe1 &#40;entget tmpna&#41;
     &#41;;setq
     &#40;entmake tmpe2&#41;
     &#40;setq tmpna2 &#40;entlast&#41;
            tmpe2 &#40;entget tmpna2&#41;
     &#41;;setq
    
     &#40;if &#40;equal fuzz 0.0&#41;
         &#40;setq fuzz #acet-pljoin-prec&#41;
     &#41;;if
    
     ;Pljoin checks distances between neighboring points of differing objects
     ;to find the closest candidates for joining. The performance problem is
     ;largely one of minimizing the number of distance calculations that occur.
     ;Here's the approach... Points are placed into a grid where each point
     ;is checked against other points that fall within neighboring grid points.
     ;This operation is similar to drawing in AutoCAD with snap turned on.
     ;Picked points snap to the nearest grid point.
     ;
     ;
     &#40;setq   g &#40;* 2.01 fuzz&#41;              ;grid size
           lst &#40;acet-pljoin-round ss g&#41;  ;round points to the grid
                                         ;lst - sub-lists &#40;roundedpoint originalpoint 0/1 ename&#41;
           len &#40;length lst&#41;
             x &#40;/ len 8&#41;
     &#41;;setq
     &#40;if &#40;< len 2000&#41; ;for performance reasons if the list is greater than 2000
                      ;point the split the operation into 8 separate chunks
                      ;so they can be processed independantly.
         &#40;setq  len 0
               lst4 lst
                lst nil
         &#41;;setq
     &#41;;if
    
     &#40;setq n 0&#41;
     &#40;repeat len
     &#40;setq    a &#40;nth n lst&#41;
           lst2 &#40;cons a lst2&#41;
     &#41;;setq
     &#40;if &#40;equal n &#40;* x &#40;/ n x&#41;&#41;&#41;
         &#40;progn
           &#40;setq lst2 &#40;acet-pljoin-get-matched-pairs lst2 ;list of point data lists
                                                     lst3 ;entname map
                                                      fuzz ;fuzz distance
                                                        g ;grid size
                                                       st ;mode
                                                    tmpe1 ;temp ent
                                                    tmpe2 ;temp ent2
                                                     flst ;pairs that failed a join attempt
                      &#41;
                 lst3 &#40;cadr lst2&#41;
                 flst &#40;caddr lst2&#41;
                 lst2 &#40;car lst2&#41;
           &#41;;setq
           &#40;if lst2
               &#40;setq lst4 &#40;append lst4 lst2&#41;
                     lst2 nil
               &#41;;setq
           &#41;;if
         &#41;;progn then
     &#41;;if
     &#40;setq n &#40;+ n 1&#41;&#41;
     &#41;;repeat
     &#40;if lst2
         &#40;setq lst2 &#40;acet-pljoin-get-matched-pairs lst2 ;list of point data lists
                                                   lst3 ;entname map
                                                    fuzz ;fuzz distance
                                                      g ;grid size
                                                     st ;mode
                                                  tmpe1 ;temp ent
                                                  tmpe2 ;temp ent2
                                                   flst ;pairs that failed a join attempt
                    &#41;
               lst3 &#40;cadr lst2&#41;
               flst &#40;caddr lst2&#41;
               lst2 &#40;car lst2&#41;
         &#41;;setq
     &#41;;if
     &#40;if lst2
         &#40;setq lst4 &#40;append lst4 lst2&#41;&#41;;setq
     &#41;;if
     &#40;setq  lst nil
           lst2 nil
     &#41;;setq
    
     &#40;while lst4
      &#40;setq  lst4 &#40;acet-pljoin-get-matched-pairs lst4 ;list of point data lists
                                                 lst3 ;entname map
                                                  fuzz ;fuzz distance
                                                    g ;grid size
                                                   st ;mode
                                                tmpe1 ;temp ent
                                                tmpe2 ;temp ent2
                                                 flst ;pairs that failed a join attempt
                  &#41;
             lst3 &#40;cadr lst4&#41;
             flst &#40;caddr lst4&#41;
             lst4 &#40;car lst4&#41;
      &#41;;setq
     &#41;;while
    
     &#40;entdel tmpna&#41;
     &#40;entdel tmpna2&#41;
    
    
    &#41;;defun acet-pljoin-2nd-pass
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-get-matched-pairs &#40; lst lst5 fuzz g st tmpe1 tmpe2 flst /
                                           na na2 p1 p2 n j a b c d lst2 lst3
                                           id id2 ulst x flst flag flag2 ulst2 flst2
                                           nskip
                                         &#41;
    
    ;&#40;print "acet-pljoin-get-matched-pairs"&#41;
    ;&#40;print ""&#41;
    
    &#40;setq n 0&#41;               ;;;create a list of sublist pairs in lst2 i.e. &#40;&#40;0 4&#41; &#40;2 5&#41;...&#41;
    &#40;repeat &#40;length lst&#41;     ;;;also create list of non-candidate indexs in lst3
     &#40;cond
      &#40;&#40;setq j &#40;acet-pljoin-get-closest &#40;nth n lst&#41; lst fuzz g flst&#41;&#41;
       &#40;setq    j &#40;list &#40;nth n lst&#41; j&#41;        ;the point and it's closest candidate
             lst2 &#40;cons j lst2&#41;
       &#41;;setq then add this closest match pair
      &#41;;cond #1
      &#40;T
       &#40;setq lst3 &#40;cons n lst3&#41;&#41; ;non-candidates
      &#41;;cond #2
     &#41;;cond close
     &#40;if &#40;equal n &#40;* 20 &#40;/ n 20&#41;&#41;&#41;
         &#40;acet-spinner&#41;
     &#41;;if
    &#40;setq n &#40;+ n 1&#41;&#41;
    &#41;;repeat
    
    ;Loop through lst2 and look for pairs that point back at each other. i.e. &#40;p1 p2 ...&#41; &#40;p2 p1 ...&#41;
    ;attempt the join. Track the success of the joins in ulst and the failures in flst.
    
    
    &#40;setq nskip 0&#41;
    &#40;setq n 0&#41;
    &#40;repeat &#40;length lst2&#41;
     &#40;setq     x &#40;nth n lst2&#41;   ;a sublist with the a point and it's 5 closest point buddies.
              id &#40;car x&#41;
             id2 &#40;cadr x&#41;
     &#41;;setq
    
     &#40;if &#40;and &#40;not &#40;member id ulst&#41;&#41;                   ;both are points not used yet
              &#40;not &#40;member id2 ulst&#41;&#41;
              &#40;not &#40;member &#40;list id id2&#41; flst&#41;&#41;        ;have not already tried this pair and failed
              &#40;setq b &#40;assoc id2 lst2&#41;&#41;
              &#40;equal id &#40;cadr b&#41;&#41;                      ;closest pairs point at each other
              &#40;setq  na &#40;last id&#41;                      ;get some of the data out of id and id2
                    na2 &#40;last id2&#41;
                     p1 &#40;cadr id&#41;                      ;the real points
                     p2 &#40;cadr id2&#41;
              &#41;;setq
              &#40;progn                                   ;get the proper entity names from the ename map lst5
               &#40;while &#40;setq c &#40;assoc na lst5&#41;&#41;   &#40;setq na &#40;cadr c&#41;&#41;&#41;;while
               &#40;while &#40;setq c &#40;assoc na2 lst5&#41;&#41;  &#40;setq na2 &#40;cadr c&#41;&#41;&#41;;while
               T
              &#41;;progn
              na                                       ;both entities still exist?
              na2
         &#41;;and
         &#40;progn
           ;then attempt a join
          &#40;setq flag nil
                lst5 &#40;acet-pljoin-do-join fuzz st na p1 na2 p2 lst5 tmpe1 tmpe2&#41;
                flag &#40;cadr lst5&#41; ;join success?
                lst5 &#40;car lst5&#41;
          &#41;;setq return updated entname map and success flag
          &#40;if flag
              &#40;setq ulst &#40;cons id ulst&#41;     ;Then the join succeeded.
                    ulst &#40;cons id2 ulst&#41;    ;mark the two as used by adding the them to ulst
              &#41;;setq the success
              &#40;setq flst &#40;cons &#40;list id id2&#41; flst&#41;
                    flst &#40;cons &#40;list id2 id&#41; flst&#41;
              &#41;;setq else join failed so mark as such in flst
          &#41;;if
         &#41;;progn then
         &#40;progn
          &#40;setq nskip &#40;+ nskip 1&#41;&#41;;setq
    
          ;&#40;print '&#40;not &#40;member id ulst&#41;&#41;&#41;
          ;&#40;print &#40;not &#40;member id ulst&#41;&#41;&#41;
          ;&#40;print '&#40;not &#40;member id2 ulst&#41;&#41;&#41;
          ;&#40;print &#40;not &#40;member id2 ulst&#41;&#41;&#41;
          ;&#40;print '&#40;not &#40;member &#40;list id id2&#41; flst&#41;&#41;&#41;
          ;&#40;print &#40;not &#40;member &#40;list id id2&#41; flst&#41;&#41;&#41;
          ;&#40;print '&#40;setq b &#40;assoc id2 lst2&#41;&#41;&#41;
          ;&#40;print &#40;setq b &#40;assoc id2 lst2&#41;&#41;&#41;
          ;&#40;print '&#40;equal id &#40;cadr b&#41;&#41;&#41;
          ;&#40;print &#40;equal id &#40;cadr b&#41;&#41;&#41;
          ;&#40;print 'na&#41;
          ;&#40;print na&#41;
          ;&#40;print 'na2&#41;
          ;&#40;print na2&#41;
          ;
          ;&#40;d-point &#40;cadr id&#41; "1"&#41;
          ;&#40;d-point &#40;cadr id2&#41; "2"&#41;
          ;&#40;princ "\ndecided not to try it."&#41;
          ;&#40;getstring ""&#41;
          ;&#40;entdel &#40;entlast&#41;&#41;
          ;&#40;entdel &#40;entlast&#41;&#41;
    
         &#41;;progn else
     &#41;;if
    &#40;setq n &#40;+ n 1&#41;&#41;
    &#41;;repeat
    
    &#40;if &#40;equal nskip n&#41;
        &#40;setq lst nil&#41;;then all were skipped so the job is finished.
    &#41;;if
    
    &#40;setq lst2 nil&#41;;setq ;;;remove the used and non-candidate point data from lst
    &#40;setq n 0&#41;
    &#40;repeat &#40;length lst&#41;
    &#40;setq a &#40;nth n lst&#41;&#41;;setq
     &#40;if &#40;and &#40;not &#40;member n lst3&#41;&#41;    ;not a non-candidate
              &#40;not &#40;member a ulst&#41;&#41;    ;not used
         &#41;;and
         &#40;setq lst2 &#40;cons a lst2&#41;&#41;
     &#41;;if
    &#40;setq n &#40;+ n 1&#41;&#41;
    &#41;;repeat
    
    &#40;list lst2 lst5 flst&#41;
    &#41;;defun acet-pljoin-get-matched-pairs
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-get-closest &#40; p1 lst fuzz g flst / a b c d x1 x2 x3 y1 y2 y3 n j
                                                         lst2 lst3 len2 len3 clst
                                   &#41;
    
    ;&#40;print "acet-pljoin-get-closest"&#41;
    ;&#40;print ""&#41;
    
    &#40;setq   b &#40;cadr p1&#41; ;the real point
            a &#40;car p1&#41;  ;the grid point
    &#41;;setq
    
    ;determine the grid points to examine.
    &#40;cond
     &#40;&#40;equal fuzz 0.0 #acet-pljoin-prec&#41;
      &#40;setq lst2 &#40;list &#40;list &#40;car a&#41; &#40;cadr a&#41;&#41;
                 &#41;;list
      &#41;;setq else
     &#41;;cond #2
     &#40;T
      &#40;if &#40;<= &#40;car a&#41; &#40;car b&#41;&#41;
          &#40;setq x1 &#40;car a&#41;
                x2 &#40;acet-calc-round &#40;+ &#40;car a&#41; g&#41; g&#41;
          &#41;;setq
          &#40;setq x1 &#40;acet-calc-round &#40;- &#40;car a&#41; g&#41; g&#41;
                x2 &#40;car a&#41;
         &#41;;setq
      &#41;;if
      &#40;if &#40;<= &#40;cadr a&#41; &#40;cadr b&#41;&#41;
          &#40;setq y1 &#40;cadr a&#41;
                y2 &#40;acet-calc-round &#40;+ &#40;cadr a&#41; g&#41; g&#41;
          &#41;;setq
          &#40;setq y1 &#40;acet-calc-round &#40;- &#40;cadr a&#41; g&#41; g&#41;
                y2 &#40;cadr a&#41;
          &#41;;setq
      &#41;;if
      &#40;setq lst2 &#40;list &#40;list x1 y1&#41;
                       &#40;list x2 y1&#41;
                       &#40;list x2 y2&#41;
                       &#40;list x1 y2&#41;
                 &#41;;list
      &#41;;setq
     &#41;;cond #3
    &#41;;cond close
    
    &#40;setq    d &#40;* fuzz 2.0&#41;
          len2 &#40;length lst2&#41;
    &#41;;setq
    ;;loop through the grid points and check each of the points that fall on each grid point
    &#40;setq n 0&#41;
    &#40;while &#40;< n len2&#41;
    &#40;setq lst3 &#40;acet-list-m-assoc &#40;nth n lst2&#41; lst&#41; ;get a list of assoc point based on grid point
          len3 &#40;length lst3&#41;
    &#41;;setq
    
     &#40;setq j 0&#41;
     &#40;while &#40;< j len3&#41;                       ;loop through the current list of grid points
                                             ;and find the closest point
      &#40;setq a &#40;nth j lst3&#41;&#41;
      &#40;if &#40;and
               ;@rk 4&#58;13 PM 9/7/98
               ;removed
               ;;;&#40;not &#40;equal &#40;last a&#41; &#40;last p1&#41;&#41;&#41;       ;not same entity name
               ;and changed to ...
               &#40;not &#40;equal a p1&#41;&#41;
    
               &#40;setq c &#40;distance &#40;cadr p1&#41; &#40;cadr a&#41;&#41;&#41; ;distance between real original points
               &#40;<= c fuzz&#41;                            ;less than or equal to fuzz
               &#40;< c d&#41;
               &#40;not &#40;member &#40;list p1 a&#41; flst&#41;&#41;
          &#41;;and
          &#40;progn
           &#40;setq    d c
                 clst a
           &#41;;setq
           &#40;if &#40;equal c 0.0 #acet-pljoin-prec&#41;
               &#40;setq n len2
                     j len3
               &#41;;setq then jump out of the loop
           &#41;;if
          &#41;;progn then
      &#41;;if
     &#40;setq j &#40;+ j 1&#41;&#41;
     &#41;;while
    
    &#40;setq n &#40;+ n 1&#41;&#41;
    &#41;;while
    
    clst
    &#41;;defun acet-pljoin-get-closest
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-do-join &#40; fuzz st na p1 na2 p2 lst3 tmpe1 tmpe2 / x b e1 e2 flag &#41;
    
    ;&#40;print "acet-pljoin-do-join"&#41;
    ;&#40;print ""&#41;
    
    &#40;if &#40;or &#40;equal st "Add"&#41;
            &#40;equal 0.0 &#40;distance p1 p2&#41; #acet-pljoin-prec&#41;
            &#40;and &#40;setq p1 &#40;acet-pljoin-fillet-with-fuzz fuzz na p1 tmpe1 na2 p2 tmpe2&#41;
                       p2 &#40;cadr p1&#41;
                       p1 &#40;car p1&#41;
                 &#41;;setq
                 &#40;equal st "Both"&#41;
            &#41;;and
            &#40;and &#40;equal p1 p2&#41;
                 &#40;equal st "Fillet"&#41;
            &#41;;and
        &#41;;or
        &#40;progn
    
         &#40;setq flag T&#41; ;then set the success flag
    
         &#40;if &#40;not &#40;equal p1 p2&#41;&#41; ;;avoid the distance calc. &#40;not &#40;equal 0.0 &#40;distance p1 p2&#41;&#41;&#41;
             &#40;progn
              &#40;command "_.pline" p1 p2 ""&#41;
              &#40;command "_.pedit" na "_j" na &#40;entlast&#41; "" "_x"&#41;
              &#40;if &#40;equal 1 &#40;logand 1 &#40;cdr &#40;assoc 70 &#40;entget na&#41;&#41;&#41;&#41;&#41;
                  &#40;progn
                   &#40;if &#40;setq b &#40;assoc na lst3&#41;&#41;
                       &#40;setq lst3 &#40;subst &#40;list na nil&#41; b lst3&#41;&#41;;setq then subst
                       &#40;setq lst3 &#40;cons &#40;list na nil&#41; lst3&#41;&#41;;setq else add
                   &#41;;if
                   &#40;setq na nil&#41;
                  &#41;;progn then
              &#41;;if
             &#41;;progn then
         &#41;;if
    
         &#40;cond
          &#40;&#40;not na&#41;
           na
          &#41;;cond #1
          &#40;&#40;and &#40;equal na na2&#41;
                &#40;<= &#40;length &#40;acet-geom-vertex-list na&#41;&#41; 2&#41;;then it's a single segment polyline so don't change it
           &#41;;and
           ;then make the ename inactive by pointing it to nil in the ename map list
           &#40;if &#40;setq b &#40;assoc na2 lst3&#41;&#41;
               &#40;setq lst3 &#40;subst &#40;list na2 nil&#41; b lst3&#41;&#41;;then subst
               &#40;setq lst3 &#40;cons &#40;list na2 nil&#41; lst3&#41;&#41;;setq else add
           &#41;;if
          &#41;;cond #2
          &#40;T
           &#40;acet-spinner&#41;
           &#40;command "_.pedit" na "_j" na na2 "" "_x"&#41;
           ;The na2 is gone now so update the ename map list so that na2 points at na
           &#40;if &#40;setq b &#40;assoc na2 lst3&#41;&#41;
               &#40;setq lst3 &#40;subst &#40;list na2 na&#41; b lst3&#41;&#41;;then subst
               &#40;setq lst3 &#40;cons &#40;list na2 na&#41; lst3&#41;&#41;;setq else add
           &#41;;if
           &#40;if &#40;or &#40;equal na na2&#41;
                   &#40;equal 1 &#40;logand 1 &#40;cdr &#40;assoc 70 &#40;entget na&#41;&#41;&#41;&#41;&#41;
               &#41;;or
               &#40;progn
                ;then na is closed now so update ename map so that it points to nil.
                &#40;if &#40;setq b &#40;assoc na lst3&#41;&#41;
                    &#40;setq lst3 &#40;subst &#40;list na nil&#41; b lst3&#41;&#41;;then subst
                    &#40;setq lst3 &#40;cons &#40;list na nil&#41; lst3&#41;&#41;;setq else add
                &#41;;if
                &#40;setq na nil&#41;
               &#41;;progn then
           &#41;;if
          &#41;;cond #3
         &#41;;cond close
        &#41;;progn then add
        &#40;progn
         ;&#40;print '&#40;equal 0.0 &#40;distance p1 p2&#41;&#41;&#41;
         ;&#40;print &#40;equal 0.0 &#40;distance p1 p2&#41;&#41;&#41;
         ;&#40;print "skipping"&#41;
        &#41;;progn else
    &#41;;if
    
    
    &#40;list lst3 flag&#41; ;return the entity name map and a flag of success or failure for join.
    &#41;;defun acet-pljoin-do-join
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Returns a list of sub-list of the form &#40;roundedpoint originalpoint 0/1 ename&#41;
    ;where 0 mean start point and 1 means end point of the object.
    ;
    &#40;defun acet-pljoin-round &#40; ss g / lst na a b c d n &#41;
    
    ;;&#40;princ "\nCreating data grid of points..."&#41;
    ;;&#40;print "acet-pljoin-round"&#41;
    &#40;setq n 0&#41;
    &#40;repeat &#40;sslength ss&#41;
    &#40;setq na &#40;ssname ss n&#41;
           a &#40;acet-pljoin-get-epoints na&#41;
           b &#40;cadr a&#41;
           a &#40;car a&#41;
    &#41;;setq
    &#40;if &#40;and a b&#41;
        &#40;setq   c &#40;list &#40;acet-calc-round &#40;car a&#41; g&#41;
                        &#40;acet-calc-round &#40;cadr a&#41; g&#41;
                  &#41;;list
                d &#40;list &#40;acet-calc-round &#40;car b&#41; g&#41;
                        &#40;acet-calc-round &#40;cadr b&#41; g&#41;
                  &#41;;list
              lst &#40;cons &#40;list c a 0 na&#41; lst&#41;
              lst &#40;cons &#40;list d b 1 na&#41; lst&#41;
        &#41;;setq then
    &#41;;if
    
    &#40;if &#40;equal n &#40;* &#40;/ n 10&#41; 10&#41;&#41; ;update the spinner once every ten objects
        &#40;acet-spinner&#41;
    &#41;;if
    &#40;setq n &#40;+ n 1&#41;&#41;;setq
    &#41;;repeat
    ;&#40;princ "Done."&#41;
    
    lst
    &#41;;defun acet-pljoin-round
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-get-epoints &#40; na / e1 a b z v &#41;
    
    ;&#40;print "acet-pljoin-get-epoints"&#41;
    ;&#40;print ""&#41;
    
     &#40;if &#40;and &#40;setq e1 &#40;entget na&#41;&#41;
              &#40;setq e1 &#40;acet-lwpline-remove-duplicate-pnts e1&#41;&#41;
         &#41;;and
         &#40;progn
          &#40;setq z &#40;cdr &#40;assoc 38 e1&#41;&#41;&#41;;setq
          &#40;if &#40;not z&#41; &#40;setq z 0.0&#41;&#41;
          &#40;setq v &#40;cdr &#40;assoc 210 e1&#41;&#41;
                a &#40;cdr &#40;assoc 10 e1&#41;&#41;
                a &#40;list &#40;car a&#41; &#40;cadr a&#41; z&#41;
                a &#40;trans a v 1&#41;
               e1 &#40;reverse e1&#41;
                b &#40;cdr &#40;assoc 10 e1&#41;&#41;
                b &#40;list &#40;car b&#41; &#40;cadr b&#41; z&#41;
                b &#40;trans b v 1&#41;
          &#41;;setq
          &#40;setq a &#40;list a b&#41;&#41;
         &#41;;progn then
     &#41;;if;
    
    ;&#40;print "done epoints"&#41;
    
    a
    &#41;;defun acet-pljoin-get-epoints
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Takes an entity list of lwpolylines and modifies the object
    ;removing neighboring duplicate points. If no duplicated points
    ;are found then the object will not be passed to &#40;entmod &#41;.
    ;Returns the new elist when done.
    &#40;defun acet-lwpline-remove-duplicate-pnts &#40; e1 / a n lst e2&#41;
    
    &#40;setq n 0&#41;
    &#40;repeat &#40;length e1&#41;
    &#40;setq a &#40;nth n e1&#41;&#41;;setq
    &#40;cond
     &#40;&#40;not &#40;equal 10 &#40;car a&#41;&#41;&#41;
      &#40;setq e2 &#40;cons a e2&#41;&#41;
     &#41;;cond #1
     &#40;&#40;not &#40;equal &#40;car lst&#41; a&#41;&#41;
      &#40;setq lst &#40;cons a lst&#41;
             e2 &#40;cons a e2&#41;
      &#41;;setq
     &#41;;cond #2
    &#41;;cond close
    &#40;setq n &#40;+ n 1&#41;&#41;;setq
    &#41;;repeat
    &#40;setq e2 &#40;reverse e2&#41;&#41;
    &#40;if &#40;and e2
             &#40;not &#40;equal e1 e2&#41;&#41;
             lst
        &#41;;and
        &#40;progn
         &#40;if &#40;equal 1 &#40;length lst&#41;&#41;
             &#40;progn
              &#40;entdel &#40;cdr &#40;assoc -1 e1&#41;&#41;&#41;
              &#40;setq e2 nil&#41;
             &#41;;progn then single vertex polyline so delete it.
             &#40;progn
              &#40;setq e2 &#40;subst &#40;cons 90 &#40;length lst&#41;&#41; &#40;assoc 90 e2&#41; e2&#41;
              &#41;;setq
              &#40;entmod e2&#41;
             &#41;;progn else
         &#41;;if
        &#41;;progn then
    &#41;;if
    
    e2
    &#41;;defun acet-lwpline-make-remove-duplicate-pnts
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-fillet-with-fuzz &#40; fuzz na p1 tmpe1 na2 p2 tmpe2 /
                                         e1 e2 p1a p2a lst flag flag2 n a
                                         tmpna tmpna2 x y v
                                 &#41;
    
    ;&#40;print "acet-pljoin-fillet-with-fuzz"&#41;
    ;&#40;print ""&#41;
    
    
    &#40;setq  tmpna &#40;cdr &#40;assoc -1 tmpe1&#41;&#41; ;get the temp entitiy names out of the ent lists
          tmpna2 &#40;cdr &#40;assoc -1 tmpe2&#41;&#41;
             lst &#40;acet-pljoin-mod-tmp na p1 tmpe1&#41; ;make the temp ent look like the begining or ending segment
              e1 &#40;car lst&#41;                         ;the modified temp ent list
            flag &#40;cadr lst&#41;                        ;0 or 1 start or end
             p1a &#40;caddr lst&#41;                       ;segment info sub-list &#40;p1 p2 bulge&#41; where p2 is always the endpoint
             lst &#40;acet-pljoin-mod-tmp na2 p2 tmpe2&#41;
              e2 &#40;car lst&#41;
           flag2 &#40;cadr lst&#41;                          ;0 or 1 start or end
             p2a &#40;caddr lst&#41;                         ;segment info sub-list &#40;p1 p2 bulge&#41; ;in entity ucs
             lst &#40;acet-geom-intersectwith tmpna tmpna2 3&#41; ;get the intersection list
               v &#40;cdr &#40;assoc 210 e1&#41;&#41;
             lst &#40;acet-geom-m-trans lst 0 v&#41; ;trans to entity coord system
    &#41;;setq
    
    &#40;if lst
        &#40;progn
         &#40;setq x &#40;acet-pljoin-get-best-int p1a lst&#41;&#41;            ;get the best intersection
         &#40;setq y &#40;acet-pljoin-get-best-int p2a lst&#41;&#41;            ;get the best intersection
         ;put the best intersections in the list x
         &#40;cond
          &#40;&#40;and x y&#41;
           &#40;setq x &#40;list x y&#41;&#41;
          &#41;;cond #1
          ;;&#40;x &#40;setq x &#40;list x&#41;&#41;&#41; ;commented because both objects must pass the best intersect test
          ;;&#40;y &#40;setq x &#40;list y&#41;&#41;&#41;
          &#40;T &#40;setq x nil&#41;&#41;
         &#41;;cond
         &#40;if &#40;and x
                  &#40;setq x &#40;acet-geom-m-trans x v 1&#41;&#41;
                  &#40;setq x &#40;acet-pljoin-get-closest-int p1 p2 x&#41;&#41;
                  &#40;<= &#40;distance p1 x&#41; fuzz&#41;
                  &#40;<= &#40;distance p2 x&#41; fuzz&#41;
             &#41;;and
             &#40;progn
              &#40;acet-pljoin-fillet-mod-epoint e1 flag x&#41;
              &#40;if &#40;equal na na2&#41;
                  &#40;setq e2 &#40;entget na&#41;&#41;
              &#41;;if
              &#40;acet-pljoin-fillet-mod-epoint e2 flag2 x&#41;
              &#40;setq lst &#40;list x x&#41;&#41;
             &#41;;progn then
             &#40;setq lst &#40;list p1 p2&#41;&#41;
         &#41;;if
    
        &#41;;progn then
        &#40;setq lst &#40;list p1 p2&#41;&#41;
    &#41;;if
    
    lst
    &#41;;defun acet-pljoin-fillet-with-fuzz
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;takes&#58;
    ; a  - segment info sub-list &#40;p1 p2 bulge&#41; where p2 is always the endpoint
    ; lst - list of intersections
    ;returns the best candidate
    ;
    &#40;defun acet-pljoin-get-best-int &#40; a lst / p1 p2 a1 a2 n j b c d nb &#41;
    
    ;&#40;print "acet-pljoin-get-best-int"&#41;
    ;&#40;print ""&#41;
    
    &#40;setq p1 &#40;car a&#41;   ;the iner segement
          p2 &#40;cadr a&#41;  ;the end point &#40;first or last&#41;
           b &#40;caddr a&#41; ;the bulge
    &#41;;setq
    &#40;if &#40;equal b 0.0&#41;
        &#40;setq a1 &#40;angle p1 p2&#41;&#41;                      ;line segment so get the angle
        &#40;setq a1 &#40;caddr &#40;acet-geom-pline-arc-info p1 p2 b&#41;&#41;&#41; ;arc segment, so get delta angle from arc_info
    &#41;;if
    &#40;setq n 0&#41;
    &#40;repeat &#40;length lst&#41;
    &#40;setq a &#40;nth n lst&#41;&#41;
    &#40;if &#40;equal b 0.0&#41;
        &#40;progn
         ;the it's a line segment
         &#40;if &#40;and &#40;or &#40;equal &#40;angle p1 a&#41; a1 #acet-pljoin-prec&#41;                  &#40;equal &#40;abs &#40;- &#40;angle p1 a&#41; a1&#41;&#41;
                             &#40;* 2.0 pi&#41;
                             #acet-pljoin-prec
                      &#41;
                  &#41;;or
                  &#40;or &#40;not d&#41;
                      &#40;< &#40;setq c &#40;distance p2 a&#41;&#41; d&#41;
                  &#41;;or
             &#41;;and
             &#40;progn
              &#40;setq d c
                    j n
              &#41;;setq
             &#41;;progn then
         &#41;;if
        &#41;;progn then line segment
        &#40;progn
         &#40;if &#40;equal p1 a #acet-pljoin-prec&#41;
             &#40;progn
              &#40;setq a2 &#40;* pi 2.0
                          &#40;/ &#40;abs a1&#41; a1&#41;
                       &#41;;mult
              &#41;;setq then make it 360 degrees and preserve the sign.
             &#41;;progn then
             &#40;progn
              &#40;setq nb &#40;acet-pljoin-calc-new-bulge p1 b p2 a&#41;
                    a2 &#40;acet-geom-pline-arc-info p1 a nb&#41;
                    a2 &#40;caddr a2&#41; ;delta angle
              &#41;;setq
             &#41;;progn else
         &#41;;if
         &#40;setq c &#40;abs &#40;- &#40;abs a2&#41;
                         &#40;abs a1&#41;
                      &#41;
                 &#41;
         &#41;;setq
         &#40;if &#40;and &#40;>= &#40;* a2 a1&#41; 0.0&#41; ;same sign delta angle
                  &#40;or &#40;not d&#41;
                      &#40;< c d&#41;
                  &#41;;or
             &#41;;and
             &#40;progn
              &#40;setq d c
                    j n
              &#41;;setq
             &#41;;progn then
         &#41;;if
        &#41;;progn else
    &#41;;if
    &#40;setq n &#40;+ n 1&#41;&#41;;setq
    &#41;;repeat
    &#40;if j
        &#40;setq d &#40;nth j lst&#41;&#41;
        &#40;setq d nil&#41;
    &#41;;if
    
    ;;;for debuging only
    ;&#40;d-point p1 "1"&#41;
    ;&#40;d-point p2 "2"&#41;
    ;&#40;if d &#40;d-point d "3"&#41;&#41;;if
    ;&#40;print 'p1&#41;
    ;&#40;print p1&#41;
    ;&#40;print 'lst&#41;
    ;&#40;print lst&#41;
    ;&#40;print d&#41;
    ;&#40;if d
    ;    &#40;progn
    ;     &#40;getstring "\n\nit thinks this is   COOL"&#41;
    ;    &#41;;progn then
    ;    &#40;getstring "\n\nit thinks this   SUCKs"&#41;
    ;&#41;;if
    ;&#40;entdel &#40;entlast&#41;&#41;
    ;&#40;entdel &#40;entlast&#41;&#41;
    ;&#40;if d &#40;entdel &#40;entlast&#41;&#41;&#41;;if
    
    d
    &#41;;defun acet-pljoin-get-best-int
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-get-closest-int &#40; p1 p2 lst / n a j d &#41;
    
    &#40;setq n 0&#41;
    &#40;repeat &#40;length lst&#41;
    &#40;setq a &#40;nth n lst&#41;
          a &#40;+ &#40;distance a p1&#41; &#40;distance a p2&#41;&#41;
    &#41;;setq
    &#40;if &#40;or &#40;not d&#41;
            &#40;< a d&#41;
        &#41;;or
        &#40;setq d a
              j n
        &#41;;setq
    &#41;;if
    &#40;setq n &#40;+ n 1&#41;&#41;;setq
    &#41;;repeat
    &#40;if j
        &#40;setq a &#40;nth j lst&#41;&#41;
        &#40;setq a nil&#41;
    &#41;;if
    
    a
    &#41;;defun acet-pljoin-get-closest-int
    
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-fillet-mod-epoint &#40; e1 flag x / p1 p2 a b e2 blg n v&#41;
    
    ;&#40;print "acet-pljoin-fillet-mod-epoint"&#41;
    ;&#40;print ""&#41;
    
    &#40;setq v &#40;cdr &#40;assoc 210 e1&#41;&#41;
          x &#40;trans x 1 v&#41;
          ;x &#40;trans x 1 &#40;cdr &#40;assoc -1 e1&#41;&#41;&#41;
          x &#40;list &#40;car x&#41; &#40;cadr x&#41;&#41;
    &#41;;setq
    
    &#40;if &#40;equal flag 1&#41;
        &#40;setq e1 &#40;reverse e1&#41;&#41;
    &#41;;if
    &#40;setq n 0&#41;
    &#40;while &#40;and e1
                &#40;not p2&#41;
           &#41;;and
     &#40;setq  a &#40;car e1&#41;
           e1 &#40;cdr e1&#41;
           e2 &#40;cons a e2&#41;
     &#41;;setq
     &#40;cond
      &#40;&#40;equal 10 &#40;car a&#41;&#41;
       &#40;if &#40;not p1&#41;
           &#40;setq p1 n&#41;
           &#40;setq p2 n&#41;
       &#41;;if
      &#41;;cond #1
      &#40;&#40;and p1
            &#40;equal 42 &#40;car a&#41;&#41;
       &#41;;and
       &#40;setq b n&#41;
      &#41;;cond #2
     &#41;;cond close
    &#40;setq n &#40;+ n 1&#41;&#41;
    &#41;;while
    &#40;setq e2 &#40;reverse e2&#41;&#41;
    &#40;if &#40;equal 0.0 &#40;cdr &#40;nth b e2&#41;&#41;&#41;
        &#40;setq e2 &#40;acet-list-put-nth &#40;cons 10 x&#41; e2 p1&#41;&#41;;setq then line segment
        &#40;progn
         &#40;if &#40;equal flag 0&#41;
             &#40;setq blg &#40;acet-pljoin-calc-new-bulge &#40;cdr &#40;nth p2 e2&#41;&#41;
                                                  &#40;* -1.0 &#40;cdr &#40;nth b e2&#41;&#41;&#41;
                                                  &#40;cdr &#40;nth p1 e2&#41;&#41;
                                                  x
                       &#41;
                    e2 &#40;acet-list-put-nth &#40;cons 42 &#40;* -1.0 blg&#41;&#41; e2 b&#41;
                    e2 &#40;acet-list-put-nth &#40;cons 10 x&#41; e2 p1&#41;
             &#41;;setq then
             &#40;setq blg &#40;acet-pljoin-calc-new-bulge &#40;cdr &#40;nth p2 e2&#41;&#41;
                                                  &#40;cdr &#40;nth b e2&#41;&#41;
                                                  &#40;cdr &#40;nth p1 e2&#41;&#41;
                                                  x
                       &#41;
                    e2 &#40;acet-list-put-nth &#40;cons 42 blg&#41; e2 b&#41;
                    e2 &#40;acet-list-put-nth &#40;cons 10 x&#41; e2 p1&#41;
             &#41;;setq then
         &#41;;if
        &#41;;progn else arc segment
    &#41;;if
    &#40;setq e1 &#40;append e2 e1&#41;&#41;
    &#40;if &#40;equal flag 1&#41;
        &#40;setq e1 &#40;reverse e1&#41;&#41;
    &#41;;if
    &#40;entmod e1&#41;
    
    &#41;;defun acet-pljoin-fillet-mod-epoint
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Make the temporary ent match the segment of interest to get ready to
    ;use the intersectwith method.
    ;Takes an entity name and a point that is on one end of the entity
    ;and a entity list of a single segment lwpolyline
    ;modifies the single segment polyline such that it matches the
    ;first or last segment &#40;depending on the p1 provided&#41; of the
    ;polyline 'na'
    ;
    &#40;defun acet-pljoin-mod-tmp &#40; na p1 tmpe1 / e1 e2 a b z p2 flag v &#41;
    
    &#40;setq    e1 &#40;entget na&#41;
              v &#40;cdr &#40;assoc 210 e1&#41;&#41;
             p1 &#40;trans p1 1 v&#41;
             p1 &#40;list &#40;car p1&#41; &#40;cadr p1&#41;&#41;
          tmpe1 &#40;subst &#40;assoc 38 e1&#41;  &#40;assoc 38 tmpe1&#41;  tmpe1&#41;
          tmpe1 &#40;subst &#40;assoc 39 e1&#41;  &#40;assoc 39 tmpe1&#41;  tmpe1&#41;
          tmpe1 &#40;subst &#40;assoc 210 e1&#41; &#40;assoc 210 tmpe1&#41; tmpe1&#41;
              z &#40;cdr &#40;assoc 38 e1&#41;&#41;
              a &#40;assoc 10 e1&#41;
    &#41;;setq
    
    &#40;if &#40;equal &#40;cdr a&#41; p1 #acet-pljoin-prec&#41;
        &#40;progn
         &#40;setq  flag 0
               tmpe1 &#40;reverse tmpe1&#41;
               tmpe1 &#40;subst a &#40;assoc 10 tmpe1&#41; tmpe1&#41;
               tmpe1 &#40;reverse tmpe1&#41;
                  e2 &#40;cdr &#40;member &#40;assoc 10 e1&#41; e1&#41;&#41;
                  p2 &#40;list &#40;car p1&#41; &#40;cadr p1&#41; z&#41;
                  p1 &#40;cdr &#40;assoc 10 e2&#41;&#41;
                  p1 &#40;list &#40;car p1&#41; &#40;cadr p1&#41; z&#41;
               tmpe1 &#40;subst &#40;assoc 10 e2&#41; &#40;assoc 10 tmpe1&#41; tmpe1&#41;
                   b &#40;* -1.0 &#40;cdr &#40;assoc 42 e2&#41;&#41;&#41;
               tmpe1 &#40;subst &#40;cons 42 b&#41;
                            &#40;assoc 42 tmpe1&#41;
                            tmpe1
                     &#41;
         &#41;;setq
        &#41;;progn then
        &#40;progn
         &#40;setq  flag 1
                  e2 &#40;reverse e1&#41;
               tmpe1 &#40;reverse tmpe1&#41;
                   a &#40;assoc 10 e2&#41;
                  p2 &#40;cdr a&#41;
                  p2 &#40;list &#40;car p2&#41; &#40;cadr p2&#41; z&#41;
               tmpe1 &#40;subst a &#40;assoc 10 tmpe1&#41; tmpe1&#41;
                  e2 &#40;cdr &#40;member a e2&#41;&#41;
                  p1 &#40;cdr &#40;assoc 10 e2&#41;&#41;
                  p1 &#40;list &#40;car p1&#41; &#40;cadr p1&#41; z&#41;
                   b &#40;cdr &#40;assoc 42 e2&#41;&#41;
               tmpe1 &#40;reverse tmpe1&#41;
               tmpe1 &#40;subst &#40;cons 42 b&#41; &#40;assoc 42 tmpe1&#41; tmpe1&#41;
                   a &#40;assoc 10 e2&#41;
               tmpe1 &#40;subst &#40;assoc 10 e2&#41; &#40;assoc 10 tmpe1&#41; tmpe1&#41;
         &#41;;setq
        &#41;;progn else
    &#41;;if
    
    &#40;entmod tmpe1&#41;
    
    &#40;list e1 flag &#40;list p1 p2 b&#41;&#41;
    &#41;;defun acet-pljoin-mod-tmp
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Calculates the new bulge formed by moving
    ;point p2 to p3 and still retaining the same radius and center point.
    ;
    &#40;defun acet-pljoin-calc-new-bulge &#40; p1 b p2 p3 / p4 x r a c b2 info &#41;
    
    &#40;setq c &#40;distance p1 p3&#41;&#41;
    &#40;if &#40;not &#40;equal c 0.0&#41;&#41;
        &#40;progn
         &#40;setq   p4 &#40;acet-geom-midpoint p1 p3&#41;
               info &#40;acet-geom-pline-arc-info p1 p2 b&#41;
                  r &#40;cadr info&#41;;radius
                  x &#40;car info&#41; ;center point
                  a &#40;- r
                       &#40;distance x p4&#41;
                    &#41;
         &#41;;setq
         &#40;setq b2 &#40;/ &#40;* 2.0 a&#41; c&#41;
               b2 &#40;* b2 &#40;/ &#40;abs b&#41; b&#41;&#41;
         &#41;;setq
         &#40;setq info &#40;acet-geom-pline-arc-info p1 p3 b2&#41;&#41;
         &#40;if &#40;not &#40;equal x &#40;car info&#41; #acet-pljoin-prec&#41;&#41;
             &#40;progn
              &#40;setq a &#40;- &#40;* r 2.0&#41; a&#41;&#41;;setq
              &#40;setq b2 &#40;/ &#40;* 2.0 a&#41; c&#41;
                    b2 &#40;* b2 &#40;/ &#40;abs b&#41; b&#41;&#41;
              &#41;;setq
             &#41;;progn then
         &#41;;if
        &#41;;progn then
        &#40;setq b2 0.0&#41;
    &#41;;if
    
    b2
    &#41;;defun acet-pljoin-calc-new-bulge
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;- explode all curve fitted and/or splined plines and re-join
    ;- convert all to light weight plines.
    ;- turn all arcs and lines into lightweight plines.
    ;- finally return a selection set of all plines.
    &#40;defun acet-pljoin-do-ss-pre-work &#40; ss flt / na ss2 ss3 n w&#41;
    
    
    &#40;command "_.select" ss ""&#41;
    &#40;setq ss2 &#40;ssget "_p" '&#40;&#40;-4 . "&"&#41; &#40;70 . 6&#41;&#41;&#41;&#41; ;fit or splined
    &#40;command "_.select" ss ""&#41;
    &#40;setq ss3 &#40;ssget "_p" '&#40;&#40;-4 . "<OR"&#41; &#40;0 . "LINE"&#41; &#40;0 . "ARC"&#41; &#40;-4 . "OR>"&#41;&#41;&#41;&#41; ;lines and arcs
    
    &#40;if ss2
        &#40;progn
         &#40;setq n 0&#41;
         &#40;repeat &#40;sslength ss2&#41;
         &#40;setq na &#40;ssname ss2 n&#41;
                w &#40;acet-pljoin-get-width na&#41;
         &#41;;setq
         &#40;command "_.explode" na&#41;
         &#40;while &#40;wcmatch &#40;getvar "cmdnames"&#41; "*EXPLODE*"&#41; &#40;command ""&#41;&#41;
         &#40;command "_.pedit" &#40;entlast&#41; "_y" "_j" "_p" ""&#41;
         &#40;if &#40;not &#40;equal w 0.0&#41;&#41;
             &#40;command "_w" w&#41;
         &#41;;if
         &#40;command "_x"&#41;
         &#40;setq ss &#40;ssdel na ss&#41;
               ss &#40;ssadd &#40;entlast&#41; ss&#41;
         &#41;;setq
         &#40;setq n &#40;+ n 1&#41;&#41;;setq
         &#41;;repeat
        &#41;;progn then
    &#41;;if
    &#40;command "_.convertpoly" "_light" ss ""&#41;
    &#40;if ss3
        &#40;progn
         &#40;setq n 0&#41;
         &#40;repeat &#40;sslength ss3&#41;
          &#40;setq na &#40;ssname ss3 n&#41;&#41;;setq
          &#40;command "_.pedit" na "_y" "_x"&#41;
          &#40;setq ss &#40;ssdel na ss&#41;
                ss &#40;ssadd &#40;entlast&#41; ss&#41;
          &#41;;setq
         &#40;setq n &#40;+ n 1&#41;&#41;;setq
        &#41;;repeat
       &#41;;progn then
    &#41;;if
    &#40;if &#40;equal 0 &#40;sslength ss&#41;&#41;
        &#40;setq ss nil&#41;
    &#41;;if
    &#40;setq ss &#40;acet-pljoin-ss-flt ss flt&#41;&#41;
    
    
    ss
    &#41;;defun acet-pljoin-do-ss-pre-work
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;return the with of the heavy polyline provided in 'na'
    &#40;defun acet-pljoin-get-width &#40; na / e1 a b&#41;
    
    &#40;if &#40;and &#40;setq e1 &#40;entget na&#41;&#41;
             &#40;equal &#40;cdr &#40;assoc 0 e1&#41;&#41; "POLYLINE"&#41;
        &#41;;and
        &#40;progn
         &#40;setq a &#40;cdr &#40;assoc 40 e1&#41;&#41;
               b &#40;cdr &#40;assoc 41 e1&#41;&#41;
         &#41;;setq
         &#40;while &#40;and &#40;equal a b&#41;
                     &#40;setq na &#40;entnext na&#41;&#41;
                     &#40;setq e1 &#40;entget na&#41;&#41;
                     &#40;not &#40;equal &#40;cdr &#40;assoc 0 e1&#41;&#41; "SEQEND"&#41;&#41;
                &#41;;and
          &#40;setq a &#40;cdr &#40;assoc 40 e1&#41;&#41;
                b &#40;cdr &#40;assoc 41 e1&#41;&#41;
          &#41;;setq
         &#41;;while
        &#41;;progn then
        &#40;setq a 0.0&#41;
    &#41;;if
    a
    &#41;;defun acet-pljoin-get-width
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-ss-flt &#40; ss flt / n na e1 p1 p2 &#41;
    &#40;if &#40;and ss
             &#40;> &#40;sslength ss&#41; 0&#41;
        &#41;;and
        &#40;progn
         &#40;command "_.select" ss ""&#41;
         &#40;setq ss &#40;ssget "_p" flt&#41;&#41;
        &#41;;progn then
        &#40;setq ss nil&#41;
    &#41;;if
    
    ss
    &#41;;defun acet-pljoin-ss-flt
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun c&#58;pljoinmode &#40; / &#41;
    &#40;acet-error-init nil&#41;
     &#40;acet-pljoinmode&#41;
    &#40;acet-error-restore&#41;
    &#41;;defun c&#58;pljoinmode
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;prompt for a joinmode setting of "Fillet" or "Add"
    &#40;defun acet-pljoinmode &#40; / st &#41;
      &#40;acet-pljoin-init-mode&#41;
      &#40;initget "Fillet Add Both _Fillet Add Both"&#41;
      &#40;setq st &#40;getkword
                &#40;acet-str-format "\nEnter join type &#91;Fillet/Add/Both&#93; <%1>&#58; " #acet-pljoinmode&#41;
               &#41;;getkword
      &#41;;setq
      &#40;if st
          &#40;progn
           &#40;setq #acet-pljoinmode st&#41;
           &#40;acet-setvar &#40;list "ACET-PLJOINMODE" #acet-pljoinmode 2&#41;&#41;
          &#41;;progn
      &#41;;if
    &#41;;defun acet-pljoinmode
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    &#40;defun acet-pljoin-init-mode &#40;&#41;
     &#40;if &#40;not #acet-pljoinmode&#41;
         &#40;setq #acet-pljoinmode &#40;acet-getvar '&#40;"ACET-PLJOINMODE" 2&#41;&#41;&#41;
     &#41;;if
     &#40;if &#40;not #acet-pljoinmode&#41;
         &#40;progn
          &#40;setq #acet-pljoinmode "Both"&#41;
          &#40;acet-setvar &#40;list "ACET-PLJOINMODE" #acet-pljoinmode 2&#41;&#41;
         &#41;;progn then
     &#41;;if
     #acet-pljoinmode
    &#41;;defun acet-pljoin-init-mode
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;prompt for fuzz distance and/or pljoinmode setting.
    ;return list... &#40;fuzz pljoinmode&#41;
    ;
    &#40;defun acet-pljoin-get-fuzz-and-mode &#40; / st fuzz &#41;
      &#40;setq st &#40;acet-pljoin-init-mode&#41;&#41;
      &#40;princ &#40;acet-str-format "\n Join Type = %1" st&#41;&#41;
      &#40;if &#40;equal "Both" st&#41;
          &#40;princ " &#40;Fillet and Add&#41; "&#41;
      &#41;;if
      &#40;if &#40;not #acet-pljoin-fuzz&#41;
          &#40;setq #acet-pljoin-fuzz 0.0&#41;
      &#41;;if
      &#40;setq fuzz ""&#41;
      &#40;while &#40;equal &#40;type fuzz&#41; 'STR&#41;
       &#40;initget "Jointype _Jointype" 4&#41;
       &#40;setq fuzz &#40;getdist
                    &#40;acet-str-format "\nEnter fuzz distance or &#91;Jointype&#93; <%1>&#58; " &#40;rtos #acet-pljoin-fuzz&#41;&#41;
                  &#41;;getdist
       &#41;;setq
       &#40;cond
        &#40;&#40;not fuzz&#41;
         &#40;setq fuzz #acet-pljoin-fuzz&#41;
        &#41;;cond #1
        &#40;&#40;equal "Jointype" fuzz&#41;
         &#40;acet-pljoinmode&#41;
        &#41;;cond #2
        &#40;&#40;equal &#40;type fuzz&#41; 'REAL&#41;
         &#40;setq #acet-pljoin-fuzz fuzz&#41;
        &#41;;cond #3
       &#41;;cond close
      &#41;;while
      &#40;list #acet-pljoin-fuzz #acet-pljoinmode&#41;
    &#41;;defun acet-pljoin-get-fuzz-and-mode
    
    
    &#40;princ&#41;
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;&#40;defun acet-pljoin-fuzzy-member &#40; x lst / n flag &#41;
    ; &#40;setq n 0&#41;
    ; &#40;while &#40;and &#40;< n &#40;length lst&#41;&#41;
    ;             &#40;not &#40;setq flag &#40;equal &#40;nth n lst&#41; x #acet-pljoin-prec&#41;&#41;&#41;
    ;        &#41;;and
    ; &#40;setq n &#40;+ n 1&#41;&#41;
    ; &#41;;while
    ;flag
    ;&#41;;defun acet-pljoin-fuzzy-member
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;&#40;defun c&#58;f &#40; / p1 p2 na na2 e1 e2 &#41;
    ;&#40;setq  na &#40;car &#40;entsel "1"&#41;&#41;
    ;       p1 &#40;getpoint "p1"&#41;
    ;       e1 &#40;entget &#40;car &#40;entsel "e1"&#41;&#41;&#41;
    ;      na2 &#40;car &#40;entsel "2"&#41;&#41;
    ;       p2 &#40;getpoint "p2"&#41;
    ;       e2 &#40;entget &#40;car &#40;entsel "e2"&#41;&#41;&#41;
    ;&#41;;setq
    ;&#40;acet-pljoin-fillet-with-fuzz #acet-pljoin-fuzz na p1 e1 na2 p2 e2&#41;
    ;&#41;;defun c&#58;f
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;&#40;defun c&#58;x &#40;&#41;
    ;
    ;&#40;acet-pljoin-fillet-mod-epoint &#40;entget &#40;car &#40;entsel&#41;&#41;&#41; 1 &#40;getpoint "pick"&#41;&#41;
    ;
    ;&#41;;defun c&#58;x
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;&#40;defun d-point &#40; p1 c / &#41;
    ; &#40;setvar "pdmode" 2&#41;
    ; &#40;setvar "cecolor" c&#41;
    ; &#40;command "_.point" p1&#41;
    ;&#41;;defun d-point
    erona

    "AutoCAD habangbuhay" not anymore... moved to Vectorworks>Cinema4D

    Just got back to AutoCAD. Modeling directly in C4D.

  3. #3
    Forum Newbie
    Using
    not specified
    Join Date
    Jun 2005
    Posts
    5

    Default

    i saved the code as lsp, loaded the command in 2005, it loaded succesfuly, but when I tested it I've got an error:

    Command: pljoin
    ; error: no function definition: ACET-ERROR-INIT

    do I make a mistake?

    thanks again

  4. #4
    Senior Member erona's Avatar
    Using
    AutoCAD 2007
    Join Date
    Feb 2005
    Location
    Philippines
    Posts
    306

    Default

    I think it should work on 2005 since its almost the same as 2004 (not sure tho) but it works seamlessly with 2004.

    Others here might give a more definite answer to your question.
    erona

    "AutoCAD habangbuhay" not anymore... moved to Vectorworks>Cinema4D

    Just got back to AutoCAD. Modeling directly in C4D.

  5. #5
    Junior Member Rbtdanforth's Avatar
    Using
    not specified
    Join Date
    Mar 2006
    Posts
    20

    Default pline makers

    As I am usually trying to accomplish cad when I decide to do lisp I tend to write them pretty sparse and direct, an rarely foolproof, as I am usually the primary user, and would rather adjust me than spend a lot of programmming to make sure I was adjusted

    Years ago I got angry with Pedit's multi level commands and wrote stuff to accomplish specific jobs with one command. As versions have gone from V-10 to 2005 they have gotten less reliable, but still work in the majority of circumstances.

    In any case since all I wanted was to reduce several commands to one that is just what I did as follows,
    ;PLINE MAKER
    (defun CLN ( / LN C ENT EN R)
    ( setq LN (SSGET)
    C (SSLENGTH LN)
    )
    (WHILE (> C 0)(PROGN (PRINC C)(PRINC " " )
    (SETQ C (1- C)
    ENT (SSNAME LN C)
    EN (ENTGET ENT) R (ASSOC 70 EN)
    )(COND ((= 1 (CDR R))(PRINT "CLOSED"))
    ((NOT EN )(PRINC C))
    ((WCMATCH (CDR (ASSOC 0 EN)) "P*L*" ) (COMMAND "PEDIT" ENT "J" LN "" "X"))
    ( (WCMATCH (CDR (ASSOC 0 EN)) "LI*,ARC")(COMMAND "PEDIT" ENT "" "J" LN "" "X") )
    ((= 1 1)(PROGN(PRINC C)(PRINT "?") )) );COND
    ) ) ^P );PROGN1 WHILE DEFUN

    It spits out a few comments to alert me to issues but otherwise just does the job. Written today I might do a ssnamex and foreach rather than a while loop, but while loops work, and ssnamex didn't exist then.

  6. #6
    Junior Member Rbtdanforth's Avatar
    Using
    not specified
    Join Date
    Mar 2006
    Posts
    20

    Default Aec error init

    As to the error in question I would guess that Erona has a subroutine in her Acad lisp or some autoloaded function that defuns Aect-error-init, as I don't see such a function defined above.

    While subfunctions in acad.lsp can be helpful they can certainly make for so much interdependance, and obscuring the program, that it can cause just such inadvertant maiming. I looked down that road early on and decided that I would leave subroutines in the routine using them.

    I find that cut and paste of subroutines each time needed is cheap insurance against such maiming. Just as I prefer updatable blocks to nested xrefs that can have similar issues. IMHO

  7. #7
    Senior Member
    Using
    not specified
    Join Date
    Dec 2004
    Location
    YUL
    Posts
    484

    Default

    Registered forum members do not see this ad.

    Code:
    &#40;defun c&#58;pj &#40;/ ss oecho&#41;
    	oecho &#40;getvar "cmdecho"&#41;&#41;
      &#40;setvar "cmdecho" 0&#41;
      &#40;if &#40;setq ss &#40;ssget '&#40;&#40;-4 . "<OR"&#41;
                            &#40;0 . "LINE,ARC"&#41;
                            &#40;-4 . "<AND"&#41;      ;
                            &#40;0 . "LWPOLYLINE"&#41; ;
                            &#40;-4 . "<not"&#41;      ;
                            &#40;-4 . "&"&#41;;  ??    ; = AND loop
                            &#40;70 . 1&#41;           ;
                            &#40;-4 . "NOT>"&#41;      ;
                            &#40;-4 . "AND>"&#41;      ;
                            &#40;-4 . "OR>"&#41;
                           &#41;
                   &#41;
          &#41;
        &#40;if &#40;= &#40;cdr &#40;assoc 0 &#40;entget &#40;ssname ss 0&#41;&#41;&#41;&#41; "LWPOLYLINE"&#41;
          &#40;command ".pedit" ss "j" ss "" ""&#41;
          &#40;command ".pedit" ss "y" "j" ss "" ""&#41;
        &#41;
      &#41;
      &#40;setvar "cmdecho" oecho&#41;
      &#40;princ&#41;
    &#41;
    Thanks to CAB's elegant contribution, here is what you need.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts