Reverse Polyline Then Re-Select it

Reverse Polyline Then Re-Select it

ebsoares
Collaborator Collaborator
1,061 Views
8 Replies
Message 1 of 9

Reverse Polyline Then Re-Select it

ebsoares
Collaborator
Collaborator

Hi, all.

 

I'm a big fan but still quite a newbie when it comes to lisp routines.

I'd like to select an element (say a polyline), then call a lisp routine that would call the command "Reverse" to reverse the direction of that element, then re-select the element it just reversed (it annoys me that after I call the "Reverse"command it just deselects it afterwards).

 

Here's what I have so far:

(defun c:RV ()
  (command "Reverse")
  (command "PSelect" "P" "")
)

If i just call "Reverse" in ACAD with the element selected, it just does its job then ends the command, no questions asked. However, when running this lisp it still asks to select an element, even though one is already selected.

 

This is what I get:

RV Reverse
Select line, polyline, spline or helix to reverse direction:
Select objects: PSelect
*Invalid selection*
Expects a point or yada, yada, yada...
; error: Function cancelled
Select objects:

I just want to keep that element selected so I can work with the selection grips right after...

 

Can anyone help me here? If it's not too much trouble, also explain why it did not work in the first place?

 

Much appreciated,

 

Edgar

0 Likes
Accepted solutions (2)
1,062 Views
8 Replies
Replies (8)
Message 2 of 9

Jonathan3891
Advisor
Advisor

Give this a try:

 

(defun c:test (/ ss)
(if (not (setq ss (ssget)))
(command "reverse" ss "")
(sssetfirst nil ss)
)
)

 


Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 9

jdiala
Advocate
Advocate
Accepted solution

I'd like to select an element  ...


(defun c:TEST (/ ss)
(if (setq ss (ssget "_+.:E:S"))
  (progn
    (command ".reverse" (ssname ss 0) "")
    (sssetfirst nil ss)
  )
)
(princ)
)
Message 4 of 9

ebsoares
Collaborator
Collaborator
Thanks for the reply, DMS. Unfortunately it did not work on my end.

To test, I drew a polyline, selected it, ran the lisp, and the polyline direction did not change... and it didn't stay selected with the selection grips and everything either (for that I think we need "PSelect")

Does it work on your end if you go through the test I did above?
0 Likes
Message 5 of 9

Jonathan3891
Advisor
Advisor
I tested it and it wouldnt reverse the line.

jdiala posted the correct code.

Jonathan Norton
Blog | Linkedin
0 Likes
Message 6 of 9

ebsoares
Collaborator
Collaborator
Thanks for trying, DMS!
0 Likes
Message 7 of 9

ebsoares
Collaborator
Collaborator
Super awesome, jdiala! It works!
Thank a lot!
Edgar
0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@ebsoares wrote:

....

I'd like to select an element (say a polyline), then call a lisp routine that would call the command "Reverse" to reverse the direction of that element, then re-select the element it just reversed ....


Here's a version that:

 

A) works with a pre-selection if there is one, or if not, asks the User to select;

 

B) works with multiple objects at once:

 

C) prevents selection [pre- or otherwise] of reversible objects on locked Layers.

 

;;  ReverseRemainSelected.lsp [command name: RRS]
;;  Applies Reverse command to pre-existing or new selection of reversible
;;    entities, and leaves them selected/gripped/highlighted
;;  Kent Cooper, 9 October 2015

(defun C:RRS (/ rrss); = Reverse and Remain Selected
  (setq filter '((0 . "LINE,*POLYLINE,SPLINE,HELIX"))); reversible entity types
  (if
    (or
      (setq rrs-ss (ssget "_:L-I" filter)); pre-selection of valid entities
      (setq rrs-ss (ssget "_:L" filter)); if not, get some
    ); or
    (progn ; then
      (command ".reverse" rrs-ss "")
      (sssetfirst nil rrs-ss); select-grip-highlight
    ); progn
  ); if
  (princ)
); defun
Kent Cooper, AIA
Message 9 of 9

ebsoares
Collaborator
Collaborator

Fantastic, Kent! It works better than I expected, even when there are multiple elements selected!

 

Big kudos for you and jdiala. You guys rock.

 

Edgar

0 Likes