Author Topic: [XDrX-Function(4)] The ultimate solution to SSGET with keywords  (Read 966 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 527
[XDrX-Function(4)] The ultimate solution to SSGET with keywords
« on: November 28, 2023, 11:31:24 PM »
The 2016.0923 version of the API finally provides the "ultimate" solution to SSGET with keywords.

SSGET with keywords has always been what LISPER wants, but limited by the functions of LISP, no matter what kind of LISP solution, the SSGET selection cannot be perfectly combined with GETXXX keywords.
Because the API relies on ARX, it combines ARX's acedSSGetKwordPtr() and other functions with LISP usage habits and encapsulates them, bringing the API functions xdrx_initSSGet and xdrx_ssget functions.

Just like the keyword setting of the GETXXX class requires the function initget, xdrx_ssget requires the xdrx_initssget function preset keyword and other information.

Usage of xdrx-initssget function:

Code - Auto/Visual Lisp: [Select]
  1. (xdrx_initSSGet <"Select object prompt string"> ["Keyword"] ["Remove object prompt string"] ["Keyword callback function"] ["Non-keyword input callback function"])
  2. Parameters between <> are required, and parameters between [] are optional.

1. Select object prompt string: SSGET no longer looks at the static "Select object:" prompt string. You can customize your
    own prompt string. 2. Keywords: Enter keywords separated by spaces, and do not conflict with SSGET's own "fixed"
    keywords, such as W, C, WP, CP, etc.
3. Remove object prompt string: Customize your own prompt string when inputting R in SSGET.
4. Keyword callback function: After entering the keyword, activate the function called to process the keyword (optional)
5. Non-keyword callback function: the processing function called when a non-keyword is entered (optional)

The API has two schemes for handling keywords:

1. Give the callback function parameters:

       Features: Without interrupting SSGET, the function that needs to be processed after the callback function processes
       the keyword completes the required work. After the callback function is executed, the SSGET process continues.

2. No callback function:

       Features, just like the keyword processing method we are used to in GETXXX class functions, when keyword parameters are given, if no callback function parameters are given or "" is given to the callback function, then when the keyword is entered, SSGET ends and a string is returned. to LISP.

3. The parameters of the selection set function xdrx_ssget are the same as those of the ordinary SSGET function.

       Here are two sets of example programs for processing keywords:

1) In xdrx_initSSGet, give keywords and callback function parameters, process keywords, and enter the distance of the offset polyline without interrupting SSGET.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt()
  2.     (xdrx_begin)
  3.     (if (not #wid)
  4.       (setq #wid 10)
  5.     )
  6.     (xdrx_initssget "Select the curve to be offset [Settings (XL)]<Exit>:";;Select object prompt string
  7.                     "XL" ;;keyword
  8.                     "" ;;Remove object prompt string
  9.                     "_callback" ;;Keyword callback function
  10.                     "_callback1" ;;Non-keyword callback function
  11.     )
  12.     (defun _callback(kword)
  13.        (princ (strcat "\nKeyword selected: " kword))
  14.        (if (= kword "XL")
  15.           (if (setq wid (getreal (xdrx_prompt "\nPlease enter the offset distance<" #wid ">:" t)))
  16.             (setq #wid wid)
  17.           )
  18.        )
  19.        (princ)
  20.     )
  21.     (defun _callback1(kword)
  22.       (princ)
  23.     )
  24.     (if (setq ss (xdrx_ssget '((0 . "LWPOLYLINE")(-4 . "&=")(70 . 1))))
  25.        (progn
  26.           (xdrx_curve_getoffsetcurves ss #wid)
  27.        )
  28.     )
  29.     (xdrx_end)
  30.     (princ)
  31. )

2) The code structure is the same as that of ordinary GETXXX function processing keywords, and is processed according to the returned keywords (SSGET is interrupted during the period)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (not #wid)
  4.      (setq #wid 10)
  5.    )
  6.    (setq tf t)
  7.    (while (and
  8.             tf
  9.             (xdrx_initssget "Select the curve to be offset [Settings (XL)]<Exit>:" "XL" "" "" "")
  10.             (setq ss (xdrx_ssget))
  11.           )
  12.        (setq tf1 (type ss))
  13.        (cond
  14.          ((= tf1 'STR)
  15.            (if (= ss "XL")
  16.              (if (setq wid (getreal (xdrx_prompt "\nPlease enter the offset distance<" #wid
  17.                                                  ">:" t
  18.                                     )
  19.                            )
  20.                  )
  21.                (setq #wid wid)
  22.              )
  23.            )
  24.          )
  25.          ((= tf1 'PICKSET)
  26.            (xdrx_curve_getoffsetcurves ss #wid)
  27.            (setq tf nil)
  28.          )
  29.        )
  30.    )
  31.    (xdrx_end)
  32.    (princ)
  33. )

xdrx_ssget perfectly combines keyword processing and SSGET operations. On the basis of keyword processing, it fully realizes the function of SSGET.

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



In fact, rewrite the second solution above as follows:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (defun _getdist()
  3.      (if (setq wid (getreal (xdrx_prompt
  4.                               "\nPlease enter the offset distance<"
  5.                               #wid
  6.                               ">:"
  7.                               t
  8.                             )
  9.                    )
  10.          )
  11.        (setq #wid wid)
  12.      )
  13.    )
  14.    (defun _prompt ()
  15.      (xdrx-prompt
  16.        "\nCurrent Setting: ***offset distance ( "
  17.        #wid
  18.        " )***"
  19.      )
  20.    )
  21.    (xdrx_begin)
  22.    (if (not #wid)
  23.      (setq #wid 10)
  24.    )
  25.    (setq tf t)
  26.    (while (and
  27.             tf
  28.             (_prompt)
  29.             (xdrx-initget "T");;Set input T and press Enter directly
  30.             (xdrx_initssget
  31.               "Select the curve to be offset [Settings(T)] <Exit>:"
  32.               "T" ""
  33.               "" ""
  34.              )
  35.             (setq ss (xdrx_ssget))
  36.           )
  37.      (setq tf1 (type ss))
  38.      (cond
  39.        ((= tf1 'STR)
  40.         (if (= ss "T")
  41.           (_getdist)
  42.           ;; Call the function (is it equivalent to the callback function of the first solution?)
  43.         )
  44.        )
  45.        ((= tf1 'PICKSET)
  46.         (setq ss1 (xdrx_curve_getoffsetcurves ss #wid))
  47.         (xdrx-entity-setcolor ss1 1)
  48.         (setq tf nil)
  49.        )
  50.      )
  51.    )
  52.    (xdrx_end)
  53.    (princ)
  54. )

Compared with the first solution, the first solution is to put the function _getdist() into xdrx_initssget and declare it. The judgment and processing of whether to enter the keyword are all processed inside xdrx_ssget, without interrupting the ssget process, and the code is shorter ( There is no WHILE loop and COND judgment keyword), and the efficiency is higher.

The above code can be omitted:

Code - Auto/Visual Lisp: [Select]
  1.        ((= tf1 'STR)
  2.         (if (= ss "XL")
  3.           (_getdist)
  4.           ;; Call the function (is it equivalent to the callback function of the first solution?)
  5.         )
  6.        )
  7.        ((= tf1 'PICKSET)
  8.         (xdrx_curve_getoffsetcurves ss #wid)
  9.         (setq tf nil)
  10.        )
  11. )
  12.  

Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss (xdrx_ssget '((0 . "LWPOLYLINE")(-4 . "&=")(70 . 1))))
  2.       (progn
  3.          (xdrx_curve_getoffsetcurves ss #wid)
  4.       )
  5.    )
  6.  

Equivalent to:

Code - Auto/Visual Lisp: [Select]
  1.             tf
  2.             (xdrx_initssget
  3.               "Select the curve to be offset [Settings (XL)] <Exit>:"
  4.               "XL" ""
  5.               "" ""
  6.              )
  7.             (setq ss (xdrx_ssget))
  8.           )
  9.      (setq tf1 (type ss))
  10.      (cond
  11.        ((= tf1 'STR)
  12.         (if (= ss "XL")
  13.           (_getdist)
  14.           ;; Call the function (is it equivalent to the callback function of the first solution?)
  15.         )
  16.        )
  17.        ((= tf1 'PICKSET)
  18.         (xdrx_curve_getoffsetcurves ss #wid)
  19.         (setq tf nil)
  20.        )
  21.      )
  22. )
  23.  

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

1. Only the selection prompt string is required, the others are optional.

2. If keywords and callback functions are given, then it is the first option.

3. If a keyword is given and the keyword callback function is not given, this is the second option.

4. The non-keyword callback function does not matter, whether it is provided or not does not matter. This is to adapt to the expansion of ARX functions. Currently, it will never be given or "" will be given.
« Last Edit: December 04, 2023, 01:29:18 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net