Author Topic: AutoCAD 2010 quick fix reminder for polyline issues  (Read 4651 times)

0 Members and 1 Guest are viewing this topic.

KewlToyZ

  • Guest
AutoCAD 2010 quick fix reminder for polyline issues
« on: August 14, 2009, 11:48:08 AM »


FYI, using stretch on polylines produces some really funky bugs in 2010 products.
Use the following and you shouldn't have any trouble until the service pack is issued.

;Acad2010doc.lsp
;===============================================================================
; Turn off command line responses
(setvar "CMDECHO" 0)
;===============================================================================
(command "convert" "Polyline" "All")
(prompt"\n   Converted polylines to fix 2010 formatting.....\n")
;===============================================================================
; Turn on command line responses
(setvar "CMDECHO" 1)
;===============================================================================

GDF

  • Water Moccasin
  • Posts: 2081
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #1 on: August 14, 2009, 02:20:43 PM »
I have not seen this problem...yet.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

James Cannon

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #2 on: August 14, 2009, 02:28:23 PM »
I have not seen this problem...yet.

Ditto.

What issues have there been?

I draw my 2D objects almost exclusively as polylines, and have not had any problemos in vanilla bean 20.10.

KewlToyZ

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #3 on: August 14, 2009, 02:38:48 PM »
Try stretching the items in the white square:
Notice the loops on the leaders, the insertion point remains stationary while the rest moves...
Works normally when using 2007-2009
Didnt work right in 2010 until I added this code to my acad2010doc.lsp

James Cannon

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #4 on: August 14, 2009, 02:55:26 PM »
Try stretching the items in the white square:
Notice the loops on the leaders, the insertion point remains stationary while the rest moves...
Works normally when using 2007-2009
Didnt work right in 2010 until I added this code to my acad2010doc.lsp

Gotcha.  That's very odd.  I can't even understand why it does what it is doing with your fake-ellipses.

Btw, why not use a real ellipse, or 4 arc segments like how you draw an ISO circle the by-hand way? (before I discovered circle/ellipse templates...)

KewlToyZ

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #5 on: August 14, 2009, 03:02:31 PM »
The routine allows the user to select the span for each end of the Polyline ellipse while making the leader.
A Stanadard Ellipse just doesnt work for that.


Code: [Select]
; EL.LSP VER 2, AUGUST 13, 1997
;
; A program by Grant A. Vogl
;
; EL is designed to make a leader with an ellipse, while
; giving the user the option to "stretch" the ellipse to
; another line.

  (defun C:ellipseleader ( / curosnap ortho cmd c1 p2 ds cl elev ang1
  break1 break2 end1 pell el1 line1 pickp3
  p3 ang2 line2 pickline ent entpt1 entpt2
  c2 line2pick name ltr line break3 break4
  end2 el2 line3 line4 vert horz intvert
  inthorz p2horz p2vert p2new p3new *error*
    )
  ;; Added by Chris Moor ====================================================
(setq ds (getvar "dimscale"))
(setq usersnaps (getvar "osmode")) ; -----------------------Get User Osmode Settings
(setq userlayer (getvar "clayer")) ; -----------------------Get User Layer Settings
;(setq userpol (getvar "polarang")) ; -----------------------Get User Polar Angle Settings
(setq userauto (getvar "autosnap")) ; -----------------------Get User Polar Mode Settings
  ;; Added by Chris Moor ====================================================
 
  ;  Error condition for exit to restore osnaps -------------------------------------------------------------------------------
  (DEFUN *error* (errormessage /)
      (COND ((NOT errormessage))                              ; no error, do nothing       
            ((VL-POSITION (STRCASE errormessage T)            ; cancel
                          '("console break"
                            "function cancelled"
                            "quit / exit abort"
                           )                           
             )
            )
            (setvar "osmode" usersnaps)
            (princ "\n Osnaps returned.") ; return osnaps
            ((PRINC (STRCAT "\nApplication Error: "
                            (GETVAR "errno")
                            " :- "
                            errormessage
                    )                 
             )
            )
      )
(command "osmode" usersnaps) ; -----------------------Return User Osmode Settings
(command "autosnap" userauto) ; -----------------------Return User Polar Mode Settings
(command "clayer" userlayer) ; -----------------------Return User Layer Settings
(command "polarang" userpol) ; -----------------------Return User Polar Angle Settings
  (princ "\n Ellipse Leader Osnaps & Layer Returned.l --Error Catch--")
  )
;  Error condition for exit to restore osnaps -------------------------------------------------------------------------------
     (command "undo" "begin")

