Demesne Posted October 7, 2010 Posted October 7, 2010 Hi all I'm trying to write a lisp that returns the value of a text string and stores this for use later on in the routine. i.e. imagine you have a text object that represents the Z value of a point. I want to select this text object and store the value for later use as the insertion Z value of a block. All text is at zero height! Quote
pBe Posted October 7, 2010 Posted October 7, 2010 (edited) Here's what you can do... select all the text... store it on a txt file.. now when you need to insert blocks for the points.. you can retrive it from the txt file you just created. use this to export the string value.. (defun c:writeme () (setq dwgnme (getvar "dwgname") fileTW (getfiled "Enter Filename" "" "txt" 1)) (setq akcs_fyw (open fileTW "a" )) (setq tx_twrt (ssget '((0 . "TEXT,MTEXT"))) cntr 0) (repeat (sslength tx_twrt) (setq vl_wrt (cdr (assoc 1 (entget (ssname tx_twrt cntr))))) (write-line vl_wrt akcs_fyw) (setq cntr (1+ cntr)) ) (close akcs_fyw) ) its unclear wether you want ot insert a different block for every point.... is it? or just one block for all points? Edited October 7, 2010 by pBe Quote
Demesne Posted October 7, 2010 Author Posted October 7, 2010 ok, rather than create a txt file i was hoping to store a single text string in a list. I'm currently using: (setq code (getstring "\nEnter name: ")) and manually typing in a value. Rather than type I was wanting to pick text and use the text string already on the drawing. Or is there a system variable that returns the text string??? Quote
pBe Posted October 7, 2010 Posted October 7, 2010 (edited) as a matter of fact there is. "USERS1" to "USERS5" (setq txt_usrs (cdr (assoc 1 (entget (car (entsel "\nSelect Text: ")))))) (setvar "users1" txt_usrs) you can retrieve the "string" by (getvar "USERS1")... but if you want to store it on a 'list (22.0 333.0 2555.0) you can use this (defun c:storeme () (setq tx_twrt (ssget '((0 . "TEXT,MTEXT"))) cntr 0 vl_lst nil) (repeat (sslength tx_twrt) (setq vl_wrt (cdr (assoc 1 (entget (ssname tx_twrt cntr)))) vl_lst (cons vl_wrt vl_lst)) (setq cntr (1+ cntr)) ) (print vl_lst)(princ) ) Better yet... tell us what you need and im sure somebody here will write if for you .. but then again where's the fun in that c",) We give you you a code to start with... try to learn it... and if you're stumped you can always ask again... I should know.. that's what did Cheers Edited October 7, 2010 by pBe Quote
David Bethel Posted October 7, 2010 Posted October 7, 2010 Maybe: [b][color=BLACK]([/color][/b]defun c:storetxt [b][color=FUCHSIA]([/color][/b]/ ss[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not ss[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]/= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nSelect 1 Text..."[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"*TEXT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq code [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 1 [b][color=GREEN]([/color][/b]entget [b][color=BLUE]([/color][/b]ssname ss 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] code[b][color=BLACK])[/color][/b] The variable 'code' is global and the name will be tricky if you are trying to use multiple values. -David Quote
Guest kruuger Posted October 7, 2010 Posted October 7, 2010 maybe at window registry (defun C:WR (/ W) (if (setq W (getstring T "\nEnter text to save to window registry: ")) (vl-registry-write "HKEY_CURRENT_USER\\Software\\Demesne" "My Text" W) ) (princ) ) (defun C:RE (/ R) (if (setq R (vl-registry-read "HKEY_CURRENT_USER\\Software\\Demesne" "My Text")) (alert (strcat "\nYou save to registry:\n" R ) ) (princ "\nNo text at registry. ") ) (princ) ) (princ) Quote
pBe Posted October 7, 2010 Posted October 7, 2010 Maybe: [b][color=black]([/color][/b]defun c:storetxt [b][color=fuchsia]([/color][/b]/ ss[b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]while [b][color=navy]([/color][/b]or [b][color=maroon]([/color][/b]not ss[b][color=maroon])[/color][/b] [b][color=maroon]([/color][/b]/= [b][color=green]([/color][/b]sslength ss[b][color=green])[/color][/b] 1[b][color=maroon])[/color][/b][b][color=navy])[/color][/b] [b][color=navy]([/color][/b]princ [color=#2f4f4f]"\nSelect 1 Text..."[/color][b][color=navy])[/color][/b] [b][color=navy]([/color][/b]setq ss [b][color=maroon]([/color][/b]ssget '[b][color=green]([/color][/b][b][color=blue]([/color][/b]0 . [color=#2f4f4f]"*TEXT"[/color][b][color=blue])[/color][/b][b][color=green])[/color][/b][b][color=maroon])[/color][/b][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b] [b][color=fuchsia]([/color][/b]setq code [b][color=navy]([/color][/b]cdr [b][color=maroon]([/color][/b]assoc 1 [b][color=green]([/color][/b]entget [b][color=blue]([/color][/b]ssname ss 0[b][color=blue])[/color][/b][b][color=green])[/color][/b][b][color=maroon])[/color][/b][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b] code[b][color=black])[/color][/b] The variable 'code' is global and the name will be tricky if you are trying to use multiple values. -David You are right David.. its unclear what Demesne intended to do with the string... Quote
pBe Posted October 7, 2010 Posted October 7, 2010 maybe at window registry (defun C:WR (/ W) (if (setq W (getstring T "\nEnter text to save to window registry: ")) (vl-registry-write "HKEY_CURRENT_USER\\Software\\Demesne" "My Text" W) ) (princ) ) (defun C:RE (/ R) (if (setq R (vl-registry-read "HKEY_CURRENT_USER\\Software\\Demesne" "My Text")) (alert (strcat "\nYou save to registry:\n" R ) ) (princ "\nNo text at registry. ") ) (princ) ) (princ) That is wickedly cool... i will use this sometime Quote
Demesne Posted October 7, 2010 Author Posted October 7, 2010 That's it: (setq ss (ssget '((0 . "*TEXT")))) (setq code (cdr (assoc 1 (entget (ssname ss 0))))) Thanks David, thanks pBe You are right David.. its unclear what Demesne intended to do with the string... Apologies - I'm trying to multi-task! Thanks for your help Quote
alanjt Posted October 7, 2010 Posted October 7, 2010 Put the values in a list. (defun foo (/ ss) (if (setq ss (ssget '((0 . "TEXT")))) (reverse ((lambda (i / e l) (while (setq e (ssname ss (setq i (1+ i)))) (setq l (cons (cdr (assoc 1 (entget e))) l)) ) ) -1 ) ) ) ) eg. (setq lst (foo)) Quote
alanjt Posted October 7, 2010 Posted October 7, 2010 maybe at window registry (defun C:WR (/ W) (if (setq W (getstring T "\nEnter text to save to window registry: ")) (vl-registry-write "HKEY_CURRENT_USER\\Software\\Demesne" "My Text" W) ) (princ) ) (defun C:RE (/ R) (if (setq R (vl-registry-read "HKEY_CURRENT_USER\\Software\\Demesne" "My Text")) (alert (strcat "\nYou save to registry:\n" R ) ) (princ "\nNo text at registry. ") ) (princ) ) (princ) You can also use SETENV and GETENV. 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.