home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November / PCWK1103B.iso / DesignCAD 3D Max PLUS trial 30 / DATA1.CAB / Example_Files / Sample_Macros / 4PtMove.d3m < prev    next >
Encoding:
Text File  |  2003-09-29  |  2.0 KB  |  113 lines

  1. 'Sys(800) = 1          ' +++++++ Turn on Tracing Dialog
  2.  
  3. nSelEntity = sys(80)
  4.  
  5. if nSelEntity < 1 then
  6.   Message "Please select objects before running this program"
  7.   end
  8.   endif
  9.  
  10. SETPOINT "Set points: 1-Lower Left, 2-Lower Right, 3-Upper Left, 4-Upper Right", 4
  11. if sys(1) < 4 then
  12.   Message "Four points are needed to complete the command."
  13.   end
  14.   endif
  15.  
  16. POINTVAL Qx, Qy, Qz, 3
  17. POINTVAL Rx, Ry, Rz, 4
  18. POINTVAL Sx, Sy, Sz, 2
  19. POINTVAL Tx, Ty, Tz, 1
  20.  
  21. sys(36) = 1
  22.  
  23. >VectorConvert
  24. {
  25.   }
  26.  
  27. minX = sys(196)
  28. minY = sys(197)
  29. maxX = sys(198)
  30. maxY = sys(199)
  31.  
  32. Ax = minX
  33. Ay = maxY
  34.  
  35. Bx = maxX
  36. By = maxY
  37.  
  38. Cx = maxX
  39. Cy = minY
  40.  
  41. Dx = minX
  42. Dy = minY
  43.  
  44. dim x(400), y(400), z(400)
  45.  
  46. nSelEntity = sys(80)
  47.  
  48. for i = 1 to nSelEntity
  49.   GetSelect i, k
  50.   Entity k
  51.  
  52.   if sys(90) = 1 then
  53.     npts = sys(99)
  54.     for j = 1 to npts
  55.       PointVal x(j), y(j), z(j), j
  56.       ratio1 = (x(j) - Dx) / (Cx - Dx)
  57.       ratio2 = (y(j) - Dy) / (Ay - Dy)
  58.  
  59.       pTSx = Tx + ratio1*(Sx-Tx)
  60.       pTSy = Ty + ratio1*(Sy-Ty)
  61.       pTSz = Tz + ratio1*(Sz-Tz)
  62.  
  63.       pQRx = Qx + ratio1*(Rx-Qx)
  64.       pQRy = Qy + ratio1*(Ry-Qy)
  65.       pQRz = Qz + ratio1*(Rz-Qz)
  66.  
  67.       pTQx = Tx +ratio2*(Qx-Tx)
  68.       pTQy = Ty +ratio2*(Qy-Ty)
  69.       pTQz = Tz +ratio2*(Qz-Tz)
  70.  
  71.       pSRx = Sx + ratio2*(Rx-Sx)
  72.       pSRy = Sy + ratio2*(Ry-Sy)
  73.       pSRz = Sz + ratio2*(Rz-Sz)
  74.  
  75.       b = ((pSRy-pTQy)*(pTQx-pTSx)-(pSRx-pTQx)*(pTQy-pTSy))/((pSRy-pTQy)*(pQRx-pTSx)-(pSRx-pTQx)*(pQRy-pTSy))
  76.  
  77.       x(j) = pTSx + b*(pQRx-pTSx)
  78.       y(j) = pTSy + b*(pQRy-pTSy)
  79.       z(j) = pTSz + b*(pQRz-pTSz)
  80.       next
  81.  
  82.       ir = sys(290)
  83.       ig = sys(291)
  84.       ib = sys(292)
  85.       lay = sys(93)
  86.       ltype = sys(91)
  87.       dscale = sys(97)
  88.       bold = sys(98)
  89.  
  90.       >Line
  91.       {
  92.         <Color [ir, ig, ib]
  93.         <Layer [lay]
  94.         <LineStyle [ltype, dscale, bold]
  95.  
  96.         for j = 1 to npts
  97.           <PointXYZ [x(j), y(j), z(j)]
  98.           next
  99.         }
  100.     endif
  101.  
  102.   next
  103.  
  104. >SelectDelete
  105. {
  106.   }
  107.  
  108. >Regenerate
  109. {
  110.   }
  111.  
  112. sys(36) = 0
  113.