; Save system variables.

     (setq curosnap (getvar "osmode"))
     (setq ortho (getvar "orthomode"))
     (setq cmd (getvar "cmdecho"))

; Prompt the user to begin the first leader line.

     (command "cmdecho" 0)
     (command "osnap" "nea")
     (princ "\nLEADER with ellipse.")
     (setq c1 (getpoint "\nPick beginning of leader <return to exit>: "))

; If the user picks the first point, prompt the user to end the
; first leader line.  Otherwise, exit the "if" statement.

     (if c1
(progn
   (command "osnap" "")
   (command "ortho" "off")
   (setq c1 (list (car c1) (car (cdr c1)) 0))
   (setq p2 (getpoint c1 "\nPick end of leader line <return to exit>: "))

; If the user picks the second point, draw the first leader line
; and the ellipse, and prompt the user to end the second leader
; line.  Otherwise, exit the "if" statement.

   (if p2
      (progn
(setq p2 (list (car p2) (car (cdr p2)) 0))
(setq ds (getvar "dimscale"))
(setq cl (getvar "clayer"))
(setq elev (getvar "elevation"))
(command "elevation" 0)

; The first leader line has a minimum length based on the
; dimscale.

(setq ang1 (angle c1 p2))
(if (< (distance c1 p2) (* ds (/ 13 96.0)))
    (setq p2 (polar c1 ang1 (* ds (/ 13 96.0))))
)
(setq break1 (polar c1 (+ ang1 (/ pi 2)) (/ ds 48.0)))
(setq break2 (polar c1 (- ang1 (/ pi 2)) (/ ds 48.0)))
(setq end1 (polar c1 ang1 (/ ds 24.0)))
(command "layer" "m" "G-ANNO-TEXT" "")
(setq pell (getvar "pellipse"))
(command "pellipse" 1)
(command "ellipse" break1 break2 end1)
(setvar "pellipse" pell)
(setq el1 (entlast))
(command "line" end1 p2 "")
(setq line1 (entlast))
(setvar "clayer" cl)
(setvar "elevation" elev)

; While the user continues picking a non-horizontal elbow,
; keep asking the user to pick the end of the elbow.  If the
; user picks the third point, draw the short horizontal
; line, called an elbow, hook line, dogleg, or landing.
; Otherwise, exit the "while" statement.

(setq pickp3 1)
(while (= pickp3 1)
    (progn
       (command "ortho" "on")
       (setq p3 (getpoint p2 "\nPick end of elbow <return to exit>: "))
       (if (null p3)
  (setq pickp3 0)
  (if (or (= (angle p2 p3) 0) (= (angle p2 p3) pi))
     (progn
(setq pickp3 0)
(setq p3 (list (car p3) (car (cdr p3)) 0))

; The short horizontal line has a minimum length of the text
; height.

(if (< (distance p2 p3) (* ds 0.09375))
   (progn
      (setq ang2 (angle p2 p3))
      (setq p3 (polar p2 ang2 (* ds 0.09375)))
   )
        )
        (command "layer" "m" "G-ANNO-TEXT" "")
        (command "line" p2 p3 "")
        (setq line2 (entlast))
        (setvar "clayer" cl)
     )
     (princ "\nThe elbow must be horizontal.")
  )
       )
    )
)

; While the user continues to pick an illegitimate entity, keep
; asking the user to pick a line to stretch the ellipse to.
; Otherwise, exit the "while" statement.

(setq pickline 1)
(while (= pickline 1)
    (progn
       (setq ent (entsel "\nPick a line to stretch ellipse to <return to exit>: "))
       (if ent
  (progn

; If the entity is a line, find its endpoints and the
; intersection point of the line and the leader line, which
; is the second center point.

     (if (= (cdr (assoc 0 (entget (car ent)))) "LINE")
(progn
   (setq entpt1 (cdr (assoc 10 (entget (car ent)))))
   (setq entpt1 (list (car entpt1) (car (cdr entpt1)) 0))
   (setq entpt2 (cdr (assoc 11 (entget (car ent)))))
   (setq entpt2 (list (car entpt2) (car (cdr entpt2)) 0))
   (setq c2 (inters c1 p2 entpt1 entpt2 [off]))
)
     )

; If the entity selected is the elbow, set the variable
; "line2pick" to 1.

     (setq line2pick 0)
     (if line2
(if (eq (car ent) line2)
   (setq line2pick 1)
)
     )

; Start the "cond" statement for selecting the case.

     (cond

; If the entity is the ellipse, tell the user.

((eq (car ent) el1)
   (princ "\nYou have selected the ellipse by mistake.")
)

; If the entity is not a line, tell the user what it is.

((/= (cdr (assoc 0 (entget (car ent)))) "LINE")
   (progn
      (setq name (cdr (assoc 0 (entget (car ent)))))
      (setq name (strcase name ""))
      (if (= name "insert")
(setq name "block")
      )
      (setq ltr (substr name 1 1))
      (if (or (= ltr "a") (= ltr "e") (= ltr "i") (= ltr "o") (= ltr "u"))
(setq line "The entity you have selected is an ")
(setq line "The entity you have selected is a ")
      )
      (princ (strcat "\n" line name ", not a line."))
   )
)

; If the line is the elbow, tell the user.

((= line2pick 1)
   (princ "\nYou have selected the elbow by mistake.")
)

; If the line is the leader line, tell the user.

((eq (car ent) line1)
   (princ "\nYou have selected the leader line by mistake.")
)

; If the first and second center points coincide, tell
; the user.

((equal c1 c2 0.00000001)
   (princ "\nYou have selected this line by mistake.")
)

; The first case for stretching the ellipse.

((and (< (distance p2 c2) (distance p2 c1))
      (< (distance c1 c2) (distance c1 p2))
      (>= (distance c2 p2) (* ds (/ 13 96.0))))
   (progn
      (entdel el1)
      (entdel line1)
      (command "elevation" 0)
      (command "layer" "m" "G-ANNO-TEXT" "")
      (command "pellipse" 1)
      (command "ellipse" break2 break1 end1)
      (command "break" (entlast) break1 break2)
      (setq el1 (entlast))
      (setq break3 (polar c2 (- ang1 (/ pi 2)) (/ ds 48.0)))
      (setq break4 (polar c2 (+ ang1 (/ pi 2)) (/ ds 48.0)))
      (setq end2 (polar c2 ang1 (/ ds 24.0)))
      (command "ellipse" break4 break3 end2)
      (setvar "pellipse" pell)
      (command "break" (entlast) break3 break4)
      (setq el2 (entlast))
      (command "line" break1 break4 "")
      (setq line3 (entlast))
      (command "line" break2 break3 "")
      (setq line4 (entlast))
      (command "line" end2 p2 "")
      (setvar "clayer" cl)
      (setvar "elevation" elev)
      (command "pedit" el1 "j" el2 line3 line4 "" "")
      (setq pickline 0)
   )
        )

; The second case for stretching the ellipse.

((and (< (distance p2 c1) (distance p2 c2))
      (< (distance c2 c1) (distance c2 p2)))
   (progn
      (command "elevation" 0)
      (command "break" el1 break1 break2)
      (setq el1 (entlast))
      (setq break3 (polar c2 (- ang1 (/ pi 2)) (/ ds 48.0)))
      (setq break4 (polar c2 (+ ang1 (/ pi 2)) (/ ds 48.0)))
      (command "layer" "m" "G-ANNO-TEXT" "")
      (command "pellipse" 1)
      (command "ellipse" break3 break4 (/ ds 24.0))
      (setvar "pellipse" pell)
      (command "break" (entlast) break3 break4)
      (setq el2 (entlast))
      (command "line" break1 break4 "")
      (setq line3 (entlast))
      (command "line" break2 break3 "")
      (setq line4 (entlast))
      (setvar "clayer" cl)
      (setvar "elevation" elev)
      (command "pedit" el1 "j" el2 line3 line4 "" "")
      (setq pickline 0)
   )
)

; The third case for stretching the ellipse.

(T
   (progn
      (command "elevation" 0)
      (setq vert (polar p2 (/ pi 2) 1))
      (setq horz (polar p2 0 1))
      (setq intvert (inters p2 vert entpt1 entpt2 [off]))
      (setq inthorz (inters p2 horz entpt1 entpt2 [off]))
      (if inthorz
(if (> (car p2) (car c1))
    (setq p2horz (polar inthorz 0 (* ds (/ 13 96.0))))
    (setq p2horz (polar inthorz pi (* ds (/ 13 96.0))))
)
      )
      (if intvert
(if (> (car (cdr p2)) (car (cdr c1)))
    (setq p2vert (polar intvert (/ pi 2) (* ds (/ 13 96.0))))
    (setq p2vert (polar intvert (* pi 1.5) (* ds (/ 13 96.0))))
)
      )
      (cond
((and inthorz intvert)
    (if (< (distance p2 inthorz) (distance p2 intvert))
       (setq p2new p2horz)
       (setq p2new p2vert)
    )
)
(inthorz
    (setq p2new p2horz)
)
(T
    (setq p2new p2vert)
)
      )
      (setq c2 (inters c1 p2new entpt1 entpt2 [off]))
      (setq ang1 (angle c1 c2))
      (setq break1 (polar c1 (+ ang1 (/ pi 2)) (/ ds 48.0)))
      (setq break2 (polar c1 (- ang1 (/ pi 2)) (/ ds 48.0)))
      (entdel el1)
      (entdel line1)
      (command "layer" "m" "G-ANNO-TEXT" "")
      (command "pellipse" 1)
      (command "ellipse" break2 break1 (/ ds 24.0))
      (command "break" (entlast) break1 break2)
      (setq el1 (entlast))
      (setq break3 (polar c2 (- ang1 (/ pi 2.0)) (/ ds 48.0)))
      (setq break4 (polar c2 (+ ang1 (/ pi 2.0)) (/ ds 48.0)))
      (setq end2 (polar c2 ang1 (/ ds 24.0)))
      (command "ellipse" break4 break3 end2)
      (setvar "pellipse" pell)
      (command "break" (entlast) break3 break4)
      (setq el2 (entlast))
      (command "line" break1 break4 "")
      (setq line3 (entlast))
      (command "line" break2 break3 "")
      (setq line4 (entlast))
      (command "line" end2 p2new "")
      (setvar "clayer" cl)
      (command "pedit" el1 "j" el2 line3 line4 "" "")
      (if p3
(progn
    (entdel line2)
    (setq ang2 (angle p2 p3))
    (setq p3new (polar p2new ang2 (* ds 0.09375)))
    (if (and (< (distance p2new p3new) (distance p2new p3))
     (< (distance p3 p3new) (distance p3 p2new)))
       (setq p3new (polar p2new ang2 (abs (- (car p3) (car p2new)))))
    )
    (command "layer" "m" "G-ANNO-TEXT" "")
    (command "line" p2new p3new "")
    (setvar "clayer" cl)
)
      )
      (setvar "elevation" elev)
      (setq pickline 0)
   )
)
     )
  )
  (setq pickline 0)
       )
    )
)
      )
   )
)
     )

; Set back system variables and end the program.

     
     ;(setvar "orthomode" ortho)     
     (command "cmdecho" cmd)
     (command "orthomode" ortho)
; added today 11/19/07     
     (command "osmode" usersnaps) ; -----------------------Return User Osmode Settings
(command "autosnap" userauto) ; -----------------------Return User Polar Mode Settings
(command "clayer" userlayer) ; -----------------------Return User Layer Settings
;(command "polarang" userpol) ; -----------------------Return User Polar Angle Settings
(princ "\n Ellipse Leader Osnaps & Layer Returned.--end run--")
(princ)
     (command "undo" "end")
)

KewlToyZ

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #6 on: August 14, 2009, 03:05:06 PM »
Notice pic below

James Cannon

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #7 on: August 14, 2009, 03:09:25 PM »
Oh ok, I was trying to read through your code and see why an ellipse doesn't work, now I see; it's the style of your loops, they're more like full-rounded rectangles, sometimes.

Btw, I very much like reading through your code.  It's thoroughly documented, and the way you are organized and writing things out, it is very easy for a total novice like me to follow along and see what's going on, and how.

That's still some crazy behavior in the stretch command.  I'm actually pretty surprised I  -haven't- run into this yet.  I am addicted to closed polylines for my drawings, because they just make so many things so much easier.  It's vastly more efficient to do material quantities for site plans with closed polylines comprising all areas of construction.  Also makes hatching almost crash-proof, being able to -always- use "select object" rather than "pick point".

I will keep this thread in mind, should I ever run in to it, thanks for sharing your solution.

KewlToyZ

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #8 on: August 14, 2009, 03:23:10 PM »
Thanks James, but Grant did most of this documentation, I wish I was more on top of illustrating the code I use at times.
I try to keep some clarity in items for the sake of sanity when trying to figure out items or debugging.
The crew in The Swamp have been really great examples with their guidance as well.

James Cannon

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #9 on: August 14, 2009, 03:32:32 PM »
I bet it really helps, too, in larger environments when someone else may need to work on your code ;)

KewlToyZ

  • Guest
Re: AutoCAD 2010 quick fix reminder for polyline issues
« Reply #10 on: August 17, 2009, 04:53:27 PM »
Oh yeah, not to mention if I should someday move on the next guy has a ray of hope in debugging  :lol: