Author Topic: [XDrX-PlugIn(8)] Modify HATCH Line spacing and batch modify HATCH entities  (Read 900 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 514
The code written in the forum is mainly to demonstrate the usage of the main functions to be introduced. There may be a better or direct way to implement it.

The following code mainly introduces Let SSGET support keywords.....



1. Let SSGET support keywords, callback functions, and modify prompt strings.
;|
xdrx-initssget
1.ssget Supports CallBack Function Usages,
 
2.Supports one-click carriage return. For example, if you enter B, you can enter directly.|;
  (xdrx-initssget "\nPlease select the padding to be modified [Scale(B)/Spacing(V)]<Exit>:"
    "B V"
    ""
    "-KEYWORD"
  )


Code - Auto/Visual Lisp: [Select]
  1.  
  2. (xdrx-initssget
  3.     "\nPlease select the padding to be modified [Scale(B)/Spacing(V)]<Exit>:"
  4. ;;Replace "Select Objects:" with the prompt string
  5.     "B V"  
  6. ;;Keyword, supports one-click carriage return. After entering the keyword, enter the callback function processing, and then continue the SSGET process.
  7.     ""
  8.     "-KEYWORD"
  9. ;;CallBack Function
  10.   )
  11. (xdrx-ssget '((0 . "hatch") (2 . "~solid")))
  12.  


Code - Auto/Visual Lisp: [Select]
  1. (defun c:xdtb-hatchmodscl (/ gap scl ss i x)
  2.   (defun -prompt ()
  3.     (xdrx-prompt
  4.       "\nCurrent settings: "
  5.       (cond ((= #xd-var-global-mode-hatch-mode 0) "Scale(")
  6.             ((= #xd-var-global-mode-hatch-mode 1) "Spacing(")
  7.       )
  8.       #xd-var-global-gap
  9.       ")"
  10.     )
  11.   )
  12.   (defun -keyword (key)
  13.     (cond ((= key "B")
  14.            (if (setq val (getreal
  15.                            (xdrx-prompt
  16.                              "\nInput Scale<"
  17.                              #xd-var-global-gap
  18.                              ">:"
  19.                              t
  20.                            )
  21.                          )
  22.                )
  23.              (setq #xd-var-global-gap val)
  24.            )
  25.            (setq #xd-var-global-mode-hatch-mode 0)
  26.           )
  27.           ((= key "V")
  28.            (if (setq val
  29.                       (getreal
  30.                         (xdrx-prompt "\nInput Spacing<" #xd-var-global-gap ">:" t)
  31.                       )
  32.                )
  33.              (setq #xd-var-global-gap val)
  34.            )
  35.            (setq #xd-var-global-mode-hatch-mode 1)
  36.           )
  37.     )
  38.     (-prompt)
  39.   )
  40.   (xdrx-begin)
  41.   (xdrx-initget "B V")
  42.   (if (not #xd-var-global-gap)
  43.     (setq #xd-var-global-gap 1.0)
  44.   )
  45.   (if (not #xd-var-global-mode-hatch-mode)
  46.     (setq #xd-var-global-mode-hatch-mode 0)
  47.   )
  48.   (-prompt)
  49. ;|
  50. xdrx-initssget
  51. 1.ssget Supports CallBack Function Usages,
  52.   Let SSGET support keywords, callback functions, and modify prompt strings.
  53. 2.Supports one-click carriage return. For example, if you enter B, you can enter directly.|;
  54.   (xdrx-initssget
  55.     "\nPlease select the padding to be modified [Scale(B)/Spacing(V)]<Exit>:"
  56.     "B V"
  57.     ""
  58.     "-KEYWORD"
  59.   )
  60.   (if (setq ss (xdrx-ssget '((0 . "hatch") (2 . "~solid"))))
  61.     (progn
  62.       (if (= #xd-var-global-mode-hatch-mode 0)
  63.         (xdrx-entity-setproperty
  64.           ss
  65.           "patternscale"
  66.           #xd-var-global-gap
  67.         )
  68.         (progn
  69.           (setq i 0)
  70.           (mapcar
  71.             '(lambda (x)
  72.                (if
  73.                  (setq gap (xdrx-getpropertyvalue x "ParallelSpacing"))
  74.                   (progn (setq gap (car gap)
  75.                                scl (xdrx-getpropertyvalue x "PatternScale")
  76.                                scl (* scl (/ #xd-var-global-gap gap))
  77.                          )
  78.                          (xdrx-setpropertyvalue x "patternscale" scl)
  79.                          (setq i (1+ i))
  80.                   )
  81.                )
  82.              )
  83.             (xdrx-pickset->ents ss)
  84.           )
  85.           (xdrx-prompt
  86.             "\nSelected"
  87.             (sslength ss)
  88.             "Hatch, modified successfully"
  89.             i
  90.           )
  91.         )
  92.       )
  93.     )
  94.   )
  95.   (xdrx-end)
  96.   (princ)
  97. )
« Last Edit: November 26, 2023, 05:27:28 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