BlackBox Posted June 30, 2011 Share Posted June 30, 2011 I did mean that it is new to me to know that the mtext would behave that way when it is being formatted .Thanks for the clarification . See... we learn something new everyday! Quote Link to comment Share on other sites More sharing options...
Reu Posted January 24, 2013 Share Posted January 24, 2013 I'm just getting started with AutoLISP, how would I rewrite this to remove more than one character? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 24, 2013 Share Posted January 24, 2013 I'm just getting started with AutoLISP, how would I rewrite this to remove more than one character? Consider the following code: (defun c:rchar ( / e i n s x ) (setq n 1) ;; Number of characters to remove from end of string (if (setq s (ssget "_:L" '((0 . "TEXT")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) x (cdr (assoc 1 (entget e))) ) (if (< n (strlen x)) (entmod (list (cons -1 e) (cons 1 (substr x 1 (- (strlen x) n))))) ) ) ) (princ) ) Welcome to CADTutor thunderfoot Quote Link to comment Share on other sites More sharing options...
Reu Posted January 24, 2013 Share Posted January 24, 2013 Consider the following code: (defun c:rchar ( / e i n s x ) (setq n 1) ;; Number of characters to remove from end of string (if (setq s (ssget "_:L" '((0 . "TEXT")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) x (cdr (assoc 1 (entget e))) ) (if (< n (strlen x)) (entmod (list (cons -1 e) (cons 1 (substr x 1 (- (strlen x) n))))) ) ) ) (princ) ) Welcome to CADTutor thunderfoot Thanks Lee. Works perfectly. It may take me a while to figure out exactly what is going on there though. AutoLISP is great can't wait to write some real programs of my own. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 24, 2013 Share Posted January 24, 2013 Thanks Lee. Works perfectly. It may take me a while to figure out exactly what is going on there though. AutoLISP is great can't wait to write some real programs of my own. You're very welcome - if you have any questions when dissecting the code, just ask. Quote Link to comment Share on other sites More sharing options...
Reu Posted January 24, 2013 Share Posted January 24, 2013 You're very welcome - if you have any questions when dissecting the code, just ask. Could you explain each line with "; comments"? *edit* Starting with the "if" statement, I do understand the basics of setq, and I thought I understood if. . . Thanks, Reuben Shilling Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 24, 2013 Share Posted January 24, 2013 Here's a quick dissection: ([color=BLUE]defun[/color] c:rchar ( [color=BLUE]/[/color] e i n s x ) [color=GREEN];; define function, declare local variables[/color] ([color=BLUE]setq[/color] n 1) [color=GREEN];; Number of characters to remove from end of string[/color] ([color=BLUE]if[/color] [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]setq[/color] s [color=GREEN];; Assign the following value to the symbol 's'[/color] ([color=BLUE]ssget[/color] [color=GREEN];; Collect a selection set of[/color] [color=MAROON]"_:L"[/color] [color=GREEN];; Object on unlocked layers[/color] '((0 . [color=MAROON]"TEXT"[/color])) [color=GREEN];; whose entity type (DXF Group 0) = TEXT[/color] ) [color=GREEN]; end ssget[/color] ) [color=GREEN];; end setq[/color] ([color=BLUE]repeat[/color] [color=GREEN];; repeat a set of expressions a number of times[/color] ([color=BLUE]setq[/color] i [color=GREEN];; Assign the following value to the symbol 'i'[/color] ([color=BLUE]sslength[/color] s) [color=GREEN];; Number of items in the selection set[/color] ) [color=GREEN];; end setq [/color] ([color=BLUE]setq[/color] e [color=GREEN];; Assign the following value to the symbol 'e'[/color] ([color=BLUE]ssname[/color] s [color=GREEN];; Retrieve the entity name at a specific index in the set[/color] ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)) [color=GREEN];; Decrement the counter variable 'i'[/color] ) [color=GREEN];; end ssname[/color] x [color=GREEN];; Assign the following value to the symbol 'x'[/color] ([color=BLUE]cdr[/color] [color=GREEN];; Return the second item of the dotted pair[/color] ([color=BLUE]assoc[/color] 1 [color=GREEN];; Retrieve the dotted pair with DXF Group 1 (the text string)[/color] ([color=BLUE]entget[/color] e) [color=GREEN];; Retrieve the DXF data for the entity assigned to the symbol 'e'[/color] ) [color=GREEN];; end assoc[/color] ) [color=GREEN];; end cdr[/color] ) [color=GREEN];; end setq[/color] ([color=BLUE]if[/color] [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]<[/color] n ([color=BLUE]strlen[/color] x)) [color=GREEN];; If the length of the text string is greater than the number of characters to be subtracted[/color] ([color=BLUE]entmod[/color] [color=GREEN];; Modify the following DXF data[/color] ([color=BLUE]list[/color] [color=GREEN];; Contruct a list of DXF data[/color] ([color=BLUE]cons[/color] -1 e) [color=GREEN];; Create a dotted pair with the entity to be modified (1 . <entity-name>)[/color] ([color=BLUE]cons[/color] 1 [color=GREEN];; Create a dotted pair with the new string value (DXF Group 1)[/color] ([color=BLUE]substr[/color] x [color=GREEN];; Return a substring of the entity text string[/color] 1 [color=GREEN];; from the first character[/color] ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] x) n) [color=GREEN];; spanning the length of the string minus the number of characters to be removed[/color] ) [color=GREEN];; end substr[/color] ) [color=GREEN];; end cons[/color] ) [color=GREEN];; end list[/color] ) [color=GREEN];; end entmod[/color] ) [color=GREEN];; end if[/color] ) [color=GREEN];; end repeat[/color] ) [color=GREEN];; end if[/color] ([color=BLUE]princ[/color]) [color=GREEN];; Suppress the return of the last evaluated expression[/color] ) [color=GREEN];; end defun[/color] Quote Link to comment Share on other sites More sharing options...
Reu Posted January 24, 2013 Share Posted January 24, 2013 Here's a quick dissection: ([color=BLUE]defun[/color] c:rchar ( [color=BLUE]/[/color] e i n s x ) [color=GREEN];; define function, declare local variables[/color] ([color=BLUE]setq[/color] n 1) [color=GREEN];; Number of characters to remove from end of string[/color] ([color=BLUE]if[/color] [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]setq[/color] s [color=GREEN];; Assign the following value to the symbol 's'[/color] ([color=BLUE]ssget[/color] [color=GREEN];; Collect a selection set of[/color] [color=MAROON]"_:L"[/color] [color=GREEN];; Object on unlocked layers[/color] '((0 . [color=MAROON]"TEXT"[/color])) [color=GREEN];; whose entity type (DXF Group 0) = TEXT[/color] ) [color=GREEN]; end ssget[/color] ) [color=GREEN];; end setq[/color] ([color=BLUE]repeat[/color] [color=GREEN];; repeat a set of expressions a number of times[/color] ([color=BLUE]setq[/color] i [color=GREEN];; Assign the following value to the symbol 'i'[/color] ([color=BLUE]sslength[/color] s) [color=GREEN];; Number of items in the selection set[/color] ) [color=GREEN];; end setq [/color] ([color=BLUE]setq[/color] e [color=GREEN];; Assign the following value to the symbol 'e'[/color] ([color=BLUE]ssname[/color] s [color=GREEN];; Retrieve the entity name at a specific index in the set[/color] ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)) [color=GREEN];; Decrement the counter variable 'i'[/color] ) [color=GREEN];; end ssname[/color] x [color=GREEN];; Assign the following value to the symbol 'x'[/color] ([color=BLUE]cdr[/color] [color=GREEN];; Return the second item of the dotted pair[/color] ([color=BLUE]assoc[/color] 1 [color=GREEN];; Retrieve the dotted pair with DXF Group 1 (the text string)[/color] ([color=BLUE]entget[/color] e) [color=GREEN];; Retrieve the DXF data for the entity assigned to the symbol 'e'[/color] ) [color=GREEN];; end assoc[/color] ) [color=GREEN];; end cdr[/color] ) [color=GREEN];; end setq[/color] ([color=BLUE]if[/color] [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]<[/color] n ([color=BLUE]strlen[/color] x)) [color=GREEN];; If the length of the text string is greater than the number of characters to be subtracted[/color] ([color=BLUE]entmod[/color] [color=GREEN];; Modify the following DXF data[/color] ([color=BLUE]list[/color] [color=GREEN];; Contruct a list of DXF data[/color] ([color=BLUE]cons[/color] -1 e) [color=GREEN];; Create a dotted pair with the entity to be modified (1 . <entity-name>)[/color] ([color=BLUE]cons[/color] 1 [color=GREEN];; Create a dotted pair with the new string value (DXF Group 1)[/color] ([color=BLUE]substr[/color] x [color=GREEN];; Return a substring of the entity text string[/color] 1 [color=GREEN];; from the first character[/color] ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] x) n) [color=GREEN];; spanning the length of the string minus the number of characters to be removed[/color] ) [color=GREEN];; end substr[/color] ) [color=GREEN];; end cons[/color] ) [color=GREEN];; end list[/color] ) [color=GREEN];; end entmod[/color] ) [color=GREEN];; end if[/color] ) [color=GREEN];; end repeat[/color] ) [color=GREEN];; end if[/color] ([color=BLUE]princ[/color]) [color=GREEN];; Suppress the return of the last evaluated expression[/color] ) [color=GREEN];; end defun[/color] THANKS! I appreciate the time you invested in that. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 24, 2013 Share Posted January 24, 2013 THANKS! I appreciate the time you invested in that. You're very welcome Reuben, I hope my explanation are clear Quote Link to comment Share on other sites More sharing options...
Reu Posted January 29, 2013 Share Posted January 29, 2013 You're very welcome Reuben, I hope my explanation are clear Where can I find a list of accepted strings for the '0' DXF group? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 29, 2013 Share Posted January 29, 2013 Where can I find a list of accepted strings for the '0' DXF group? You could always try the developer documentation. :wink: Quote Link to comment Share on other sites More sharing options...
Reu Posted January 29, 2013 Share Posted January 29, 2013 You could always try the developer documentation. :wink: Thanks, Reuben Shilling So the DXF codes are basically used to narrow down the accepted selection set? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 29, 2013 Share Posted January 29, 2013 So the DXF codes are basically used to narrow down the accepted selection set? Correct, the majority* of DXF group codes, along with special filter operators (using a -4 group code), may be used to form the filter list argument for the ssget function. For more information, consult the documentation on the ssget function. *not all: you cannot filter for entity name types [DXF -1, 330, 340, 360 etc.], handles [DXF 5], or xData groups [DXF 1000 onwards] Quote Link to comment Share on other sites More sharing options...
ABUSAIF Posted February 15, 2013 Share Posted February 15, 2013 Hello, Tunnelrat.. could you please direct me to where you seen a lisp to add a lerre to a text? I been looking all day to find one with no luck, Thanks Quote Link to comment Share on other sites More sharing options...
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.