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
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Solved by Lee_Mac. Go to Solution.
Solved by Lee_Mac. Go to Solution.
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.
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
Why not simply:
(defun c:rpl ( / s ) (if (setq s (ssget "_:L" '((0 . "LWPOLYLINE")))) (vl-cmdf "_.pedit" "_M" s "" "_R" "") ) (princ) )
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
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)
Perfect. That works fine 🙂 but sometimes it doesnt select lines. Why?
@gurselgunacar wrote:Perfect. That works fine 🙂 but sometimes it doesnt select lines. Why?
Excellent
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?
lee mac
this lisp doesnt work for lines. Can we include them to lisp?
Thx again
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
Excellent - you're welcome!
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.
@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]
)
....
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
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.
@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.