Exchange Forum > AutoLISP and Visual LISP
Move & Rotate along Axis in 3D
Move & Rotate along Axis in 3D

#1

Laison
Join Date:
03-11-2009
Hello,
I am new to this forum. I have been searching for the answer to this question for some time now. I have this AutoLISP function that moves objects in 2D & 3D. I would like to enhance it. I want to add to the code where just selecting on the destination object, the source object will "Move & Rotate along its Axis" so that the two are aligned. Here are three things to consider about this function.
 
1. It has to work in 3D
2. The distance is unknown
3. The angle is unknown
 
I have seen some great 2D routines, but I cannot find any 3D routines that have this feature.
Any help would be greatly appreciated!
Laison
Code:
; MPF.lsp - Move Objects Along Axis
; Move objects with Point Filter in the X, Y or Z direction.
(defun c:MPF (/ dir)
  (setq dir (getstring "\nEnter Point Filter Direction:> X Y or Z: "))
  (if (or (= dir "x") (= dir "X")) (MXX))
  (if (or (= dir "y") (= dir "Y")) (MYY))
  (if (or (= dir "z") (= dir "Z")) (MZZ))
  (princ)
)
(defun MXX (/ osm slset pt1 pt2)
  (prompt "MOVE with .X Filter")(terpri)
  (setq slset (ssget))
  (setq pt1 (getpoint "Select Base Point of Object to move: "))(terpri)
  (setq pt2 (getpoint "Select destination .X of: "))(terpri)
  (command ".move" slset "" pt1 ".X" pt2 "@") ;change @ to pause without the quotes to manually pick direction
)
(defun MYY (/ osm slset pt1 pt2)
  (prompt "MOVE with .Y Filter")(terpri)
  (setq slset (ssget))
  (setq pt1 (getpoint "Select Base Point of Object to move: "))(terpri)
  (setq pt2 (getpoint "Select destination .Y of: "))(terpri)
  (command ".move" slset "" pt1 ".Y" pt2 "@")
)
(defun MZZ (/ osm slset pt1 pt2)
  (prompt "MOVE with .Z Filter")(terpri)
  (setq slset (ssget))
  (setq pt1 (getpoint "Select Base Point of Object to move: "))(terpri)
  (setq pt2 (getpoint "Select destination .Z of: "))(terpri)
  (command ".move" slset "" pt1 ".Z" pt2 "@")
)
;**********************************
(princ "\nEnter MPF to run program")
Move & Rotate along Axis in 3D

#2

Bennett
Join Date:
07-26-2007
Laison,
Welcome to the Exchange Forum. I tested your MPF function and it works fine. Here is another version using "initget" and "getkword" for your reference. The user must enter one of the option key words before the program proceeds to the next section in the code.
 
Regarding your request for the destination object and the source object to "Move & Rotate along its Axis" so that the two are aligned; have you considered using the "align" command in your function instead of the "move" command?
Code:
(defun c:MPF2 (/ dir)
  (initget "X Y Z")
  (if (not (setq dir (getkword "\nEnter Point Filter Direction <X>/Y/Z: ")))
    (setq dir "X")
  )
  (cond
    ((= dir "X") (MXX))
    ((= dir "Y") (MYY))
    ((= dir "Z") (MZZ))
  )
  (princ)
)
Move & Rotate along Axis in 3D

#3

Laison
Join Date:
03-11-2009
Bennett,
First of all I want to thank you for replying. You have no idea on how long I have been trying to find somebody with some knowledge that had a couple of minutes.
 
I tried the code that you uploaded, unfortunately I received the following errors:
Quote:
Command: mpf2 
Enter Point Filter Direction <X>/Y/Z: x 
; error: no function definition: MXX 
Command: mpf2 
Enter Point Filter Direction <X>/Y/Z: y 
; error: no function definition: MYY 
Command: mpf2 
Enter Point Filter Direction <X>/Y/Z: z 
; error: no function definition: MZZ
As far as the "align" command, it will mate up both components. What I am looking to incorporate, is something similar to the 3D rotate into my MPF.lsp function. Where once the destination point is selected it will move that component then prompt for an alignment angle, then the exact point is selected. Then which the source component is rotated in alignment, but stays on the same centerline from which it originated from before moving.
Move & Rotate along Axis in 3D

#4

Bennett
Join Date:
07-26-2007
Laison,
I just modified your MPF function and named it MPF2, but it was intended to be used with your existing MPF functions, MXX, MYY & MZZ. Sorry about the confusion. From your description it seems like you may need to incorporate the 'move' and 'rotate3d' commands into your functions. I'm not exactly sure what you are intending without a simple drawing of the before and after results that you want to accomplish. If that's not possible, perhaps you could just copy the related command line history into your post. That way I can see the prompts that you will be working with. For example:
Quote:
Command: rotate3d  Current positive angle:  ANGDIR=counterclockwise  ANGBASE=0.00 
Select objects: 1 found  Select objects: 
Specify first point on axis or define axis by 
[Object/Last/View/Xaxis/Yaxis/Zaxis/2points]:  
Move & Rotate along Axis in 3D

#5

Laison
Join Date:
03-11-2009
I want to move then rotate the tee in the horizontal that is above and on side of it so that it will align with horizontal tee that is rolled. All by selecting the rolled tee maybe twice at the most.
 
I attached a small model.

Attachments  3Dtest.dwg  
Move & Rotate along Axis in 3D

#6

Laison
Join Date:
03-11-2009
Ok, I just tried the align command. I used the midpoint of the tee as the 1st source point, then perp. to the branch of the rolled horiz. tee as my 1st destination point. I then used the center (the branch connection) of the tee as my 2nd source point. The 2nd destination point is the center of the rolled tee.
 
It worked. Now all I need to do is figure out this code and add it to the MPF.lsp file.
Move & Rotate along Axis in 3D

#7

Bennett
Join Date:
07-26-2007
Laison,
A few of us at work tried a few things with your 3Dtest drawing, including the "move", "rotate3d" and "align" commands.
I think the "align" command may be the best option for your function.
Move & Rotate along Axis in 3D

#8

Laison
Join Date:
03-11-2009
Yeah, I feel like such an idiot. I put this together a few minutes ago. It worked in AutoCad 2004 & 2009. The one advantage is that you do not have to select the source item.
 
I used the intersection of the tee as my 1st source point, then perp. to the centerline of rolled tee as my 1st destination point. The center of branch on the tee as my 2nd source point and the center of the rolled tee's branch as my 2nd destination point.
 
If anyone can use this, go ahead.
 
Thank you
Move & Rotate along Axis in 3D

#9

Bennett
Join Date:
07-26-2007
Laison,
Honestly we had a hard time figuring out exactly what points you were referring to with your description. And several of us just moved the objects as we thought you intended. Sometimes a picture is worth a thousand words. Maybe if you can provide an image similar to this one with the points labeled as 1, 2, 3 etc. that you are selecting, it might be helpful.



Attachments  3Dtest.gif