Move object using osnaps while retaining original z value

Move object using osnaps while retaining original z value

dlbsurveysuk
Collaborator Collaborator
459 Views
8 Replies
Message 1 of 9

Move object using osnaps while retaining original z value

dlbsurveysuk
Collaborator
Collaborator

Hi, I've cobbled together the following routine.

 

(defun c:MXY (/ ss bp)

         (defun *error* (MSG)

            (if (/= MSG "Function cancelled")
                (princ (strcat "\nError: " MSG)))

              (if osm (setvar "OSMODE" OSM))
              (if lyr (setvar "CLAYER" LYR))

          (princ) )

   (setq OSM   (getvar "OSMODE"))
   (setq LYR   (getvar "CLAYER"))

   (command "OSNAP" "INS,NEA")

  (if (and (setq ss (ssget "_:L"))
           (setq bp (getpoint "\nSpecify base point: "))
      )
    (command "_.move" ss "_non" "" bp ".Z" "_non" bp)
  )

  (setvar "OSMODE" OSM)
  (setvar "CLAYER" LYR)      

  (princ)
)

 

I was hoping would allow me to move an object by snapping to it's insert and then snapping to a nearest point on a line, while retaining the z value of it's original position. Snap to insert works but then osnap seems to revert to OSM before I try to snap to nearest. I don't really fully understand all the syntax of - 

(command "_.move" ss "_non" "" bp ".Z" "_non" bp)

which I copied from another forum post.

 

Any help appreciated.

Thanks.

 

0 Likes
460 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

How about just set OSNAPZ to 1?

 

 

 

(defun c:test ( / os zz)
  
  (setq oz (getvar 'osnapz))
  (setvar 'osnapz 1)
  
  (if (setq ss (ssget "_:L"))
    (command "_.move" ss "" "_ins" pause "_nea" pause))
  
  (setvar 'osnapz oz)
  (princ)
  )

 

0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant

@dlbsurveysuk wrote:

.... Snap to insert works but then osnap seems to revert to OSM before I try to snap to nearest. .... 

(command "_.move" ss "_non" "" bp ".Z" "_non" bp)

....


That leaves you still in the Move command awaiting the pick, and resets OSMODE before you can pick. So include a pause for the pick to happen before the OSMODE reset:

 

(command "_.move" ss "_non" "" bp ".Z" "_non" bp pause)

 

I would also suggest not including "NEA" in the Osnap setting where you do -- it could mean you don't get the "INS" point you're after, because almost always something on the object will be NEArer to the cursor location than the INSertion point is.  Try setting it to "INS" only for the first pick, then to "NEA" for the second one.

Kent Cooper, AIA
0 Likes
Message 4 of 9

dlbsurveysuk
Collaborator
Collaborator
Thanks for the reply. Your routine seems to snap to the z value of the line I'm snapping to.
0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant

Sorry, sure. Osnapz should be 1.

0 Likes
Message 6 of 9

dlbsurveysuk
Collaborator
Collaborator
Thanks a lot. That works fine now.

Good point re the Osnap settings. I've tried making the first one just INS and inserting a NEA in various places but can't get **** to work....
0 Likes
Message 7 of 9

dlbsurveysuk
Collaborator
Collaborator
OK. That works perfectly now. Thanks a lot.
0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

@dlbsurveysuk wrote:
.... I've tried making the first one just INS and inserting a NEA in various places but can't get **** to work....

Have you tried this way?

(command "_.move" ss "_non" "" bp ".Z" "_non" bp "_nea" pause)
Kent Cooper, AIA
0 Likes
Message 9 of 9

dlbsurveysuk
Collaborator
Collaborator
OK. No I hadn't tried that. It's because my Lisp knowledge is very basic and I'm not aware of all the different options that can be in a command line and how they are formatted. Works now. Thanks very much.
0 Likes