Can I change the direction of a custom linetype?

Discussion in 'AutoCAD' started by Ervin Battle, Apr 12, 2004.

  1. Ervin Battle

    Ervin Battle Guest

    Hi all,

    I've created a custom linetype that includes text and shows conduit runs
    through
    city streets. my problem is when i assign the linetype to the plines
    sometime the text doesn't come out the way i want it to because if the
    direction it was drawn in. is there a routine that will change the direction
    the plines are drawn in or do i have to redraw the lines? i have a routine
    that will would on lines but not plines.

    thanks,
    ervin
     
    Ervin Battle, Apr 12, 2004
    #1
  2. Ervin Battle

    Larry Travis Guest

    Sorry, I am in the same boat as you. One way you can manually reverse the
    direction is to add a short temporary line segment to one of the ends of
    the polyline. Make sure that the new line has the same linetype as the
    pline and that its direction is what you want. Then pedit this segment to
    turn it into a pline and join it to the existing pline. That will reverse
    the direction of the vertices of the original pline and you can then trim
    off the original extra segment. I would assume it would be easy to create a
    lisp routine to automate that.

    LT
     
    Larry Travis, Apr 13, 2004
    #2
  3. This is a program I wrote several years ago that might work for you. I
    deletes the existing lwpolyline or line and create a new line in the
    opposite direction. The "yellow" arrow shows the direction of the line.

    ;RP = reverse direction of LWPOLYLINE or LINE (converted to LWPOLYLINE)
    (defun C:RP (/ ES PD1 PD2 PD3 PD4 EG LH LP NLP KKF KK KL KF1 KF2 EE E1 E2 E3
    E4 AA AD TT)
    (setq ES (entsel "\nPick Polyline/Line to Reverse ? "))
    (while ES
    (if (and PD1 PD2 PD3)
    (progn
    (grdraw PD1 PD2 0)
    (grdraw PD2 PD3 0)
    (grdraw PD2 PD4 0)
    )
    )
    (setq EG (entget (car ES)))
    ;---
    (setq LH nil LP nil NLP nil)
    (if (member (cdr (assoc 0 EG)) (list "LWPOLYLINE" "LINE"))
    (progn
    ;--change line to LWPOLYLINE
    (if (= (cdr (assoc 0 EG)) "LINE")
    (progn
    (command "PEDIT" (cdr (assoc -1 EG)) "Y" "X")
    (setq EG (entget (entlast)))
    )
    )
    ;--get header data
    (setq EP (member (assoc 10 EG) EG))
    (setq KKF (- (length EG) (length (member (assoc 10 EG) EG))))
    (setq KK 0 KL KKF)
    (while (< KK KL)
    (setq EE (nth KK EG))
    (setq LH (append LH (list EE)))
    (setq KK (1+ KK))
    )
    ;--get vertex data
    (setq KK KKF KL (length EG))
    (while (< KK KL)
    (setq E1 (nth KK EG))
    (if (= (car E1) 10)
    (progn
    (setq E2 (nth (+ KK 1) EG))
    (setq E3 (nth (+ KK 2) EG))
    (setq E4 (nth (+ KK 3) EG))
    (if (/= 0.0 (cdr E4))
    (setq E4 (cons 42 (- (cdr E4))))
    )
    (if (= (car (nth (+ KK 4) EG)) 210)
    (setq LP (append LP (list E1)))
    (setq LP (append LP (list E1) (list E4) (list E3) (list
    E2)))
    )
    )
    )
    (setq KK (+ KK 4))
    )
    (setq LP (append (list (last EG)) (list (cons 42 0.0)) (list (cons
    41 0.0)) (list (cons 40 0.0)) LP))
    )
    (alert (strcat "\nERROR - Entity selected is [" (cdr (assoc 0 EG)) "]
    and NOT a PLINE."))
    )
    (if LP
    (progn
    (entdel (cdr (assoc -1 EG)))
    (setq NLP (append LH (reverse LP)))
    (entmake NLP)
    (setq KK 0 KL (length EG))
    (setq KF1 nil KF2 nil)
    (while (< KK KL)
    (setq TT (nth KK EG))
    (cond
    ((and (not KF1) (= (car TT) 10)) (setq KF1 (cdr TT)))
    ((and KF1 (not KF2) (= (car TT) 10)) (setq KF2 (cdr TT) KK KL))
    )
    (setq KK (1+ KK))
    )
    (setq AA (angle KF1 KF2))
    (setq DD (/ (getvar "VIEWSIZE") 20.0))
    (setq PD1 KF1 PD2 (polar PD1 AA DD))
    (setq PD3 (polar PD2 (+ AA (* pi 0.75)) (* 0.5 DD)))
    (setq PD4 (polar PD2 (- AA (* pi 0.75)) (* 0.5 DD)))
    (grdraw PD1 PD2 2)
    (grdraw PD2 PD3 2)
    (grdraw PD2 PD4 2)
    (princ "\nNew Pline Direction Shown.")
    )
    )
    (setq ES (entsel "\nPick Polyline/Line to Reverse ? "))
    )
    (princ)
    )
     
    Alan Henderson, Apr 13, 2004
    #3
  4. Ervin Battle

    Friptzap Guest

    There is a built in command to reverse the direction of a polyline.

    Use the spline edit command and select e for reverse.

    If that is what you mean :)
     
    Friptzap, Apr 13, 2004
    #4
  5. Ervin Battle

    Ervin Battle Guest

    thanks all for your help...

    ervin
     
    Ervin Battle, Apr 13, 2004
    #5
  6. Works for Splines, but not for Plines, at least not in 2000 or 2004.

    Kent Cooper

    ...
     
    Kent Cooper, AIA, Apr 13, 2004
    #6
  7. Ervin Battle

    Friptzap Guest

    Ah. The objects I have been using are plines which have been made into curved lines with the pline edit - spline command. They still read as plines until you edit them with the spline edit command then they read as splines. Odd that is. :)
    I had not actually tested it on short straight plines but you are correct as I just tried now and found out it does not work with them.

    Maybe just a simple command that switches all the enpoints of the line you need to change then would work?
     
    Friptzap, Apr 13, 2004
    #7
  8. Ervin Battle

    CAB2k Guest

    Here is one you can try..

    Code:
    ;;;           Polyline Reverse
    ;;;      lwr.lsp by Charles Alan Butler
    ;;;            Copyright 2004
    ;;;  by Precision Drafting & Design All Rights Reserved.
    ;;;  Contact at 
    ;;;
    ;;;   Version Alpha  March 20,2004
    ;;;
    ;;;   Reverse the vertex order of a light weight polyline
    ;;;   Keeps the same starting point unlike most reverse routines
    ;;;
    ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
    ;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
    ;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
    ;;;                                                                    ;
    ;;;  You are hereby granted permission to use, copy and modify this    ;
    ;;;  software without charge, provided you do so exclusively for       ;
    ;;;  your own use or for use by others in your organization in the     ;
    ;;;  performance of their normal duties, and provided further that     ;
    ;;;  the above copyright notice appears in all copies and both that    ;
    ;;;  copyright notice and the limited warranty and restricted rights   ;
    ;;;  notice below appear in all supporting documentation.              ;
    ;;;
    (defun c:plr (/ elst vlst newlst new-vlst code42 code210
    obj nam pair )
    (command "_.undo" "_be")
    (while (null (setq en1 (entsel "\nPick an object to reverse: "))))
    (setq nam  (car en1) elst (entget nam) obj  (cdr (assoc 0 elst)))
    (cond
    ((= obj "LWPOLYLINE")
    (setq new-vlst (list (assoc 10 elst))) ; start point
    (while (setq pair (car elst))
    (cond
    ((= (car pair) 10) ; vertex
    (while (member (caar elst) '(10 40 41 42))
    (setq vlst (cons (car elst) vlst) elst (cdr elst))))
    ((= (car pair) 210) ; extru direction??
    (setq code210 pair elst (cdr elst)))
    ((setq newlst (cons pair newlst) elst (cdr elst)))))
    (while vlst
    (if (= (car (setq pair (car vlst))) 42) ; bulge
    (setq code42 (cons 42 (* (cdr pair) -1)) vlst (cdr vlst)))
    (if (= (car (setq pair (car vlst))) 41)
    (setq vlst     (cdr vlst)
    new-vlst (cons (cons 40 (cdr pair)) new-vlst)
    new-vlst (cons (cons 41 (cdr (car vlst))) new-vlst)
    vlst     (cdr vlst)))
    (if code42 ; add bulge back to list
    (setq new-vlst (cons code42 new-vlst) code42 nil))
    (if (= (car (setq pair (car vlst))) 10)
    (setq new-vlst (cons pair new-vlst) vlst (cdr vlst))))
    (setq new-vlst (cdr new-vlst)) ; remove the start pt
    (setq newlst (append new-vlst newlst))
    (if code210  (setq newlst (append (list code210) newlst)))
    (entmod (reverse newlst))
    (entupd nam) ; Regenerates the polyline entity
    )
    
    ((= obj "POLYLINE")
    (prompt "\nNot yet working... Old Style Polyline."))
    ((prompt "\nObject selected is not a polyline"))) ; end cond stmt
    (princ)
    ) ; end defun
     
    CAB2k, Apr 14, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.