Author Topic: [XDrX-PM(4)]Define a dynamic drag move (copy) function(xd::drag:simplemove)  (Read 758 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
Define a general dynamic drag move (copy) function (xd::drag:simplemove)

Here is a simple DRAG MOVE:

Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. Function name: XD::Drag:SimpleMove
  3. Call format: (XD::Drag:SimpleMove ss info baseptflag tf)
  4. Parameter description: ss --- selection set or entity
  5. info -- prompt string
  6. baseptflag -- (1-9) the base point of dragging, the 9 feature points of the bounding box
  7. tf --- t move nil copy
  8. Return value: selection set
  9. Function introduction: basic implementation of moving, copying and dragging
  10. Function source: original
  11. Function author: Lispboy
  12. Applicable versions: XDRX API
  13. Last updated: 2016-05-12
  14. |;
  15. (defun XD::Drag:SimpleMove (ss info baseptflag tf / dynpt lastpnt myerr olderr pnt)
  16.   (defun _callback (dynpt)
  17. ;|
  18. The callback function only performs a simple operation
  19. Call the MOVE function to move the selection set
  20. |;
  21.     (xdrx_entity_move ss lastpnt dynpt)
  22.     (setq lastpnt dynpt)
  23.   )                                  
  24.   (cond ((= (type baseptflag) 'INT)
  25.          (if (or (< baseptflag 1) (> baseptflag 9))
  26.            (setq baseptflag 5)
  27.          )
  28.          (setq lastpnt (trans (xd::geom:get9pt ss baseptflag) 1 0))
  29.         )
  30.         ((and (= (type baseptflag) 'LIST)
  31.               (or (= (length baseptflag) 2) (= (length baseptflag) 3))
  32.               (vl-every '(lambda (x) (or (= (type x) 'INT) (= (type x) 'REAL)))
  33.                         baseptflag
  34.               )
  35.          )
  36.          (setq lastpnt baseptflag)
  37.         )
  38.         (t (setq lastpnt (trans (xd::geom:get9pt ss 5) 1 0)))
  39.   )
  40.   (if (not tf)
  41.     (setq ss (xdrx_entity_copy ss))
  42.   )
  43.   (xdrx_pointmonitor "_callback" ss)
  44.   (initget 1)
  45.   (if (setq pnt (getpoint info))
  46.     (setvar "lastpoint" pnt)
  47.   )
  48.   (xdrx_pointmonitor)                  
  49.   pnt
  50. )

The following is a more complex drag move general function,
Allows you to customize your own callback function and handle your events in the general drag move function.


Code - Auto/Visual Lisp: [Select]
  1. (defun XD::Drag:SimpleMove
  2.        (ss info baseptflag tf / dynpt lastpnt myerr olderr pnt mlastpnt)
  3.   (defun _tmpmovecallback (dynpt)
  4.     (if
  5.       (and
  6.         (= (type #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack) 'STR)
  7.         (or (= (type (eval (read #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack)))
  8.                'SUBR
  9.             )
  10.             (= (type (eval (read #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack)))
  11.                'USUBR
  12.             )
  13.         )
  14.       )
  15.        (eval (list (read #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack)
  16.                    (read "dynpt")
  17.              )
  18.        )
  19.     )
  20.     (if (setq pnt (XD::Drag:CallBackGetDynPnt))
  21.       (setq dynpt pnt)
  22.     )
  23.     (xdrx_entity_move ss #xd-var-global-drag-basepoint dynpt)
  24.     (setq #xd-var-global-drag-basepoint dynpt)
  25.   )
  26.   (defun myerr (msg)
  27.     (princ "\nCancel")
  28.     (redraw)
  29.     (xdrx_end)
  30.     (vl-cmdf ".undo" 1)
  31.     (setq *error* olderr)
  32.   )
  33.   (setq olderr *error*)
  34.   (setq *error* myerr)
  35.   (cond
  36.     ((= (type baseptflag) 'INT)
  37.      (if (or (< baseptflag 1) (> baseptflag 9))
  38.        (setq baseptflag 5)
  39.      )
  40.      (setq lastpnt (trans (xd::geom:get9pt ss baseptflag) 1 0))
  41.     )
  42.     ((and
  43.        (= (type baseptflag) 'LIST)
  44.        (or (= (length baseptflag) 2) (= (length baseptflag) 3))
  45.        (vl-every '(lambda (x) (or (= (type x) 'INT) (= (type x) 'REAL)))
  46.                  baseptflag
  47.        )
  48.      )
  49.      (setq lastpnt baseptflag)
  50.     )
  51.     (t (setq lastpnt (trans (xd::geom:get9pt ss 5) 1 0)))
  52.   )
  53.   (xd::drag:setbasepoint lastpnt)
  54.   (setq #xd-var-global-drag-basepoint lastpnt)
  55.   (if (not tf)
  56.     (setq ss (xdrx_entity_copy ss))
  57.   )
  58.  
  59.   (initget 1)
  60.   (setq tf t)
  61.   (while (and tf (xdrx_pointmonitor "_tmpmovecallback" ss)(xd::doc:getkeyword) (setq pnt (getpoint info)))
  62.     (cond
  63.       ((= (type pnt) 'STR)
  64.        (xdrx-pointmonitor)
  65.        (xd::drag:setbasepoint #xd-var-global-drag-basepoint)
  66.        (if
  67.          (and
  68.            (= (type #XD-VAR-FUNC-DRAG-KeyWord-CallBack) 'STR)
  69.            (or (= (type (eval (read #XD-VAR-FUNC-DRAG-KeyWord-CallBack)))
  70.                   'SUBR
  71.                )
  72.                (= (type (eval (read #XD-VAR-FUNC-DRAG-KeyWord-CallBack)))
  73.                   'USUBR
  74.                )
  75.            )
  76.          )
  77.           (eval (list (read #XD-VAR-FUNC-DRAG-KeyWord-CallBack)
  78.                       (read "pnt")
  79.                 )
  80.           )
  81.        )
  82.        (setq #xd-var-global-drag-basepoint (xd::drag:getbasepoint))
  83.       )
  84.       ((= (type pnt) 'LIST)
  85.        (setq tf nil)
  86.        (setvar "lastpoint" pnt)
  87.       )
  88.     )
  89.       (xdrx_pointmonitor)
  90.  
  91.   )
  92.   (setq *error* olderr)
  93.   pnt
  94. )

Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. Function name: XD::Drag:CallBackSetMouseMove
  3. Call format: (XD::Drag:CallBackSetMouseMove func)
  4. Parameter description: func --- String function name
  5. Return value: Successfully returns the function name string
  6. No returns NIL
  7. Function introduction: Set the mouse movement callback processing function of the drag series function
  8. Function source: original
  9. Function author: XDSoft
  10. Applicable versions: XDRX API
  11. Last updated: 2016-07-08
  12. Note: The callback function has one parameter, the point parameter. The value of the point parameter is the point where the mouse moves on the dynamic point monitor. The callback function performs processing operations based on this point.
  13. |;
  14. (defun XD::Drag:CallBackSetMouseMove (func)
  15.   (setq #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack nil)
  16.   (setq #XD-VAR-FUNC-DRAG-MOUSEMove-CallBackDynPnt nil)
  17.   (if (and
  18.         (= (type func) 'STR)
  19.         (or (= (type (eval (read func))) 'SUBR)
  20.             (= (type (eval (read func))) 'USUBR)
  21.         )
  22.       )
  23.     (setq #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack func)
  24.   )
  25.   #XD-VAR-FUNC-DRAG-MOUSEMove-CallBack
  26. )
  27. (defun XD::Drag:CallBackSetDynPnt (pnt)
  28.    (setq #XD-VAR-FUNC-DRAG-MOUSEMove-CallBackDynPnt pnt)
  29. )
  30. (defun XD::Drag:CallBackGetDynPnt ()
  31.    #XD-VAR-FUNC-DRAG-MOUSEMove-CallBackDynPnt
  32. )
  33. (defun XD::Drag:CallBackSetKeyWord (str)
  34.    (setq #XD-VAR-FUNC-DRAG-MOUSEMove-CallBackKeyWord str)
  35. )
  36. (defun XD::Drag:CallBackSetKeyWord (func)
  37.   (setq #XD-VAR-FUNC-DRAG-KeyWord-CallBack nil)
  38.   (if (and (= (type func) 'STR)
  39.            (or (= (type (eval (read func))) 'SUBR)
  40.                (= (type (eval (read func))) 'USUBR)
  41.            )
  42.       )
  43.     (setq #XD-VAR-FUNC-DRAG-KeyWord-CallBack func)
  44.   )
  45.   #XD-VAR-FUNC-DRAG-KeyWord-CallBack
  46. )
  47. (defun XD::Drag:CallBackGetKeyWord ()
  48.    #XD-VAR-FUNC-DRAG-KeyWord-CallBack
  49. )
  50. ;|
  51. Function name: XD::Drag:CallBackSetMouseLeftClick
  52. Call format: (XD::Drag:CallBackSetMouseLeftClick func)
  53. Parameter description: func ---- callback function name string
  54. Return value: Successfully returns the function name string
  55. Otherwise return NIL
  56. Function introduction: Set the left mouse button click callback processing function of the dynamic drag series function
  57. Function source: original
  58. Function author: XDSoft
  59. Applicable versions: XDRX API
  60. Last updated: 2016-07-08
  61. Note: How to write the callback function:
  62. There is one parameter, the point parameter. The value of the point parameter is the point where the mouse moves on the dynamic point monitor. The callback function performs processing operations based on this point.
  63. |;
  64. (defun XD::Drag:CallBackSetMouseLeftClick (func)
  65.   (setq #XD-VAR-FUNC-DRAG-MOUSELeftClick-CallBack nil)
  66.   (if (and
  67.         (= (type func) 'STR)
  68.         (or (= (type (eval (read func))) 'SUBR)
  69.             (= (type (eval (read func))) 'USUBR)
  70.         )
  71.       )
  72.     (setq #XD-VAR-FUNC-DRAG-MOUSELeftClick-CallBack func)
  73.   )
  74.   #XD-VAR-FUNC-DRAG-MOUSELeftClick-CallBack
  75. )
  76.  


=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API and is updated at any time.

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message
« Last Edit: November 20, 2023, 06:42:08 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net