Author Topic: [XDrX-PlugIn(21)] Text (Attrib) Copy+1  (Read 3000 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 527
[XDrX-PlugIn(21)] Text (Attrib) Copy+1
« on: November 29, 2023, 01:26:59 AM »






Code - Auto/Visual Lisp: [Select]
  1. (defun c:XDTB_Copy+1 (/ base dis dynpt e1 i msg myerr num olderr p p1 p2 pos posl pt tf txt txt2 typ v x pnt
  2.                         pt v1 v2 pts sp1 sp2 dp1 dp2 ents oper info #xd_var_global_bits txt1 prev next
  3.                      )
  4.   (defun _callback1 (dynpt)
  5.     (xdrx_entity_move e (trans base 1 0) dynpt)
  6.     (setq base (trans dynpt 0 1))
  7.   )
  8.   (defun _callback2 (dynpt)
  9.     (xdrx_entity_move ents (trans base 1 0) dynpt)
  10.     (setq base (trans dynpt 0 1))
  11.   )
  12.   (defun myerr (msg)
  13.     (princ (strcat "\n" msg))
  14.     (xdrx_end)
  15.     (if oper
  16.       (progn (if ent
  17.                (setq e ent)
  18.              )
  19.              (xdrx_entity_delete e)
  20.       )
  21.     )
  22.     (setq *error* olderr)
  23.     (princ)
  24.   )
  25.   (defun _cale ()
  26.     (setq oper 1
  27.           e    (xdrx_entity_copy e)
  28.           e    (ssname e 0)
  29.           txt2 (strcat prev
  30.                        (xdrx_string_replace
  31.                          (xdrx_string_format
  32.                            (setq lpj (strcat "%" (itoa #xd_var_global_bits) "d"))
  33.                            (setq ljb (+ (atoi txt1) 1 i))
  34.                          )
  35.                          " "
  36.                          "0"
  37.                        )
  38.                        next
  39.                )
  40.     )
  41.     (setq typ (car (xdrx_object_classname e)))
  42.     (cond ((= typ "INSERT")
  43.            (setq e1 (xdrx_getpropertyvalue e "AttributeEntities"))
  44.            (xdrx_setpropertyvalue (car e1) "textstring" txt2)
  45.           )
  46.           (t (xdrx_setpropertyvalue e "textstring" txt2))
  47.     )
  48.     (setq i (1+ i))
  49.     e
  50.   )
  51.   (defun _cale1 ()
  52.     (setq oper 1
  53.           ents (xdrx_entity_copy ents)
  54.           ents (xdrx_pickset->ents ents)
  55.           ents (xd::pickset:tablesort ents 0 1 '< '<)
  56.           ents (xd::list:flat ents)
  57.     )
  58.     (mapcar
  59.       '(lambda (x)
  60.          (setq txt2 (strcat prev
  61.                             (xdrx_string_replace
  62.                               (xdrx_string_format1
  63.                                 (strcat "%" (itoa #xd_var_global_bits) "d")
  64.                                 (itoa (+ (atoi txt1) 1 i))
  65.                               )
  66.                               " "
  67.                               "0"
  68.                             )
  69.                             next
  70.                     )
  71.          )
  72.          (setq typ (car (xdrx_object_classname x)))
  73.          (cond ((= typ "INSERT")
  74.                 (setq e1 (xdrx_getpropertyvalue x "AttributeEntities"))
  75.                 (xdrx_setpropertyvalue (car e1) "textstring" txt2)
  76.                )
  77.                (t (xdrx_setpropertyvalue x "textstring" txt2))
  78.          )
  79.          (setq i (1+ i))
  80.        )
  81.       ents
  82.     )
  83.     ents
  84.   )
  85.   (defun _check (e p / i next pos posl prev tf txt txt1 x)
  86.     (setq typ (xdrx_object_classname e))
  87.     (if (= (car typ) "INSERT")
  88.       (setq e (car (xdrx_getpropertyvalue e "AttributeEntities")))
  89.     )
  90.     (if (and (setq txt (xd::text:indexatPoint e p))
  91.              (setq pos (cadr txt)
  92.                    txt (car txt)
  93.              )
  94.              (setq txt1 (xdrx_string_regexps "[0-9]+" txt))
  95.              (setq posl (xdrx_string_regexpv)
  96.                    i    -1
  97.              )
  98.              (vl-some '(lambda (x)
  99.                          (setq i (1+ i))
  100.                          (if (setq tf (<= (car x) pos (cadr x)))
  101.                            (setq pos x)
  102.                          )
  103.                        )
  104.                       posl
  105.              )
  106.         )
  107.       (progn (setq prev (xdrx_string_mid txt 0 (car pos))
  108.                    next (xdrx_string_mid txt (last pos))
  109.              )
  110.              (list prev (nth i txt1) next)
  111.       )
  112.     )
  113.   )
  114.   (defun _check1 (e / typ txt next txt1)
  115.     (setq typ (xdrx_object_classname e))
  116.     (if (= (car typ) "INSERT")
  117.       (setq e (car (xdrx_getpropertyvalue e "AttributeEntities")))
  118.     )
  119.     (if (and (setq txt  (xdrx_getpropertyvalue e "textstring")
  120.                    next ""
  121.                    txt1 (car (xdrx_string_regexps "[0-9]+" txt))
  122.              )
  123.         )
  124.       (progn (setq prev (car (xdrx_string_regexps "[^0-9]+" txt)))
  125.              (list (if prev
  126.                      prev
  127.                      ""
  128.                    )
  129.                    txt1
  130.                    next
  131.              )
  132.       )
  133.     )
  134.   )
  135.   (if (and (xdrx_initget "M")
  136.            (setq e (xdrx_entsel
  137.                      "\nSelect a String or attribute with Numbers[Multiple Selection(M)]<Exit>"
  138.                      '((-4 . "<or")
  139.                        (-4 . "<and")
  140.                        (0 . "insert")
  141.                        (66 . 1)
  142.                        (-4 . "and>")
  143.                        (0 . "*text")
  144.                        (-4 . "or>")
  145.                       )
  146.                    )
  147.            )
  148.       )
  149.     (progn
  150.       (xdrx_begin)
  151.       (xdrx_sysvar_push '("osmode" 33))
  152.       (setq olderr *error*)
  153.       (setq *error* myerr)
  154.       (cond ((and (= (type e) 'STR) (= (strcase e) "M"))
  155.              (if (and (xdrx_initssget
  156.                         "\nSelect Multiple Text with Numbers<Exit>:"
  157.                       )
  158.                       (setq ss (xdrx_ssget '((1 . "*#"))))
  159.                  )
  160.                (progn (setq ents (xdrx_pickset->ents ss)
  161.                             lxd ents
  162.                              txts
  163.                             (xdrx_entity_getproperty ss "textstring")
  164.                              maxv
  165.                             (apply
  166.                               'max
  167.                               (mapcar
  168.                                 '(lambda (x)
  169.                                    (atoi (car (xdrx_string_regexps "[0-9]+" x)))
  170.                                  )
  171.                                 txts
  172.                               )
  173.                             )
  174.                              ss1
  175.                             (xd::pickset:getsub
  176.                               ss
  177.                               (list (cons 1 (strcat "*" (itoa maxv))))
  178.                             )
  179.                              e
  180.                             (ssname ss1 0)
  181.                       )
  182.                       (setq info (_check1 e))
  183.                )
  184.              )
  185.             )
  186.             (t
  187.              (setq p (trans (cadr e) 1 0)
  188.                    e (car e)
  189.              )
  190.              (setq info (_check e p))
  191.             )
  192.       )
  193.       (if info
  194.         (progn
  195.           (setq prev (car info)
  196.                 txt1 (cadr info)
  197.                 llxd txt1
  198.                 #xd_var_global_bits
  199.                  (strlen txt1)
  200.                 dxxy #xd_var_global_bits
  201.                 next (last info)
  202.           )
  203.           (initget 128 "A")
  204.           (xdrx_initget 128 "A")
  205.  
  206.           (if (setq base (getpoint "\nBasepoint[array(A)]<exit>:"))
  207.             (progn
  208.               (cond
  209.                 ((= base "A")
  210.                  (if (not #xd_var_global_gap_factor)
  211.                    (setq #xd_var_global_gap_factor 3)
  212.                  )
  213.                  (if (setq val (getreal (xdrx_prompt
  214.                                           "\nEnter Spacing<"
  215.                                           #xd_var_global_gap_factor
  216.                                           ">:"
  217.                                           t
  218.                                         )
  219.                                )
  220.                      )
  221.                    (setq #xd_var_global_gap_factor val)
  222.                  )
  223.                  (if (not #xd_var_global_array_num)
  224.                    (setq #xd_var_global_array_num 2)
  225.                  )
  226.                  (if
  227.                    (setq p1 (getpoint
  228.                               "\nFirst Point in Direction<select curve as path>:"
  229.                             )
  230.                    )
  231.                     (progn
  232.                       (if (setq p2 (getpoint p1 "\nSecond Point in Direction <exit>:"))
  233.                         (progn (setq #xd_var_global_array_num
  234.                                       (1-
  235.                                         (fix
  236.                                           (/
  237.                                             (distance p1
  238.                                                       p2
  239.                                             )
  240.                                             #xd_var_global_gap_factor
  241.                                           )
  242.                                         )
  243.                                       )
  244.                                )
  245.                                (if (setq
  246.                                      val (getint (xdrx_prompt
  247.                                                    "\nEnter quantity<"
  248.                                                    #xd_var_global_array_num
  249.                                                    ">:"
  250.                                                    t
  251.                                                  )
  252.                                          )
  253.                                    )
  254.                                  (setq #xd_var_global_array_num val)
  255.                                )
  256.                                (setq i 0)
  257.                                (if (not ents)
  258.                                  (setq ent (_cale))
  259.                                  (progn (setq ent (_cale1)))
  260.                                )
  261.                                (setq v   (mapcar '- p2 p1)
  262.                                      dis (xdrx_vector_length v)
  263.                                      v   (trans v 1 0 t)
  264.                                      v   (xdrx_vector_normalize v)
  265.                                )
  266.                                (repeat #xd_var_global_array_num
  267.                                  (xdrx_entity_move
  268.                                    ent
  269.                                    (setq base (xd::geom:get9pt ent 5))
  270.                                    (mapcar '+
  271.                                            base
  272.                                            (xdrx_vector_product
  273.                                              v
  274.                                              #xd_var_global_gap_factor
  275.                                            )
  276.                                    )
  277.                                  )
  278.                                  (if (not ents)
  279.                                    (setq ent (_cale))
  280.                                    (progn (setq ent (_cale1)))
  281.                                  )
  282.                                )
  283.                                (xdrx_entity_delete ent)
  284.                         )
  285.                       )
  286.                     )
  287.                     (progn
  288.                       (if (setq crv
  289.                                  (car (xdrx_entsel
  290.                                         "\nPick Path Curve<Exit>:"
  291.                                         '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))
  292.                                       )
  293.                                  )
  294.                           )
  295.                         (progn (setq v1  (xdrx_entity_getecs e)
  296.                                      v1  (cadr v1)
  297.                                      pnt (xdrx_curve_getclosestpoint
  298.                                            crv
  299.                                            (xdrx_getpropertyvalue e "position")
  300.                                          )
  301.                                      v2  (xdrx_curve_getfirstderiv crv pnt)
  302.                                )
  303.                                (if (xdrx_vector_iscodirectional v1 v2)
  304.                                  (setq pts (xdrx_curve_getpointsatdist
  305.                                              crv
  306.                                              pnt
  307.                                              #xd_var_global_gap_factor
  308.                                            )
  309.                                  )
  310.                                  (setq pts (xdrx_curve_getpointsatdist
  311.                                              crv
  312.                                              pnt
  313.                                              (- #xd_var_global_gap_factor)
  314.                                            )
  315.                                  )
  316.                                )
  317.                                (if (setq
  318.                                      val (getint (xdrx_prompt
  319.                                                    "\nEnter quantity (maximum"
  320.                                                    (1- (length pts))
  321.                                                    ")<"
  322.                                                    #xd_var_global_array_num
  323.                                                    ">:"
  324.                                                    t
  325.                                                  )
  326.                                          )
  327.                                    )
  328.                                  (setq #xd_var_global_array_num val)
  329.                                )
  330.                                (setq i 0)
  331.                                (if (not ents)
  332.                                  (setq ent (_cale))
  333.                                  (progn (setq ent (_cale1)))
  334.                                )
  335.                                (while (and (< i (length pts))
  336.                                            (< i #xd_var_global_array_num)
  337.                                       )
  338.                                  (setq pt (nth i pts)
  339.                                        v1 (xdrx_entity_getecs e)
  340.                                        v1 (cadr v1)
  341.                                  )
  342.                                  (setq pnt (xdrx_curve_getclosestpoint
  343.                                              crv
  344.                                              (setq sp1 (xdrx_getpropertyvalue
  345.                                                          e
  346.                                                          "9pt"
  347.                                                          5
  348.                                                        )
  349.                                              )
  350.                                            )
  351.                                  )
  352.                                  (setq sp1 pnt
  353.                                        sp2 (mapcar '+ sp1 v1)
  354.                                        dp1 pt
  355.                                        dp2 (mapcar
  356.                                              '+
  357.                                              dp1
  358.                                              (xdrx_curve_getfirstderiv crv pt)
  359.                                            )
  360.                                  )
  361.                                  (xdrx_entity_align e sp1 sp2 dp1 dp2)
  362.                                  (if (not ents)
  363.                                    (setq ent (_cale))
  364.                                    (progn (setq ent (_cale1)))
  365.                                  )
  366.                                )
  367.                                (xdrx_entity_delete ent)
  368.                         )
  369.                       )
  370.                     )
  371.                  )
  372.                 )
  373.                 (t
  374.                  (setq i 0)
  375.                  (if (not ents)
  376.                    (progn (_cale)
  377.                           (while (setq pt (xd::drag:gmove
  378.                                             base "\nNext Point<Exit>:" -7 nil t "_callback1")
  379.                                  )
  380.                             (_cale)
  381.                           )
  382.                           (xdrx_entity_delete e)
  383.                    )
  384.                    (progn (_cale1)
  385.                           (while (setq pt (xd::drag:gmove
  386.                                             base "\nNext Point<Exit>:" -7 nil t "_callback2")
  387.                                  )
  388.                             (_cale1)
  389.                           )
  390.                           (xdrx_entity_delete ents)
  391.                    )
  392.                  )
  393.                 )
  394.               )
  395.             )
  396.           )
  397.         )
  398.         (progn (if (and (not ents) e)
  399.                  (xdrx_prompt "\nNo Number Selected.")
  400.                )
  401.         )
  402.       )
  403.       (xdrx_sysvar_pop)
  404.       (xdrx_end)
  405.       (setq *error* olderr)
  406.     )
  407.   )
  408.   (princ)
  409. )
« Last Edit: December 03, 2023, 12:23:18 AM 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

Hugo

  • Bull Frog
  • Posts: 435
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #1 on: December 02, 2023, 01:39:19 PM »
get an error in ZWCAD
Thanks

xdcad

  • Swamp Rat
  • Posts: 527
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #2 on: December 02, 2023, 04:10:22 PM »
get an error in ZWCAD
Thanks

You haven't loaded it completely yet. xd-lisp-liv.vls hasn't loaded yet. Go to the post where you asked the question. I've attached the debugged file. You can overwrite it in the installation directory and give it a try.

==========

The ZRX you are using is version 11.18, which is a bit old.
In the attachment, I give you the latest ZRX. You can use this to cover it. If there is a bug under ZRX, please post it and I will pay attention to it.
ZRX is not planned to be provided in the installation package because it has just been ported.
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

hcbn1997

  • Newt
  • Posts: 31
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #3 on: December 03, 2023, 12:48:18 AM »
Great lisp, it's what I was looking for but when the app loads the lisp I can't use it
error is as follows

hcbn1997

  • Newt
  • Posts: 31
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #4 on: December 03, 2023, 01:37:39 AM »
After installing the XDRX API library, I was able to run Lisp, but a problem arose when using it: the prefix and suffix were inconsistent.
For example, if I use the command with the text string 2CG39-1, sometimes the result is 2CG39-2, and sometimes the result is 2CG40-1.
I want it to be 2CG39-01 then 2CG39-02

Hugo

  • Bull Frog
  • Posts: 435
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #5 on: December 03, 2023, 02:27:28 AM »
Thanks, everything works now
Thank you thank you

xdcad

  • Swamp Rat
  • Posts: 527
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #6 on: December 03, 2023, 03:47:45 AM »
After installing the XDRX API library, I was able to run Lisp, but a problem arose when using it: the prefix and suffix were inconsistent.
For example, if I use the command with the text string 2CG39-1, sometimes the result is 2CG39-2, and sometimes the result is 2CG40-1.
I want it to be 2CG39-01 then 2CG39-02

Has the mouse clicked on 40? In this program, whichever number the mouse clicks on will be changed. You can enlarge the picture so that you can easily select the one you need to change.
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

Hugo

  • Bull Frog
  • Posts: 435
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #7 on: December 03, 2023, 04:24:57 AM »
Unfortunately, this doesn't work with dynamic blocks.

xdcad

  • Swamp Rat
  • Posts: 527
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #8 on: December 03, 2023, 06:29:21 AM »
Unfortunately, this doesn't work with dynamic blocks.


Only supports text and attribute text
If BLOCK is supported, where do you want to copy the text?
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

Hugo

  • Bull Frog
  • Posts: 435
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #9 on: December 03, 2023, 07:05:48 AM »
I don't know if you have tested this, but Lisp works with a normal block with ATT.
« Last Edit: December 03, 2023, 07:10:30 AM by Hugo »

xdcad

  • Swamp Rat
  • Posts: 527
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #10 on: December 03, 2023, 07:13:29 AM »
I don't know if you have tested this, but Lisp works with a normal block with ATT.

Please upload the DWG
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

Hugo

  • Bull Frog
  • Posts: 435
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #11 on: December 03, 2023, 07:21:59 AM »
HIER DIE DWG

hcbn1997

  • Newt
  • Posts: 31
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #12 on: December 04, 2023, 12:28:42 AM »
Unfortunately, this doesn't work with dynamic blocks.
IT turns out to click on the number (I didn't know this) thank you very much.
But if you could edit the array, could the algorithm change a bit? Array will use Distance to pick 2 points, then enter the number of times you want to copy.
Thank you!

xdcad

  • Swamp Rat
  • Posts: 527
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #13 on: December 04, 2023, 04:42:01 AM »
Unfortunately, this doesn't work with dynamic blocks.
IT turns out to click on the number (I didn't know this) thank you very much.
But if you could edit the array, could the algorithm change a bit? Array will use Distance to pick 2 points, then enter the number of times you want to copy.
Thank you!

I got you,
Now two points are selected to determine the direction of the array, and the distance depends on user input.

And if you want to use two points to determine the direction and the distance of the array at the same time, isn't it sometimes inefficient?

The main purpose is to reduce user interaction as much as possible
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

Hugo

  • Bull Frog
  • Posts: 435
Re: [XDrX-PlugIn(21)] Text (Attrib) Copy+1
« Reply #14 on: December 04, 2023, 05:24:02 AM »
This now also works with dynamic blocks
Thank you 1000x