BlackAlnet Posted June 12, 2009 Share Posted June 12, 2009 I have many text in a draw, and, i need to take ALL that text value, and put in a ".csv" file... i know how to extract, but, i'm having a problem with the "ssget" lsp cmd... (setq l1 (ssget "x" '((0 . "TEXT") (8 . "testlayer")))) What this returns to me? How can i take the "text" to do a "write-line" with then?? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 12, 2009 Share Posted June 12, 2009 Your code will return a selection set of all text on the layer with name: testlayer. To Collect all MTEXT and TEXT: (setq l1 (ssget "_X" '((0 . "[color=Red][b]*[/b][/color]TEXT") (8 . "testlayer")))) You will need to either iterate through this set, or convert it to a list to write the contents to file. Something like this would convert it to a list of text strings: (mapcar (function (lambda (x) (cdr (assoc 1 (entget x))))) (mapcar 'cadr (ssnamex l1))) Quote Link to comment Share on other sites More sharing options...
BlackAlnet Posted June 12, 2009 Author Share Posted June 12, 2009 Ok, i'll try to get the idea from myself. Thanks for the help AGAIN Lee Mac. I really like u mate. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 12, 2009 Share Posted June 12, 2009 Ok, i'll try to get the idea from myself. Thanks for the help AGAIN Lee Mac. I really like u mate. No problem mate, if you have any more questions about anything I have posted, just ask Quote Link to comment Share on other sites More sharing options...
BlackAlnet Posted June 12, 2009 Author Share Posted June 12, 2009 Ok, take a look, if i'm getting it right... (mapcar;return a list, using a list in the fuction (function;optimizing the function (lambda (x);define the function above (cdr (assoc 1 (entget x)));return the text of the entity("x" means ALL entitys?) );end lambda );end function (mapcar 'cadr (ssnamex l1));i dont understand that part...;end mapcar );end main mapcar Well, i dont know how to insert my "write-line" on this lisp. It's returning a "blank file".... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 12, 2009 Share Posted June 12, 2009 Take a look at this: (defun c:wrtxt (/ ss file ofile) ;; Define Function and Localise Variables (if ; IF the following (and ; Both of these must be true... (setq ss (ssget "_X" '((0 . "*TEXT") (8 . "testlayer")))) ; Collect all *TEXT on LAYER "testlayer" (setq file (getfiled "Output File" "" "txt" 9)) ; Prompt for File to Write to ) ; End And (progn ; Wrap all the following Statements (setq ofile (open file "w")) ; Open the file for writing (mapcar ;; Perform the following function on every thing in the list (function ; Declare the following as a function (lambda (x) ; Anonymous Function name (write-line x ofile) ; Write each "x" in the list to the file ) ; End Lambda ) ; End Function (mapcar ;; Perform the following function on every thing in the list (function ; Declare the following as a function (lambda (x) ; Anonymous Function name (cdr (assoc 1 (entget x))) ; Retrieve the Text String from each "x" ) ; end Lambda ) ; end Function (mapcar 'cadr ; Perform "cadr" on every item in the list (ssnamex ss) ; Get a list of information about the Selection Set ) ; End Mapcar ) ; End Mapcar ) ; End Mapcar (close ofile) ; Close File ) ; End Progn (princ "\n<< No Text Found or No File Selected >>") ; Else Statement ) ; End IF (princ) ; Exit Cleanly ) ; End DEFUN Quote Link to comment Share on other sites More sharing options...
BlackAlnet Posted June 12, 2009 Author Share Posted June 12, 2009 Wow!! Very nice, you make's me think again about the function...I am Still having a lot of things to learn... So, 1st mapcar set "x" to write, 2nd select the text itself, and 3 select the "3" entity parameter, in order(-1,0,1...), is this? Great thanks Lee If you come here in Brazil in 2014 (World Cup Soccer), tell me. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 12, 2009 Share Posted June 12, 2009 The way I have approached this is a lot more complicated than your average LISP; but if you can understand these methods, you will be better off in the long run. Instead of shuffling through the set, I am dealing with a list of all the entities in the Selection Set and applying a function to each entity using Mapcar. When trying to understand the operations, work it backwards. i.e. The first step is: [b][color=Red](ssnamex ss)[/color][/b] This will create our initial list to play with. The list contains the entity names in the selection set, and also other information about how they were acquired. We need to extract all the entity names from this list, so we apply the function cadr to every element in the list, to get to the entity name: (mapcar '[b][color=Blue]cadr[/color][/b] [b][color=Red](ssnamex ss)[/color][/b]) So, now we have a list of entity names to deal with: ([i]<ename1> <ename2> <ename3> ... <enamex>[/i]) We now need to extract the text String contained in each entity, so we can define our function to do this: [color=SeaGreen][b](function (lambda (x) (cdr (assoc 1 (entget x))) ) ; end Lambda ) ; end function[/b][/color] Above, we have defined an anonymous function lambda to perform an operation to the list. In this case, it takes an item (x), and retrieves the text String from that item. And so, just like we applied cadr using mapcar, we can now apply our newly created function lambda to the list (where our previous list is highlighted in red): (mapcar [color=SeaGreen] [b] (function (lambda (x) (cdr (assoc 1 (entget x))) ) ; end Lambda ) ; end function[/b][/color] [b][/b][color=Red][color=Black](mapcar '[/color][/color][b][color=Red][color=Blue]cadr[/color] (ssnamex ss) [/color][/b][color=Black]) ; end Mapcar[/color] ) ; end Mapcar And now we have a list of the results of applyling our lambda function, i.e.,we now have a list of text strings: ([i]"string1" "string2" "string3" ... "stringn"[/i]) And so, we can now define another anonymous function in the same fashion to write these strings to a file: [color=DarkOrchid][b](function (lambda (x) (write-line x ofile) ) ; end Lambda ); end function[/b][/color] The above takes each String (x) and will write it to the file stored to the variable: (ofile). And, so we can apply this function to our list, again using mapcar: (mapcar [b][color=Blue] [color=DarkOrchid] (function (lambda (x) (write-line x ofile) ) ; end Lambda ); end function[/color][/color][/b] [b][/b][color=Black] (mapcar[/color][b][color=Red] [color=SeaGreen] (function (lambda (x) (cdr (assoc 1 (entget x))) ) ; end Lambda ) ; end function[/color] [/color][/b][color=Black] (mapcar '[/color][b][color=Red][color=Blue]cadr[/color] (ssnamex ss) [/color][/b][color=Red][color=Black] ) ; end Mapcar ) ; end Mapcar[/color][/color] ) ; End Mapcar If you don't understand something that I have posted, just ask about it, and I will try to explain it better for you. Cheers, Lee Quote Link to comment Share on other sites More sharing options...
BlackAlnet Posted June 12, 2009 Author Share Posted June 12, 2009 When trying to understand the operations, work it backwards. Yes, i understand it from backwards. XD. I'll try make more of this operators, to fix the information. It's advanced!! You is a good man Lee, comming here, helping everyone, helping me. Thanks you so much!! I realy want to learn how to make Lisp, it's fun, think and try to make something, it's magic on screen!! Very thanks, big bro. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 12, 2009 Share Posted June 12, 2009 Yes, i understand it from backwards. XD. I'll try make more of this operators, to fix the information. It's advanced!! You is a good man Lee, comming here, helping everyone, helping me. Thanks you so much!! I realy want to learn how to make Lisp, it's fun, think and try to make something, it's magic on screen!! Very thanks, big bro. No problem, I'm glad that you could understand my explanation Lee 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.