Author Topic: MOVE & ROTATE ALONG AXIS (3D)  (Read 3136 times)

0 Members and 1 Guest are viewing this topic.

laison

  • Guest
MOVE & ROTATE ALONG AXIS (3D)
« on: March 11, 2009, 10:45:03 PM »
I have this lisp file that will move objects in 2D & 3D. Once it is activated it asked for X, Y or Z planes. It works great. I want to add on to it are find another file that will move and rotate (align, turn, orientate) with another object in 3D just by selecting he object that I want to line up with, even though the distance is unknown, the angle is unknown.

Example:
I have this horizontal pipe with a tee in it that I need to connect to running north/south.
I am running another pipe a few feet over and above in the vertical with a tee pointing towards the tee.

After I add an (elbow,tee, whatever) I would like the fitting to move and align it's points just by selecting the destination point.

This would be a great time saver. I see many move, rotate but it is for 2D only. I HAVE LOOKED. Bentley Autoplant has this feature built in to there software. So I know that this is possible.

This is the code that I have:

Code: [Select]
;;; 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))
)
(defun MXX (/ osm slset pt1 pt2)(terpri)
(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)(terpri)
(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)(terpri)
(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 "@")
)
;****************
(prompt "Enter MPF to run program")(terpri)

<edit: CAB added code tags>
« Last Edit: March 12, 2009, 12:12:17 AM by CAB »

James Cannon

  • Guest
Re: MOVE & ROTATE ALONG AXIS (3D)
« Reply #1 on: March 11, 2009, 11:25:07 PM »
I'm sorry I have not tried your routine yet so forgive me if this is a dumb question.  I may have also not understood your textual example scenario either, but is this something that the "ALIGN" command fails to achieve?

laison

  • Guest
Re: MOVE & ROTATE ALONG AXIS (3D)
« Reply #2 on: March 14, 2009, 07:14:28 PM »
What the align command does is mated the 2 different component together. I do not want this. Let say I have 2 different lines (pipe with fittings). One is running east-west and the is above and on side of it. I am go to put a tee in the line then an elbow that I would roll on some angle that I do not know.  When I activate this lisp file and select the elbow I want a destination point or fitting to align with, which would the tee in the other line. The  lisp file would then move the elbow along the centerline that it is currently on then rotate the other end of it so that the 2 fitting would be in alignment. Bentley Autoplant has this feature so
I know that it can be done.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: MOVE & ROTATE ALONG AXIS (3D)
« Reply #3 on: March 16, 2009, 01:02:54 PM »
Perhaps if you provided a sample DWG with the objects before & another set of objects after the alignment.
This would allow us to see exactly what need to happen in the lisp.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

laison

  • Guest
Re: MOVE & ROTATE ALONG AXIS (3D)
« Reply #4 on: March 18, 2009, 03:25:06 AM »
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.
What I am looking to incorporate something similar 3D rotate into MPF.lsp. 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 then source component is rotated in alignment (but stays on the same centerline from which it originated from before moving). 

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: MOVE & ROTATE ALONG AXIS (3D)
« Reply #5 on: March 18, 2009, 07:09:15 AM »
Hi,

Here's the one I use for this kind of stuff.
It works with blocks.
Maybe it can helps.

Code: [Select]
;; INS3D -Gilles Chanteau- (gile) 11/04/07
;; Insert a block ine the plane specified by 3 points
;; INS3D to choos the block in a dialog box
;; -INS3D to enter the block name at command line

(defun c:ins3d (/ nam)
  (and
    (setq nam (getBlock nil))
    (ins3d nam)
  )
  (princ)
)

(defun c:-ins3d (/ nam)
  (and
    (setq nam (getstring T "\Enter the name of the block to insert: "))
    (or (tblsearch "BLOCK" nam)
(findfile nam)
(findfile (setq nam (strcat nam ".dwg")))
    )
    (ins3d nam)
  )
  (princ)
)

(defun ins3d (nam / AcDoc Space opt xsc ysc zsc xpt ypt blk nor)
  (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
Space (if (= 1 (getvar "CVPORT"))
(vla-get-PaperSpace AcDoc)
(vla-get-ModelSpace AcDoc)
      )
  )
  (if (not
(setq opt
       (getpoint
"\nSpecify insertion point or <scale>: "
       )
)
      )
    (progn
      (if
(not (setq
       xsc (getreal
     "\nEnter X scale factor <1>: "
   )
     )
)
(setq xsc 1.0)
      )
      (if (not (setq
ysc
  (getreal
    "\nEnter Y scale factor <use X scale factor>: "
  )
       )
  )
(setq ysc xsc)
      )
      (if (not (setq
zsc
  (getreal
    "\nEnter Z scale factor <use X scale factor>: "
  )
       )
  )
(setq zsc xsc)
      )
      (initget 1)
      (setq opt (getpoint "\nSpecify insertion point: "))
    )
    (setq xsc 1
  ysc 1
  zsc 1
    )
  )
  (setq xpt opt
ypt opt
  )
  (while (equal xpt opt 1e-9)
    (setq xpt
   (getpoint
     opt
     "\nSpecify point on positive portion of the block X-axis:"
   )
    )
  )
  (while (or (equal ypt opt 1e-9) (equal ypt xpt 1e-9))
    (setq ypt
   (getpoint
     opt
     "\nSpecify point on positive Y portion of the block XY plane: "
   )
    )
  )
  (foreach p '(opt xpt ypt)
    (set p (trans (eval p) 1 0))
  )
  (if (setq blk
     (vla-InsertBlock
       Space
       (vlax-3d-Point '(0 0 0))
       nam
       xsc
       ysc
       zsc
       0.0
     )
      )
    (progn
      (vla-TransformBy
blk
(vlax-tmatrix
  (append
    (mapcar
      '(lambda (v o)
(append v (list o))
       )
      (mxm
(trp
  (reverse
    (list
      (setq nor (norm_3pts opt xpt ypt))
      (norm_3pts '(0 0 0) nor (mapcar '- xpt opt))
      (vec1 opt xpt)
    )
  )
)
(mapcar
  '(lambda (v) (trans v (trans '(0 0 1) 1 0 T) 0 T))
  '((1 0 0) (0 1 0) (0 0 1))
)
      )
      opt
    )
    (list '(0 0 0 1))
  )
)
      )
      (setvar "INSNAME" (vl-filename-base nam))
    )
  )
)

