kapat Posted November 9, 2012 Posted November 9, 2012 SOOooo..... i've been tooling around with getpoints and "cond" but i can't seem to make this work other then REALLY primitively. the 2 forums i have found on the matter are: HERE AND HERE i am not sure if it's bad karma to link to another set of forums, but for research sake, i think these should all be linked. The main problem i think most people have when they come here is they can find 90% of what their looking for in google, but have a hard time personalizing everything to the format they are looking for. I am afflicted with the same. i can just copy these guy's code and have it work halfway, but then ti's not really helping me out, since i have to go back and format it anyways. And i swear i google and try out 40 or 50 different way to code before i come to you guys. The guilt from the free coding i'm contracting from your guys really builds up. I hope i'm not seeming TOO much of a freeloader when i ask these questions, you guys really are the best. NOW, on to what i have, and what i am going for. Basically i want to pick a point, have the point named, and have that be put into notepad with formatting. such as this: (command "whatever") prompt for file name (location doens't matter to me, can be "c:\" or "user\desktop" (pick point) and the read out will have: PT1 111.1111 222.2222 333.3333 PT2 444.4444 555.5555 666.6666 and so on, and have the "pt#" increase with all the points. Also, the tricky part is i need "5 spaces" between the numbers without using a "\t". which is what i'd LIKE to use, but that's just not the way my cookie is crumbling today. i would like to thank anybody who has made it this far and hasn't moved on. Now code time: (defun c:P2FILE (/ fname file text pt p2) (setq fname (getkword "\nenter filename")) (setq file (open fname".txt" "w")) (setq pt1 (getpoint "\nPICK POINT")) (setq x (rtos (car pt1))) (setq y (rtos (cadr pt1))) (setq z (rtos (caddr Pt1))) (setq text (strcat "PT1 "x" "y" "z)) (write-line text fname) (close file) ) Now things i know are wrong but have no clue how to fix: "getkword" i'm sure is jut the wrong command, since putting in every variable is a ridiculous notion. and my "strcat" doens't number up with the points i pick, but i have no idea how to even START making that "cond" Thanks in advance for any help! Quote
JohnM Posted November 10, 2012 Posted November 10, 2012 Can you explain more? What will the notepad file be used for? Why do you need 5 spaces? Quote
kapat Posted November 10, 2012 Author Posted November 10, 2012 I have updated the code, and i am VERY close, though i'm not at work till tommarow. but it's for a program called "netrology," used, in civil engineering and such. That's just how the design files are set up. Quote
BIGAL Posted November 10, 2012 Posted November 10, 2012 You need to use rtos to increase pt number, also there were a number of other errors which I have changed (defun c:P2FILE (/ fname file text pt1 ) (setq fname (getstring "\nenter filename")) (setq file (open fname "w")) (setq J (getint "\nEnter start number")) (while (setq pt1 (getpoint "\nPICK POINT enter to EXIT")) (setq x (rtos (car pt1) 2 3 )) (setq y (rtos (cadr pt1) 2 3 )) (setq z (rtos (caddr Pt1) 2 3 )) ;I would write line for clarity (setq text (strcat "PT" (rtos J 2 0) " " x " " y " " z)) (write-line text fname) (setq J (+ J 1)) ) (close fname) ) Quote
kapat Posted November 10, 2012 Author Posted November 10, 2012 (edited) Hmm, it doens't seem to work. here's what i had: (defun c:p2f (/ p x y z x1 y1 z1 ptcoord textloc cs_from cs_to file text) (setq j (getint "\nEnter start number")) (while ;start while (setq p (getpoint "CHOOSE YOUR POINT")) (setq cs_from 1) (setq cs_to 0) (setq p1 (trans p cs_from cs_to 0)) (setq textloc (getpoint p "PLACE TEXT")) (setq x (rtos (car p1) 2 3)) (setq y (rtos (cadr p1 2 3))) (setq z (rtos (caddr P1) 2 3)) (setq ptcoord (strcat "pt"(rtos j)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") (setq text (strcat "pt"(rtos j)" "x" "y" "z)) (setq file (open "c:\design.txt" "w")) (command file) (write-line text) (close file) (setq j (+ j1)) (princ) ) ;end while ) thanks for the (rtos (+ j 1)) that's a really cool trick to number your stuff. Still not workign though Edited November 10, 2012 by kapat revised using some bigal's code Quote
MSasu Posted November 10, 2012 Posted November 10, 2012 First, please pay attention to the use of WHILE - on your excerpt will overwrite the output file at each cycle. I did some corrections to your code to output correctly to file: (setq text (strcat "pt " x " " y " " z)) (setq file (open "c:\[color=red]\[/color]design.txt" "w")) [color=red][s](command file)[/s][/color] (write-line text [color=red]file[/color]) (close file) Quote
kapat Posted November 10, 2012 Author Posted November 10, 2012 (defun c:p2f (/ p x y z j ptcoord textloc cs_from cs_to file text) (setq j (getint "\nEnter start number")) (while ;start while (setq p (getpoint "CHOOSE YOUR POINT")) (setq cs_from 1) (setq cs_to 0) (setq p1 (trans p cs_from cs_to 0)) (setq textloc (getpoint p "PLACE TEXT")) (setq x (rtos (car p1))) (setq y (rtos (cadr p1))) (setq z (rtos (caddr P1))) (setq ptcoord (strcat "pt"(rtos j)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") (setq text (strcat "pt"(rtos j)" "x" "y" "z)) (setq file (open "c:\\design.txt" "w")) (write-line text file) (close file) (setq j (+ j 1)) (princ) ) ;end while ) you're right, the "while" is still screwy. i wanted it to start at "input #" and just keep adding as i go along. and if i wanted to stop, do something else, and start again, i can just start with whatever number i left off of. Quote
kapat Posted November 10, 2012 Author Posted November 10, 2012 BTW i am aware that "ptcoord" and "text" doesn't need to be different. i jsut have it that way so it's easier for me to read. Quote
jammie Posted November 10, 2012 Posted November 10, 2012 I think you are getting close with your code, just one observation (setq file (open "c:\\design.txt" "w")) should be (setq file (open "c:\\design.txt" "a")) If you open a file using "w" it keeps overwriting the file. Opening using "a" allows you to add to a file Quote
kapat Posted November 10, 2012 Author Posted November 10, 2012 (edited) I DID IT! thanks for the help guys FINISHED CODE: (defun c:p2f (/ p x y z j ptcoord textloc cs_from cs_to file text filename) (setq filename (strcat "c:\\"(getstring "\nEnter File Name")".txt")) (setq j (getint "\nEnter Start Number")) (while ;start while (setq p (getpoint "Pick Point")) (setq cs_from 1) (setq cs_to 0) (setq p1 (trans p cs_from cs_to 0)) (setq textloc (getpoint p "PLACE TEXT")) (setq x (rtos (car p1))) (setq y (rtos (cadr p1))) (setq z (rtos (caddr P1))) (setq ptcoord (strcat "pt"(rtos j 2 0)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") (setq file (open filename "a")) (write-line ptcoord file) (close file) (setq j (+ j 1)) (princ) ) ;end while ) THANKS JAMMIE! THANKS MSasu! ALSO BIGAL! Edited November 10, 2012 by kapat added the option of nameing your file before you start picking and saving. Quote
jammie Posted November 10, 2012 Posted November 10, 2012 (edited) Congrats on the progress with code! There are two ways you could prompt for a file name - getstring & getfiled. Getfiled will produce a nice dialog but getstring also has its merits. Perhaps the following might give you an idea using getstring ;;Set a default file name to save your data to (setq saveFile "c:\\design.txt") ;;The following will ask the user to type a new filename to save to ;;Or if they hit enter just use the default value (setq prompt (strcat "\nType file or hit enter to use [" saveFile "]")) (setq input (getstring t prompt)) ;;If the user has hit enter then the would like to use the default file name ;;Getstring will return "", that means there is no need to change the file name ;;Thats where the not expression comes in (if (not (= input "")) (setq saveFile input) ) finally ;;Change the original line ;;(setq file (open "c:\\design.txt" "a")) to (setq file (open saveFile "a")) Edited November 11, 2012 by jammie Missing closing bracket on prompt statement.. Quote
stevesfr Posted November 11, 2012 Posted November 11, 2012 Congrats on the progress with code! There are two ways you could prompt for a file name - getstring & getfiled. Getfiled will produce a nice dialog but getstring also has its merits. Perhaps the following might give you an idea using getstring ;;Set a default file name to save your data to (setq saveFile "c:\\design.txt") ;;The following will ask the user to type a new filename to save to ;;Or if they hit enter just use the default value (setq prompt (strcat "\nType file or hit enter to use [" saveFile "]") (setq input (getstring t prompt)) ;;If the user has hit enter then the would like to use the default file name ;;Getstring will return "", that means there is no need to change the file name ;;Thats where the not expression comes in (if (not (= input "")) (setq saveFile input) ) finally ;;Change the original line ;;(setq file (open "c:\\design.txt" "a")) to (setq file (open saveFile "a")) Tried inserting these revisions but probably left something out for sure.... hint please for how to prompt for user file save location. Steve Quote
kapat Posted November 11, 2012 Author Posted November 11, 2012 unless there's a way to get a nifty "save as" dialog box, i thinking finding and moving the txt file from c:\ to whereever it just as useful as typign out your full location. i to need to move and save these in places, but i just keep overwriting my main "c:\" notepad and paste/rename them whenever i'm done making them. Quote
jammie Posted November 11, 2012 Posted November 11, 2012 @ stevesfr, can you test the following and see if it works as expected? (defun c:p2f (/ p x y z j ptcoord textloc cs_from cs_to file text filename) ;(setq filename (strcat "c:\\"(getstring "\nEnter File Name")".txt")) (setq saveFile "c:\\design.txt") (setq prompt (strcat "\nType file or hit enter to use [" saveFile "]")) (setq input (getstring t prompt)) (if (not (= input "")) (setq saveFile input) ) (setq j (getint "\nEnter Start Number")) (while ;start while (setq p (getpoint "Pick Point")) (setq cs_from 1) (setq cs_to 0) (setq p1 (trans p cs_from cs_to 0)) (setq textloc (getpoint p "PLACE TEXT")) (setq x (rtos (car p1))) (setq y (rtos (cadr p1))) (setq z (rtos (caddr P1))) (setq ptcoord (strcat "pt"(rtos j 2 0)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") ;(setq file (open filename "a")) (setq file (open saveFile "a")) ;(write-line ptcoord file) (write-line ptcoord saveFile) ;(close file) (close saveFile) (setq j (+ j 1)) (princ) ) ;end while ) @ kapat you should look into the Autolisp function getfiled - this will let you produce a save dialog box Quote
kapat Posted November 11, 2012 Author Posted November 11, 2012 what you could do steve is repace (setq filename (strcat "c:\\"(getstring "\nEnter File Name")".txt")) with: (setq filename (strcat (getstring "\nEnter File Name")".txt")) and when you save it you can type in the directory such as "c:\file1\blahblah1" OR you can do what i do and replace "c:\\" with "C:\Users\ (YOUR USERNAME) \Desktop\output file folder\" and just tag in your computer username in there, and you can just always have a desktop folder of all your points. Quote
kapat Posted November 11, 2012 Author Posted November 11, 2012 SWEET, thanks jammie! i couldn't specify that enough for Google to understand me. thank god for humans. nice humans. Quote
stevesfr Posted November 11, 2012 Posted November 11, 2012 @ stevesfr, can you test the following and see if it works as expected? (defun c:p2f (/ p x y z j ptcoord textloc cs_from cs_to file text filename) ;(setq filename (strcat "c:\\"(getstring "\nEnter File Name")".txt")) (setq saveFile "c:\\design.txt") (setq prompt (strcat "\nType file or hit enter to use [" saveFile "]")) (setq input (getstring t prompt)) (if (not (= input "")) (setq saveFile input) ) (setq j (getint "\nEnter Start Number")) (while ;start while (setq p (getpoint "Pick Point")) (setq cs_from 1) (setq cs_to 0) (setq p1 (trans p cs_from cs_to 0)) (setq textloc (getpoint p "PLACE TEXT")) (setq x (rtos (car p1))) (setq y (rtos (cadr p1))) (setq z (rtos (caddr P1))) (setq ptcoord (strcat "pt"(rtos j 2 0)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") ;(setq file (open filename "a")) (setq file (open saveFile "a")) ;(write-line ptcoord file) (write-line ptcoord saveFile) ;(close file) (close saveFile) (setq j (+ j 1)) (princ) ) ;end while ) @ kapat you should look into the Autolisp function getfiled - this will let you produce a save dialog box @jammie this works partially, however upon loading and thence invoking the program I get an alert popdown question screen... "Assignment to protected Symbol: PROMPT Enter break loop? Yes... No... the choice is there where to save the results and program is not repetative, now asks every time what is start coord location number. I'm using A2008 Quote
jammie Posted November 11, 2012 Posted November 11, 2012 @steve Can you change the variable name prompt to something else like msg in the code I posted and see if that works? I had a bit of a brain fart, prompt is an Autolisp function so that was the error message autocad was returning... Quote
stevesfr Posted November 11, 2012 Posted November 11, 2012 @steve Can you change the variable name prompt to something else like msg in the code I posted and see if that works? I had a bit of a brain fart, prompt is an Autolisp function so that was the error message autocad was returning... prior to these revisions and now incorporating the above revision (which cured the problem) , results are not being written to my default save file. the original program did so without a problem. also now with this edition one has to enter a start point number every time over and over. things going from bad to worse. did however get rid of prompt popdown. 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.