Author Topic: Copy and Move Window Selection  (Read 3817 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Copy and Move Window Selection
« on: April 25, 2014, 10:09:17 AM »
I have an overall lisp of my commands. How can I create a move window selection; endpoint to endpoint? command would be mw and cw..
Thanks!

Code: [Select]
(defun c:ccc ()
(prompt "copy CENter to CENter")
(ssget)
(command "copy" "p" "" "quick,CENter" pause "quick,CENter" pause ""))
Civil3D 2020

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Copy and Move Window Selection
« Reply #1 on: April 25, 2014, 12:17:57 PM »
Take a look at the function (ssget) in your help docs. Here's a link to the function:
http://docs.autodesk.com/CIV3D/2013/ENU/index.html?url=filesACD/GUID-EC257AF7-72D4-4B38-99B6-9B09952A53AD.htm,topicNumber=ACDd30e644133

The problem with using (ssget) is that you cannot provide the window argument without first obtaining the window coordinates. You would be better to use the "SELECT" command. see my code below:

Some other suggestions:
1) always include a period "." before command names in case someone has redefined the command. The "." will always get the original AutoCAD command.
2) include an underscore "_" before the command and all command option arguments. This will prevent any problems with localization in different languages.

Code: [Select]
;; Command C:MW - Move Window ENDpoint to ENDpoint.
(defun c:mw ( / os *error*)

   (defun *error* (msg)
      (if (not (wcmatch (strcase msg T) "*break*,*cancel*,*quit*,*exit*"))
  (princ (strcat "\nError: " msg))
          (princ "\nProgram Aborted.")
      )
      (setvar 'osmode os)
   )

   (princ "\nMove Window ENDpoint to ENDpoint.")
   (command "._select" "_w") ;; Use "c" instead of "w" for a crossing window.
   (while (= (logand (getvar "cmdactive") 1) 1)
      (command pause)
   )
   (setq os (getvar "osmode"))
   (setvar "osmode" 1)
   (command "._move" "_p" "" pause pause)
   (setvar "osmode" os)
   (princ)
)

EDIT: NOTE - I changed the code to set the Object Snap to ENDpoint before the command, and restore after. This is to allow the Object snap markers during the move command. You will need to add error handling to restore the object snaps if the command is canceled.

EDIT 2: Added Error Handling nested *error* function.
« Last Edit: April 25, 2014, 04:12:54 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Copy and Move Window Selection
« Reply #2 on: April 25, 2014, 01:15:16 PM »
Note: Reply above edited.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Copy and Move Window Selection
« Reply #3 on: April 25, 2014, 02:49:29 PM »
Thank you!
Civil3D 2020

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Copy and Move Window Selection
« Reply #4 on: April 25, 2014, 04:06:44 PM »
Thank you!

No problem  :-)  Just make sure you add the error handling. I will edit my post above to include an error handler and you can see how it's done.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Copy and Move Window Selection
« Reply #5 on: April 26, 2014, 10:58:45 AM »
I would recommend using an object snap modifier over changing the OSMODE system variable - this way, there is no need for an error handler, e.g.:
Code: [Select]
(defun c:mw ( / sel )
    (if (setq sel (ssget "_:L"))
        (command "_.move" sel "" "_end" "\\" "_end" "\\")
    )
    (princ)
)

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Copy and Move Window Selection
« Reply #6 on: April 28, 2014, 07:32:31 AM »
Thanks for the info! Works great! Its amazing how tight you can condense code and it still works.
Civil3D 2020

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Copy and Move Window Selection
« Reply #7 on: April 28, 2014, 01:00:58 PM »
I would recommend using an object snap modifier over changing the OSMODE system variable - this way, there is no need for an error handler, e.g.:
Code: [Select]
(defun c:mw ( / sel )
    (if (setq sel (ssget "_:L"))
        (command "_.move" sel "" "_end" "\\" "_end" "\\")
    )
    (princ)
)

Hi Lee,

you code is very efficient save for 2 things:

1) The OP asked to automatically start selection in a window selection mode - hence the command name "MW". SSGET must be supplied the 2 points ahead of time for this.
2) At least on my machine - when supplying the object snap modifiers within a command function, then pausing for user input, the Autosnap markers fail to show up. That is why I opted for changing the OSMODE.

Note - no disrespect meant Lee - you are an incredible coder. Just stating the reason I did the code the way I did it. Strange the OP seems to be satisfied with your code hoewever. Perhaps I misinterpreted what he wants?

- Phil.
« Last Edit: April 28, 2014, 01:41:07 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Copy and Move Window Selection
« Reply #8 on: April 28, 2014, 06:26:05 PM »
1) The OP asked to automatically start selection in a window selection mode - hence the command name "MW". SSGET must be supplied the 2 points ahead of time for this.

Since the OP was using ssget to begin with, so I simply followed suit - note that the Window selection mode can still be activated by typing 'W' at the selection prompt.

2) At least on my machine - when supplying the object snap modifiers within a command function, then pausing for user input, the Autosnap markers fail to show up. That is why I opted for changing the OSMODE.

They seem to show up fine for me - I'd be interested to know if they fail to show up for others reading this thread?

Note - no disrespect meant Lee - you are an incredible coder. Just stating the reason I did the code the way I did it. Strange the OP seems to be satisfied with your code hoewever. Perhaps I misinterpreted what he wants?

None taken Phil - I respect your opinion, and I openly welcome critique of my code - I might learn something new!  :-)

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Copy and Move Window Selection
« Reply #9 on: April 29, 2014, 07:13:30 AM »
Guys,
Thank you again for your help! Both solutions work great! Great Job!
Civil3D 2020

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Copy and Move Window Selection
« Reply #10 on: April 29, 2014, 10:22:00 AM »
They seem to show up fine for me - I'd be interested to know if they fail to show up for others reading this thread?

Hmmm. I'll have to investigate this. I'm using AutoCAD Mechanical 2014 64bit. I'm going to check this out on another machine and see if I get the same behavoir, and also try it with vanilla AutoCAD.

EDIT: OK - the object snap modifiers seem to work fine in vanilla AutoCAD. They do not work however in AutoCAD Mechanical. Strange... I wonder if this behavior is just with my AutoCAD Mechanical and it's due to some program or function I have loaded? Or if its common behavior in AutoCAD Mechanical? Does anyone else here experience the same?

None taken Phil - I respect your opinion, and I openly welcome critique of my code - I might learn something new!  :-)

Thanks Lee!  :-)
« Last Edit: April 29, 2014, 10:31:35 AM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Copy and Move Window Selection
« Reply #11 on: April 29, 2014, 10:23:17 AM »
Guys,
Thank you again for your help! Both solutions work great! Great Job!

Your welcome MSTG007. I'm glad we were able to help out.  :-)
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt