Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pline Direction Left to Right Lisp

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
gurselgunacar
2315 Views, 18 Replies

Pline Direction Left to Right Lisp

Hello,

 

i work with text inserted plines in autocad. For example ----------B1--------------B1----------- But sometimes i draw plines right to left. So i have to mirror it again. I googled it and there are a lot of lisp about it. But they are not the one which i am searching. Is there any way to flip plines if they mirrored. And is there any way to do it in multiple selection?

 

Thanks for helping

https://www.bilgitara.com
18 REPLIES 18
Message 2 of 19
3wood
in reply to: gurselgunacar

In AutoCAD 2014 (may be start from earlier version), this function has been incoporated in PEDIT command.

Command: _pedit
Enter an option [Close/Join/Width/Edit vertex/Fit/Spline/Decurve/Ltype gen/Reverse/Undo]: _reverse

You can also select this command from right-click pop up menu.

Reverse.png

Message 3 of 19

3wood thx for your reply. but i need a lisp about reverse automaticly. Change the direction of all plines to left to right. So the texts in polylines will be mirrored. I used that lisp couple of years ago. But i couldnt find it now :S

https://www.bilgitara.com
Message 4 of 19
hmsilva
in reply to: gurselgunacar

Try this one by Kent Cooper

 

HTH

Henrique

EESignature

Message 5 of 19
Lee_Mac
in reply to: gurselgunacar

Why not simply:

 

(defun c:rpl ( / s )
    (if (setq s (ssget "_:L" '((0 . "LWPOLYLINE"))))
        (vl-cmdf "_.pedit" "_M" s "" "_R" "")
    )
    (princ)
)

 

Message 6 of 19
gurselgunacar
in reply to: hmsilva

thx hmsilva. i found it before. but i am looking for differnt version of it. if pline drew right to left then rotate it. if not dont do anything

https://www.bilgitara.com
Message 7 of 19
Lee_Mac
in reply to: gurselgunacar

I'm not sure how you wish to handle more complicated polyline shapes in which the polyline turns back on itself, but the following simple code will reverse polylines in a selection for which the first segment is drawn right-to-left:

 

(defun c:rpl ( / e i s )
    (if (setq s (ssget "_:L" '((0 . "LWPOLYLINE"))))
        (progn
            (repeat (setq i (sslength s))
                (setq e (ssname s (setq i (1- i))))
                (if (< 0 (cos (angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getstartparam e)) 0 e))))
                    (ssdel e s)
                )
            )
            (if (< 0 (sslength s))
                (vl-cmdf "_.pedit" "_m" s "" "_r" "")
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 8 of 19
gurselgunacar
in reply to: Lee_Mac

Perfect. That works fine 🙂 but sometimes it doesnt select lines. Why?

https://www.bilgitara.com
Message 9 of 19
Lee_Mac
in reply to: gurselgunacar


@gurselgunacar wrote:

Perfect. That works fine 🙂 but sometimes it doesnt select lines. Why?


Excellent Smiley Happy

 

Since the program uses the PEDIT command, the code is restricted to LWPOLYLINEs only, i.e. standard polylines created with the PLINE command.

 

Is the REVERSE command available in your version?

Message 10 of 19
gurselgunacar
in reply to: Lee_Mac

yes avaible. but it doesnt do same thing

https://www.bilgitara.com
Message 11 of 19

lee mac

this lisp doesnt work for lines. Can we include them to lisp? 

 

Thx again

https://www.bilgitara.com
Message 12 of 19
Lee_Mac
in reply to: gurselgunacar

Maybe try something like this:

 

(defun c:rpl ( / e i s )
    (if
        (setq s
            (ssget "_:L"
               '(
                     (00 . "LINE,SPLINE,*POLYLINE")
                     (-4 . "<NOT")
                        (-4 . "<AND")
                            (00 . "POLYLINE")
                            (-4 . "&")
                            (70 . 80)
                        (-4 . "AND>")
                     (-4 . "NOT>")
                )
            )
        )
        (progn
            (repeat (setq i (sslength s))
                (setq e (ssname s (setq i (1- i))))
                (if (< 0 (cos (angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getstartparam e)) 0 e))))
                    (ssdel e s)
                )
            )
            (if (< 0 (sslength s))
                (vl-cmdf "_.reverse" s "")
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

The above uses the REVERSE command for convenience - if this command is not available we could also go the long way around and modify the DXF data for each individual entity as required.

 

Lee

Message 13 of 19
gurselgunacar
in reply to: Lee_Mac

thx that works 🙂

https://www.bilgitara.com
Message 14 of 19
Lee_Mac
in reply to: gurselgunacar

Excellent - you're welcome! Smiley Happy

Message 15 of 19
gurselgunacar
in reply to: Lee_Mac

Hello Lee Mac, 

 

I am using your lisp and it is helpful. Thx

 

Is there anyway to rotate line like in the picture in this lisp. It rotate horizantal lines very well but not same for vertical lines.

rotate.JPG

https://www.bilgitara.com
Message 16 of 19
Kent1Cooper
in reply to: gurselgunacar


@gurselgunacar wrote:

... It rotate horizantal lines very well but not same for vertical lines.


That's because the cosine of 270 is 0, just like the cosine of 90 degrees.  You want it to reverse things running at 270, but not 90.  That is, you want to remove from the set of things to be reversed not just things with negative cosines, but also things at 90 degrees [whose cosine is 0].  Try changing this part:

 

....

                (setq e (ssname s (setq i (1- i))))
                (if (< 0 (cos (angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getstartparam e)) 0 e))))
                    (ssdel e s)
                )

....

 

to this [there are other ways to do it, too]:

 

....

                (setq

                  e (ssname s (setq i (1- i)))

                  ang (angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getstartparam e)) 0 e))

                ); setq
                (if (or (<= ang (/ pi 2)) (> ang (* pi 1.5))); up to and including 90, or more than [but not equal to] 270
                  (ssdel e s); take it out [i.e. don't reverse it]
                )

....

Kent Cooper, AIA
Message 17 of 19
dbroad
in reply to: gurselgunacar

You don't need LISP programs to reverse your plines if you design the linetype correctly.  Use the U rotation parameter instead of the A or R rotation parameter.  Then it doesn't matter what the rotation of the pline is or which way it goes.

 

Example:

*B1,---B1---
A,0.25,-0.125,["B1",STANDARD,S=.1,U=0.0,X=-0.05,Y=-0.05],-.25

Architect, Registered NC, VA, SC, & GA.
Message 18 of 19
gurselgunacar
in reply to: Kent1Cooper

Thx for your answers. This lisp works fine but i think some vertical lines in my drawing is tilt. it is nearly 90 degree. And it doesnt reverse this lines. You can see example drawing in attachment.

https://www.bilgitara.com
Message 19 of 19
Kent1Cooper
in reply to: gurselgunacar


@gurselgunacar wrote:

Thx for your answers. This lisp works fine but i think some vertical lines in my drawing is tilt. it is nearly 90 degree. And it doesnt reverse this lines. You can see example drawing in attachment.


Yes, the one that didn't reverse is not quite vertical, but it's not until the 11th decimal place in the X coordinates that you can tell.  With EDATA being a variable containing its entity data, a comparison of the X coordinates of the endpoints reveals:

 

Command: (RTOS (- (CADR (ASSOC 10 EDATA)) (CADR (ASSOC 11 EDATA))) 2 16)
"-0.0000000000145519"

 

And comparing its angle to 270 degrees [but in radians]:

 

Command: (rtos (- (angle (cdr (assoc 10 edata)) (cdr (assoc 11 edata))) (* pi 1.5)) 2 16)
"0.0000000000000044"

 

It's greater than [by the tiniest margin] but not quite equal to 270 degrees, so it gets removed from the set of things to be reversed.

 

Replacing the same stretch as before with the following catches that one [in limited testing]:

....

                (setq
                  e (ssname s (setq i (1- i)))
                  ang (angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getstartparam e)) 0 e))
                ); setq
                (if
                  (and
                    (or (<= ang (/ pi 2)) (> ang (* pi 1.5))); up to and including 90, or more than [but not equal to] 270
                    (not (equal ang (* pi 1.5) 0.001)); returns nil if close to 270, so it won't be removed from set
                  ); and
                  (ssdel e s); then -- take it out [i.e. don't reverse it]
                ); if

....

 

Change the fuzz factor of 0.001 to whatever kind of tolerance you need.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost