sadhu Posted May 14, 2010 Posted May 14, 2010 I often have to number and re-number lines sequentially. Top to bottom - column by column. See attached file. The numbers are text or mtext. Can someone suggest a way to write a lisp so that I just select the texts (numbers) that I want to re-number and it gets numbered progressively 1-2-3.... I'm stuck because these numbers are in columns and I want to do it in a single selection. test.dwg Quote
asos2000 Posted May 15, 2010 Posted May 15, 2010 sadhu - Save the attached dwg in lower version - Give this a try Express menu > Text > automatic text numbering - Here Quote
alanjt Posted May 15, 2010 Posted May 15, 2010 Lee's NumInc is probably your best option. I linked to it again, asos doubled up on the http in his. Here's one I did couple months ago (just playing around with sorting). Like I said, Lee's will probably suite your needs perfectly. I know I use it. :wink: Quote
asos2000 Posted May 16, 2010 Posted May 16, 2010 alanjt yours is very useful for mass work I like this one Quote
alanjt Posted May 16, 2010 Posted May 16, 2010 alanjtyours is very useful for mass work I like this one It's clunky, so be careful. It was just a late night of playing. Quote
sadhu Posted May 17, 2010 Author Posted May 17, 2010 alanjt : I tried your lisp. What I need done is way simpler than what your code does. So I'm looking into it to adapt to my needs. The texts that I need to renumber aren't in a perfect straight line (column) and they all have a prefix ('). like so : '12 '12 'sa '13 '1 'gh '23 '12 '45 '23 Quote
sadhu Posted May 18, 2010 Author Posted May 18, 2010 I'm stuck with - how to sort a selection set of text (single column top-bottom order) Need some help:oops: Quote
alanjt Posted May 18, 2010 Posted May 18, 2010 There are examples in the link I posted. Here's an example of taking a selection set of text and sorting by the Y value, top to bottom... (if (setq ss (ssget '((0 . "TEXT")))) (vl-sort ((lambda (i / lst) (while (setq e (ssname ss (setq i (1+ i)))) (setq lst (cons e lst)) ) ) -1 ) (function (lambda (a b) (> (caddr (assoc 10 (entget a))) (caddr (assoc 10 (entget b)))))) ) ) Quote
sadhu Posted May 24, 2010 Author Posted May 24, 2010 Alanjt : I used your last posted code . The list gets ordered according to insertion order and not according to y-axis - top to bottom. Is it because of "caddr" that returns the third element ? What am I doing wrong ? What I need to do is renumber a single column of text that is on the drawing. (defun C:sorty() (if (setq ss (ssget '((0 . "TEXT")))) (vl-sort ((lambda (i / lst) (while (setq e (ssname ss (setq i (1+ i)))) (setq lst (cons e lst)) ) ) -1 ) (function (lambda (a b) (> (caddr (assoc 10 (entget a))) (caddr (assoc 10 (entget b)))))) ) ) ;************ (and ((lambda (i) (while (setq e (ssname ss (setq i (1+ i)))) (setq ent (entget e)) (entmod (subst (cons 1 (strcat "'" (rtos (+ i 1) 2 0))) ;new item (assoc 1 ent) ; old item ent ;list ) ) ) ) -1 ) ) (princ) ); DEFUN Quote
alanjt Posted May 24, 2010 Posted May 24, 2010 You're not applying the sorted list (code I provided). After you sort the selection set, you are stepping through it again (your code). (defun c:SortY (/ ss lst ent) ((lambda (n) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) (foreach x (vl-sort ((lambda (i) (while (setq e (ssname ss (setq i (1+ i)))) (setq lst (cons e lst)) ) ) -1 ) (function (lambda (a b) (> (caddr (assoc 10 (entget a))) (caddr (assoc 10 (entget b))))) ) ) (setq ent (entget x)) (entmod (subst (cons 1 (strcat "'" (itoa (setq n (1+ n))))) (assoc 1 ent) ent)) ) ) ) 0 ) (princ) ) Quote
alanjt Posted May 24, 2010 Posted May 24, 2010 Thank you very much. That was great. You're welcome, but do you understand the code? Quote
sadhu Posted May 24, 2010 Author Posted May 24, 2010 This is how I'm using it now. Changed only the selection criteria. Thanks again. (defun c:SortY (/ ss lst ent) ((lambda (n) (if (setq ss (ssget [color=Red](list (cons 0 "TEXT,MTEXT") (cons 1 "'*"))))[/color] (foreach x (vl-sort ((lambda (i) (while (setq e (ssname ss (setq i (1+ i)))) (setq lst (cons e lst)) ) ) -1 ) (function (lambda (a b) (> (caddr (assoc 10 (entget a))) (caddr (assoc 10 (entget b))))) ) ) (setq ent (entget x)) (entmod (subst (cons 1 (strcat "'" (itoa (setq n (1+ n))))) (assoc 1 ent) ent)) ) ) ) 0 ) (princ) ) Quote
alanjt Posted May 24, 2010 Posted May 24, 2010 But do you understand how it works? Also, you shouldn't have removed the "_:L" (filters locked layers) from the ssget, as the routine will fail if stepping through a text object on a locked layer. use: (setq ss (ssget "_:L" (list (cons 0 "TEXT,MTEXT") (cons 1 "'*")))) Quote
sadhu Posted May 24, 2010 Author Posted May 24, 2010 I'm scared to say that I understand but now that you have written it - hmmm - lets say - I'm going through it. I had started out like this : - select - order - replace (entmod) So I separated the code in to parts. Evidently your code does this work fine. I've corrected the code as you suggested and thank you for the explanation too. I thought L: was L Last visible object added to the database. (setq ss (ssget "_:L" (list (cons 0 "TEXT,MTEXT") (cons 1 "'*")))) I'm trying to get the hang of how lamda(n) and lamda(i) work . I have used the animate feature in debug mode. Thanks. Quote
alanjt Posted May 24, 2010 Posted May 24, 2010 SSGet info: SSGET the underscore (_) is needed with W, F, WP, :S but not with X, A, C, CP, I, L, P, :E ... (ssget '(2 2)) Create a selection set of the object passing through (2,2): +. The undocumented “+.” mode forces (ssget) to remain in “point” mode, similar to setting PickAuto to 0.... the "+." puts (ssget) into "point" mode. It helps the ":S" single-mode act just like (entsel) by avoiding implied selection windows. A All like "X" but filters frozen out Selects all objects on thawed layers. B Box Selects all objects inside or crossing a rectangle specified by two points. If the rectangle's points are specified from right to left, Box is equivalent to Crossing. Otherwise, Box is equivalent to Window. C Crossing Simular to Window selection Selects objects within and crossing an area defined by two points. A crossing selection is displayed as dashed or otherwise highlighted to differentiate it from window selection. Specifying the corners from right to left creates a crossing selection. *** (Specifying the corners from left to right creates a window selection.) (ssget "_C" '(0 0) '(1 1)) Caution: the area must be on the screen for this to work properly - CAB CP Crossing Polygon Selects objects within and crossing a polygon defined by specifying points. The polygon can be any shape but cannot cross or touch itself. AutoCAD draws the last segment of the polygon so that it is closed at all times. CPolygon is not affected by the PICKADD system variable. (ssget "_CP" '((1 1)(3 1)(5 2)(2 4))) Example with filters (ssget "_CP" '(Point list) '(Filter List)) (setq ss (ssget "_CP" '((0 0)(10 0)(10 10)(0 10)) '((0 . "INSERT") (66 . 1)) )) Caution: the area must be on the screen for this to work properly - CAB (vl-cmdf "._zoom" "_E") ; Extents Duplicates OK, else duplicates are ignored :E Everything in aperture Everything within the cursor's object selection pickbox. F Fence Selects all objects crossing a selection fence. The Fence method is similar to CPolygon except that AutoCAD does not close the fence, and a fence can cross itself. Fence is not affected by the PICKADD system variable. G Groups Selects all objects within a specified group. I Implied Implied selection (objects selected while PICKFIRST is in effect). L Last Last visible object added to the database :L Rejects locked layers M Multiple Specifies multiple points without highlighting the objects, thus speeding up the selection process for complex objects. The Multiple method also selects two intersecting objects if the intersection point is specified twice. :N Nested Call ssnamex for additional information on container blocks and transformation matrices for any entities selected during the ssget operation. This additional information is available only for entities selected via graphical selection methods such as Window, Crossing, and point picks. Unlike the other object selection methods, :N may return multiple entities with the same entity name in the selection set. For example, if the user selects a subentity of a complex entity such as a BlockReference, PolygonMesh, or old style polyline, ssget looks at the subentity that is selected when determining if it has already been selected. However, ssget actually adds the main entity (BlockReference, PolygonMesh, etc.) to the selection set. The result could be multiple entries with the same entity name in the selection set (each will have different subentity information for ssnamex to report). P Previous Selects the most recent selection set. The Previous selection set is cleared by operations that delete objects from the drawing. AutoCAD keeps track of whether each selection set was specified in model space or paper space. The Previous selection set is ignored if you switch spaces. Rejects Viewport :R Allows entities in a long transaction to be selected. :S Force single object selection only :U Enables subentity selection - 2006+ Cannot be combined with the duplicate (":D") or nested (":N") selection modes. In this mode, top-level entities are selected by default, but the user can attempt to select subentities by pressing the CTRL key while making the selection. This option is supported only with interactive selections, such as window, crossing, and polygon. It is not supported for all, filtered, or group selections. :V Forces subentity selection - 2006+ Treats all interactive, graphic selections performed by the user as subentity selections. The returned selection set contains subentities only. This option cannot be combined with the duplicate (":D") or nested (":N") selection modes. This option is supported only with interactive selections, such as window and crossing. It is not supported for all, filtered, or group selections. W Window Selects all objects completely inside a rectangle defined by two points. Specifying the corners from left to right creates a window selection. (Specifying the corners from right to left creates a crossing selection.) WP Window Polygon Selects objects completely inside a polygon defined by points. The polygon can be any shape but cannot cross or touch itself. AutoCAD draws the last segment of the polygon so that it is closed at all times. WPolygon is not affected by the PICKADD system variable. X Extended search (search whole database) Entire database. If you specify the X selection method and do not provide a filter-list, ssget selects all entities in the database, including entities on layers that are off, frozen, and out of the visible screen. Also at the command prompt "Select objects:" you can enter Add, Remove, Undo, :U Enables subentity selection. Cannot be combined with the duplicate (":D") or nested (":N") selection modes. In this mode, top-level entities are selected by default, but the user can attempt to select subentities by pressing the CTRL key while making the selection. This option is supported only with interactive selections, such as window, crossing, and polygon. It is not supported for all, filtered, or group selections. :V Forces subentity selection. Treats all interactive, graphic selections performed by the user as subentity selections. The returned selection set contains subentities only. This option cannot be combined with the duplicate (":D") or nested (":N") selection modes. This option is supported only with interactive selections, such as window and crossing. It is not supported for all, filtered, or group selections. Systen Var PICKADD controls whether subsequent selections replace the current selection set or add to it. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; * (ssget "_:S") - selecting a single object * (ssget "_:E") - selecting all objects crossing the selection box (can be also combined to e.g. (ssget "_:E:S") * (ssget "_:N") - selecting objects including nested/child objects - e.g. with block references * (ssget "_:D") - duplicate objects counted separately (2x selected object = 2 selections) * (ssget "_:L") - stops users from selecting objects on locked layers * (ssget "_:P") - rejects selection of viewports * (ssget "+.") - allows window selection even in the single selection mode - (ssget "+.:E:S") (may not work in localized versions) :N Call ssnamex for additional information on container blocks and transformation matrices for any entities selected during the ssget operation. This additional information is available only for entities selected through graphical selection methods such as Window, Crossing, and point picks. Unlike the other object selection methods, :N may return multiple entities with the same entity name in the selection set. For example, if the user selects a subentity of a complex entity such as a BlockReference, PolygonMesh, or old style polyline, ssget looks at the subentity that is selected when determining if it has already been selected. However, ssget actually adds the main entity (BlockReference, PolygonMesh, and so on) to the selection set. The result could be multiple entries with the same entity name in the selection set (each will have different subentity information for ssnamex to report). :R Allows entities in a long transaction to be selected. :U Enables subentity selection. Cannot be combined with the duplicate (":D") or nested (":N") selection modes. In this mode, top-level entities are selected by default, but the user can attempt to select subentities by pressing the CTRL key while making the selection. This option is supported only with interactive selections, such as window, crossing, and polygon. It is not supported for all, filtered, or group selections. :V Forces subentity selection. Treats all interactive, graphic selections performed by the user as subentity selections. The returned selection set contains subentities only. This option cannot be combined with the duplicate (":D") or nested (":N") selection modes. This option is supported only with interactive selections, such as window and crossing. It is not supported for all, filtered, or group selections. Quote
alanjt Posted May 24, 2010 Posted May 24, 2010 The lambda i and n portions are just applying a number to an anonymous function. In this situation, it keeps me from defining i as -1 and n as 0. Quote
CADWORKER Posted October 19, 2022 Posted October 19, 2022 On 5/24/2010 at 3:39 PM, alanjt said: You're not applying the sorted list (code I provided). After you sort the selection set, you are stepping through it again (your code). (defun c:SortY (/ ss lst ent) ((lambda (n) (if (setq ss (ssget "_:L" '((0 . "TEXT")))) (foreach x (vl-sort ((lambda (i) (while (setq e (ssname ss (setq i (1+ i)))) (setq lst (cons e lst)) ) ) -1 ) (function (lambda (a b) (> (caddr (assoc 10 (entget a))) (caddr (assoc 10 (entget b))))) ) ) (setq ent (entget x)) (entmod (subst (cons 1 (strcat "'" (itoa (setq n (1+ n))))) (assoc 1 ent) ent)) ) ) ) 0 ) (princ) ) HI, Good day to All. Going into the history can this great code be modified to ask for the starting number. and also to export the coordinates X,Y,Z along with the numbers. Thanks in advance Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.