Author Topic: Autonumber selected items lisp?  (Read 4401 times)

0 Members and 1 Guest are viewing this topic.

SVirtanen

  • Mosquito
  • Posts: 7
Autonumber selected items lisp?
« on: October 05, 2020, 10:07:39 AM »
The BlockC command shown here works just awesome for me - at least on Autocad. But our company is using Brickscad and .VLX lisps don't work with that..
Is there any alternative lisp to incrementally number a selection set? Have tried to search for ages but haven't found anything similar..

This is the original lisp:
https://knowledge.autodesk.com/support/autocad/learn-explore/caas/screencast/Main/Details/f36def8a-acd3-4dfa-9c83-9211db47ef42.html

« Last Edit: October 05, 2020, 01:37:12 PM by SVirtanen »

nini007

  • Newt
  • Posts: 58
Re: Autonumber selected items lisp?
« Reply #1 on: October 05, 2020, 02:32:40 PM »
Hi,
You can find some pretty good stuff from Giles Chanteau.

"Increment" by Giles Chanteau on the Autodesk App Store site:
https://apps.autodesk.com/ACD/fr/Detail/Index?id=8051485828049059617&appLang=fr&os=Win32_64

or the version read "Increment" on this link:
http://gilecad.azurewebsites.net/Lisp.aspx

or even Lee Mac's lisp
http://www.lee-mac.com/incrementalarray.html
http://www.lee-mac.com/numinc.html

best regard

SVirtanen

  • Mosquito
  • Posts: 7
Re: Autonumber selected items lisp?
« Reply #2 on: October 06, 2020, 03:05:42 AM »
Thank you for your reply. Sadly none of these really work. I want't to first select all the blocks and then renumber incrementally. These programs you presented only allow to renumber by individually selecting a block. The first one I couldn't test because it cannot be installed on Brickscad.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #3 on: October 06, 2020, 09:06:47 AM »

SVirtanen

  • Mosquito
  • Posts: 7