;;; Getblock (gile) 03/11/07
;;; Returns a valid block name entered or coosed by the user
;;; from a popup or the standard file dialog
;;; Argument : the title (string) or nil (défault : "Choose a block")

(defun getblock (titre / bloc n lst tmp file what_next dcl_id nom)
  (while (setq bloc (tblnext "BLOCK" (not bloc)))
    (setq lst (cons (cdr (assoc 2 bloc)) lst)
    )
  )
  (setq lst  (acad_strlsort
       (vl-remove-if
(function (lambda (n) (= (substr n 1 1) "*")))
lst
       )
     )
tmp  (vl-filename-mktemp "Tmp.dcl")
file (open tmp "w")
  )
  (write-line
    (strcat
      "getblock:dialog{label="
      (cond (titre (vl-prin1-to-string titre))
    ("\"Choose a block\"")
      )
      ";initial_focus=\"bl\";:boxed_column{
      :row{:text{label=\"Select\";alignment=left;}
      :button{label=\">>\";key=\"sel\";alignment=right;fixed_width=true;}}
      spacer;
      :column{:button{label=\"Browse...\";key=\"wbl\";alignment=right;fixed_width=true;}}
      :column{:text{label=\"Name :\";alignment=left;}}
      :edit_box{key=\"tp\";edit_width=25;}
      :popup_list{key=\"bl\";edit_width=25;}spacer;}
      spacer;
      ok_cancel;}"
    )
    file
  )
  (close file)
  (setq dcl_id (load_dialog tmp))
  (setq what_next 2)
  (while (>= what_next 2)
    (if (not (new_dialog "getblock" dcl_id))
      (exit)
    )
    (start_list "bl")
    (mapcar 'add_list lst)
    (end_list)
    (if (setq n (vl-position
  (strcase (getvar "INSNAME"))
  (mapcar 'strcase lst)
)
)
      (setq nom (nth n lst))
      (setq nom (car lst)
    n 0
      )
    )
    (set_tile "bl" (itoa n))
    (action_tile "sel" "(done_dialog 5)")
    (action_tile "bl" "(setq nom (nth (atoi $value) lst))")
    (action_tile "wbl" "(done_dialog 3)")
    (action_tile "tp" "(setq nom $value) (done_dialog 4)")
    (action_tile
      "accept"
      "(setq nom (nth (atoi (get_tile \"bl\")) lst)) (done_dialog 1)"
    )
    (setq what_next (start_dialog))
    (cond
      ((= what_next 3)
       (if (setq nom (getfiled "Select a file" "" "dwg" 0))
(setq what_next 1)
(setq what_next 2)
       )
      )
      ((= what_next 4)
       (cond
((not (read nom))
  (setq what_next 2)
)
((tblsearch "BLOCK" nom)
  (setq what_next 1)
)
((findfile (setq nom (strcat nom ".dwg")))
  (setq what_next 1)
)
(T
  (alert (strcat "The file \"" nom "\" can't be found."))
  (setq nom nil
what_next 2
  )
)
       )
      )
      ((= what_next 5)
       (if (and (setq ent (car (entsel)))
(= "INSERT" (cdr (assoc 0 (entget ent))))
   )
(setq nom (cdr (assoc 2 (entget ent)))
       what_next 1
)
(setq what_next 2)
       )
      )
      ((= what_next 0)
       (setq nom nil)
      )
    )
  )
  (unload_dialog dcl_id)
  (vl-file-delete tmp)
  nom
)

;;; VEC1 (gile)
;;; Returns the single unit vector from p1 to p2

(defun vec1 (p1 p2 / d)
  (if (not (zerop (setq d (distance p1 p2))))
    (mapcar (function (lambda (x1 x2) (/ (- x2 x1) d))) p1 p2)
  )
)

;;; VXV (gile)
;;; Returns the dot product of 2 vectors
(defun vxv (v1 v2)
  (apply '+ (mapcar '* v1 v2))
)

;; Transpose a matrice Doug Wilson
(defun trp (m)
  (apply 'mapcar (cons 'list m))
)

;; Apply a transformation matrix to a vector by Vladimir Nesterovsky
(defun mxv (m v)
  (mapcar (function (lambda (r) (vxv r v))) m)
)

;; Multiply two matrices by Vladimir Nesterovsky
(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)
Speaking English as a French Frog

laison

  • Guest
Re: MOVE & ROTATE ALONG AXIS (3D)
« Reply #6 on: March 19, 2009, 06:07:48 PM »
I tried thios but it didn't work. The components are not blocks. Thanks for trying.