Author Topic: Reverse Move  (Read 2028 times)

0 Members and 1 Guest are viewing this topic.

novice

  • Guest
Reverse Move
« on: September 15, 2015, 10:24:53 AM »
Hi all. I've been making many pretty simple Lisp routines for years. I was fully into it maybe 20 years ago, and have since forgotten a lot. I still make new Lisp routines, but I kind of hobble along. I wonder if anyone could help me with this one:

Code - Auto/Visual Lisp: [Select]
  1. ;;Move in Reverse order (pick second point; then, pick origin point)
  2.  
  3. (defun C:rmove ()
  4.   (command "undo" "begin")
  5.   (setq pt2 (getpoint "\nSelect the point to move TO:"))
  6.   (setq pt1 (getpoint "\nSelect the point to move FROM:"))
  7.   (setq ss1 (ssget))
  8.   (command "move" ss1 "" pt1 pt2)
  9.   (command "undo" "end")
  10.   (prompt "...done.")(princ))

The problem I'm having is I can't pick a point for pt1 which is perpendicular (say, to a line) to the point I already picked for pt2.

Makes sense?

Thanks,
Novice


EDIT: Added code tags.
« Last Edit: September 15, 2015, 11:13:58 AM by John Kaul (Se7en) »

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Reverse Move
« Reply #1 on: September 15, 2015, 10:34:40 AM »
This?
Code: [Select]
(setq pt2 (getpoint "\nSelect the point to move TO:"))
  (setq pt1 (getpoint pt2 "\nSelect the point to move FROM:"))

novice

  • Guest
Re: Reverse Move
« Reply #2 on: September 15, 2015, 10:40:17 AM »
This?
Code: [Select]
(setq pt2 (getpoint "\nSelect the point to move TO:"))
  (setq pt1 (getpoint pt2 "\nSelect the point to move FROM:"))

I'm not sure I understand what you're asking. I assume the simplistic way I've written the function means that pt1 & pt2 are being defined in isolation from each other, so there is no perpendicular snap option available.

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Reverse Move
« Reply #3 on: September 15, 2015, 10:55:20 AM »
Did you try to modify the code as i suggested?
Adding pt2 here:
  (setq pt1 (getpoint pt2 "\nSelect the point to move FROM:"))
will give you your perpendicular snap option.

novice

  • Guest
Re: Reverse Move
« Reply #4 on: September 15, 2015, 10:58:32 AM »
Did you try to modify the code as i suggested?
Adding pt2 here:
  (setq pt1 (getpoint pt2 "\nSelect the point to move FROM:"))
will give you your perpendicular snap option.

I apologize, I didn't see that you changed my code the first time. Thank you! Works perfect.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Reverse Move
« Reply #5 on: September 16, 2015, 03:43:46 AM »
I am surprised that jvillarreal's suggestion solves the problem. It would mean that the (getpoint) function does not change the LASTPOINT variable by default. In BricsCAD (getpoint) always updates LASTPOINT:
Code: [Select]
: (getvar 'lastpoint)
(0.0 0.0 0.0)
: (getpoint)
(2664.84 1200.31 0.0)
: (getvar 'lastpoint)
(2664.84 1200.31 0.0)

Other issues with the code:
1. Localize variables.
2. Handle osmode: (command "move" ss1 "" "_non" pt1 "_non" pt2)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Reverse Move
« Reply #6 on: September 16, 2015, 03:49:17 AM »
Here are some suggestions for your code:

Code - Auto/Visual Lisp: [Select]
  1. ;; Move in Reverse order (pick second point; then, pick origin point)
  2. (defun c:rmove ( / pt1 pt2 ss1 )
  3.     ;; Define function and declare local variables
  4.     (if ;; If the following expression returns a non-nil value
  5.         (and
  6.         ;; All of the following expressions must return a non-nil value for AND to return T
  7.         ;; AND will cease evaluating expressions if an expression returns nil
  8.             (setq pt2 (getpoint "\nSpecify the point to move TO: "))
  9.             ;; Prompt the user for a point and assign the result to the symbol 'pt2'
  10.             (setq pt1 (getpoint "\nSpecify the point to move FROM: " pt2))
  11.             ;; Prompt the user for a point with a rubber-band to 'pt2' and assign the result to the symbol 'pt1'
  12.             (setq ss1 (ssget "_:L"))
  13.             ;; Prompt the user for a selection of objects on unlocked layers
  14.         ) ;; end AND
  15.         ;; The following is the THEN argument for the IF function:
  16.         (command ;; Issue the following arguments to the command-line
  17.             "_.undo" "_begin" ;; Open an undo group
  18.             "_.move" ss1 "" "_non" pt1 "_non" pt2 ;; Invoke the MOVE command, ignoring Object Snaps
  19.             "_.undo" "_end" ;; Close the undo group
  20.         ) ;; end COMMAND
  21.         ;; Here would be the ELSE argument for the IF function
  22.     ) ;; end IF
  23.     (princ) ;; Suppress the return of the last evaluated expression
  24. ) ;; end DEFUN

novice

  • Guest
Re: Reverse Move
« Reply #7 on: September 16, 2015, 09:33:13 AM »
Thanks everyone for your input. I actually found this forum because of Lee - Lee, I've downloaded some of your Lisp routines from your website. I added your suggestions on this one.

I do feel like I'm in a bit over my head on this forum, and wonder if I can have any role here other than asking for help. Maybe the only thing I can really offer is a few good ideas for Lisp routines. My own code is always very simplistic, without error control, etc. But I think I've created some nice little functions and if I ask for help to make them better and get some help maybe everyone wins?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Reverse Move
« Reply #8 on: September 16, 2015, 03:57:04 PM »
Thanks everyone for your input. I actually found this forum because of Lee - Lee, I've downloaded some of your Lisp routines from your website. I added your suggestions on this one.

You're most welcome! I'm glad that you found my programs useful and I'm pleased to have introduced you to this oustanding community :-)

I do feel like I'm in a bit over my head on this forum, and wonder if I can have any role here other than asking for help. Maybe the only thing I can really offer is a few good ideas for Lisp routines. My own code is always very simplistic, without error control, etc. But I think I've created some nice little functions and if I ask for help to make them better and get some help maybe everyone wins?

Don't worry about it - we've all been there! Nobody starts off as being an expert in any particular field - we all stand on the shoulders of the giants before us who were kind enough to share their knowledge on forums such as this.