Re: Autonumber selected items lisp?
« Reply #4 on: October 06, 2020, 09:26:36 AM »
Yes I have, but still not suitable for my need. While awesome the autolabelattributes by leemac affects all the blocks in a drawing. I need to number just a selection set.  :-(

Usually in a drawing I have multiple "sets" of blocks that need to have their own running numbers. 

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #5 on: October 06, 2020, 03:24:23 PM »
The code below should work.

Note that BricsCAD has an issue with the order of Fence selection sets:
https://forum.bricsys.com/discussion/36160/order-of-objects-selected-by-ssget-f

Code - Auto/Visual Lisp: [Select]
  1. (defun KGA_Conv_Pickset_To_ObjectList (ss / i ret)
  2.   (if ss
  3.     (repeat (setq i (sslength ss))
  4.       (setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret))
  5.     )
  6.   )
  7. )
  8.  
  9. (defun c:NumSet ( / num pre ss suf)
  10.  
  11.   (if (not *NumSet_num*) (setq *NumSet_num* 1))
  12.   (if (not *NumSet_pre*) (setq *NumSet_pre* ""))
  13.   (if (not *NumSet_suf*) (setq *NumSet_suf* ""))
  14.  
  15.   (if
  16.     (and
  17.       (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  18.       (or
  19.         (and
  20.           (setq num (getint (strcat "\nStart number: <" (itoa *NumSet_num*) ">: ")))
  21.           (setq *NumSet_num* num)
  22.         )
  23.         T
  24.       )
  25.       (setq pre (getstring T (strcat "\nPrefix (\".\" for none): <" *NumSet_pre* ">: ")))
  26.       (or
  27.         (= "" pre)
  28.         (and (= "." pre) (setq *NumSet_pre* ""))
  29.         (setq *NumSet_pre* pre)
  30.       )
  31.       (setq suf (getstring T (strcat "\nSuffix (\".\" for none): <" *NumSet_suf* ">: ")))
  32.       (or
  33.         (= "" suf)
  34.         (and (= "." suf) (setq *NumSet_suf* ""))
  35.         (setq *NumSet_suf* suf)
  36.       )
  37.     )
  38.     (foreach obj (KGA_Conv_Pickset_To_ObjectList ss)
  39.         (car (vlax-invoke obj 'getattributes))
  40.         (strcat *NumSet_pre* (itoa *NumSet_num*) *NumSet_suf*)
  41.       )
  42.       (setq *NumSet_num* (1+ *NumSet_num*))
  43.     )
  44.   )
  45.   (princ)
  46. )

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Autonumber selected items lisp?
« Reply #6 on: October 06, 2020, 08:17:45 PM »
Interesting comment in your link about hours of work to get fence correct order. But its easy to sort on distance and use say handle (123.45 "12CF34") using get point at dist. If using say insert point. Used it many times.
A man who never made a mistake never made anything

SVirtanen

  • Mosquito
  • Posts: 7
Re: Autonumber selected items lisp?
« Reply #7 on: October 07, 2020, 01:40:23 AM »
The code below should work.

Thank you so much! You made my day.  :-) I hope your code also helps others in need.

The ability to change the attribute where to insert would be awesome. Would this be hard to implement?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #8 on: October 07, 2020, 03:06:49 AM »
But its easy to sort on distance
The task is more complex than that. You would need to write a vlax-curve-getDistAtPoint type function for fence selections. It is doable but not easy.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #9 on: October 07, 2020, 04:19:16 AM »
The ability to change the attribute where to insert would be awesome.
Updated code:
Code - Auto/Visual Lisp: [Select]
  1. (defun KGA_Conv_Pickset_To_ObjectList (ss / i ret)
  2.   (if ss
  3.     (repeat (setq i (sslength ss))
  4.       (setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret))
  5.     )
  6.   )
  7. )
  8.  
  9. (defun KGA_Sys_ObjectOwner (obj)
  10. )
  11.  
  12. (defun NumSet_InputBlockAndTag (msg / enm obj)
  13.   (if
  14.     (and
  15.       (setq enm (car (nentsel msg)))
  16.       (setq obj (vlax-ename->vla-object enm))
  17.       (= "AcDbAttribute" (vla-get-objectname obj))
  18.     )
  19.     (progn
  20.       (setq *NumSet_tag* (strcase (vla-get-tagstring obj)))
  21.       (KGA_Sys_ObjectOwner obj)
  22.     )
  23.   )
  24. )
  25.  
  26. (defun NumSet_InputTag ()
  27.   (if (not *NumSet_tag*) (setq *NumSet_tag* "*"))
  28.   (NumSet_InputBlockAndTag (strcat "\nSelect attribute for correct tag: <" *NumSet_tag* ">: "))
  29.   T ; Alway return T.
  30. )
  31.  
  32. (defun NumSet_InputNumber ( / num pre suf)
  33.   (if (not *NumSet_num*) (setq *NumSet_num* 1))
  34.   (if (not *NumSet_pre*) (setq *NumSet_pre* ""))
  35.   (if (not *NumSet_suf*) (setq *NumSet_suf* ""))
  36.   (if (setq num (getint (strcat "\nStart number: <" (itoa *NumSet_num*) ">: ")))
  37.     (setq *NumSet_num* num)
  38.   )
  39.   (setq pre (getstring T (strcat "\nPrefix (\".\" for none): <" *NumSet_pre* ">: ")))
  40.   (cond
  41.     ((= "." pre)
  42.       (setq *NumSet_pre* "")
  43.     )
  44.     ((/= "" pre)
  45.       (setq *NumSet_pre* pre)
  46.     )
  47.   )
  48.   (setq suf (getstring T (strcat "\nSuffix (\".\" for none): <" *NumSet_suf* ">: ")))
  49.   (cond
  50.     ((= "." suf)
  51.       (setq *NumSet_suf* "")
  52.     )
  53.     ((/= "" suf)
  54.       (setq *NumSet_suf* suf)
  55.     )
  56.   )
  57.   T ; Alway return T.
  58. )
  59.  
  60. ; Returns T if successful.
  61. (defun NumSet_UpdateText (blk tag str)
  62.     '(lambda (att)
  63.       (if (wcmatch (strcase (vla-get-tagstring att)) tag)
  64.         (progn
  65.           (vla-put-textstring att str)
  66.           T
  67.         )
  68.       )
  69.     )
  70.     (vlax-invoke blk 'getattributes)
  71.   )
  72. )
  73.  
  74. (defun c:NumSet ( / doc ss)
  75.   (if
  76.     (and
  77.       (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  78.       (NumSet_InputTag)
  79.       (NumSet_InputNumber)
  80.     )
  81.     (foreach obj (KGA_Conv_Pickset_To_ObjectList ss)
  82.       (if (NumSet_UpdateText obj *NumSet_tag* (strcat *NumSet_pre* (itoa *NumSet_num*) *NumSet_suf*))
  83.         (setq *NumSet_num* (1+ *NumSet_num*)) ; Only increase *NumSet_num* if NumSet_UpdateText is successful.
  84.       )
  85.     )
  86.   )
  87.   (princ)
  88. )
  89.  
  90. (defun c:NumSetIns ( / *error* doc new obj pt)
  91.  
  92.   (defun *error* (msg)
  93.     (vla-endundomark doc)
  94.     (princ)
  95.   )
  96.  
  97.   (if
  98.     (and
  99.       (setq obj (NumSet_InputBlockAndTag "\nSelect block to copy (click on attribute to change): "))
  100.       (NumSet_InputNumber)
  101.     )
  102.     (progn
  103.       (while (setq pt (getpoint "\nInsertion point (or Enter to stop): "))
  104.         (setq new (vla-copy obj))
  105.         (vla-put-insertionpoint new (vlax-3d-point (trans pt 1 0)))
  106.         (NumSet_UpdateText new *NumSet_tag* (strcat *NumSet_pre* (itoa *NumSet_num*) *NumSet_suf*))
  107.         (setq *NumSet_num* (1+ *NumSet_num*))
  108.       )
  109.     )
  110.   )
  111.   (princ)
  112. )

EDIT 20201009: Improved c:NumSet (Only increase *NumSet_num* if NumSet_UpdateText is successful).
« Last Edit: October 09, 2020, 09:57:27 AM by roy_043 »

SVirtanen

  • Mosquito
  • Posts: 7
Re: Autonumber selected items lisp?
« Reply #10 on: October 07, 2020, 04:41:48 AM »
Sorry, I meant the ability to change the attribute that is effected.  I have a block with 3 attributes. I want to change the 3rd attribute, not the 1:st.
Big thanks anyway!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #11 on: October 07, 2020, 11:37:51 AM »
I have updated the code in my previous post.

SVirtanen

  • Mosquito
  • Posts: 7
Re: Autonumber selected items lisp?
« Reply #12 on: October 09, 2020, 08:52:56 AM »
The biggest thanks to you, works great! This really is going to change the way I work. Such a big time saver! :-)

I am just curious, about the order that it is numbering: It is the order when the blovk is greated in the database not the order of selection, right?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #13 on: October 09, 2020, 09:40:28 AM »
I have not fully analyzed the BricsCAD fence bug, but the order of the selection set determines the numbering. You can verify this by using various combinations of single picks and selection windows when you use the the c:NumSet function.

For a selection window it is the draworder that determines the order of the selection set, but when not changed by the user the draworder is the same as the database order (the last or top element is selected first).
« Last Edit: October 10, 2020, 11:40:11 AM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Autonumber selected items lisp?
« Reply #14 on: October 09, 2020, 09:56:41 AM »