BIGAL Posted November 11, 2012 Posted November 11, 2012 Next number if you do again in same session but remeber if you use J somewhere else will give wrong number so make it a unique variable name ptcounter ? (defun c:p2f (J / p x y z ptcoord textloc cs_from cs_to file text filename) (if (= J nil) (setq j (Getint "\nEnter number")) (setq j (+ j 1)) ) Quote
jammie Posted November 11, 2012 Posted November 11, 2012 @steve are you using AutoCAD's VLIDE for debugging your progam or a simple text editor? The issue relating to the default save file, if not using VLIDE type !input into AutoCAD's commandline. This will return what AutoCAD sees the default path to be. Does the save location for your file look correct? In relation to the numbering you need to find a way to make the count j global. That means the value will persist between calling of the routine. In kapat's code he declares all of the variables to be made null once the program completes. You do this by assigning a / after the initial defun (defun c:p2f (/ [color="blue"]p x y z j ptcoord textloc cs_from cs_to file text filename[/color]) In this case all the variables in blue will be set to nil after the program completes. If you want something to persist, don't include the variable name here Quote
stevesfr Posted November 12, 2012 Posted November 12, 2012 jammie & BIGAL.... thanks guys.... all is fine now... due to your help Steve Quote
kapat Posted November 12, 2012 Author Posted November 12, 2012 So i have 1 quesiton that might be really simple. It might have to do with "dimzin"... Anyways, if anybody remembers in the 1st post i explained that i wanted "5 spaces." well, it turns out what "netrology" does it so that it just has 12 spots to place a 12 digit number, and a tab between those. so it reads "pt1[tab] 1245.6789[tab] 1234.5678[tab] 1234.5678 "pt2[tab] 123.4567[tab] 12345.6789[tab] 12.3456" and so on, so the decimal will always line up. it uses spaces where the leading number of "0's" go. So the # of spaces being (12 - # of digits, including the precision of 4) i'm sure it's just 1 option i just need to flock on, but DIMZIN doesn't make any sense to me. Quote
BIGAL Posted November 13, 2012 Posted November 13, 2012 Jamie In relation to the numbering you need to find a way to make the count j global. That means the value will persist between calling of the routine. Either J / p x y z or just dont include J in 1st line of defun look at post above. Quote
stevesfr Posted November 13, 2012 Posted November 13, 2012 I thought all was OK, but I'm having problem saveing to different file location. Help/hint to fix appreciated. (defun c:p2frev (/ 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 "P"(rtos j 2 1)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") ;(setq file (open "c:\\data\\design.txt" "a")) (setq saveFile "c:\\data\\design.txt") (setq MSG (strcat "\nType file or hit enter to use [" saveFile "]")) (setq input (getstring t MSG)) (setq file (open saveFile "a")) (write-line ptcoord file) (close file) (setq j (+ j 1)) (princ) ) ;end while ) Quote
jammie Posted November 13, 2012 Posted November 13, 2012 Hi Steve, I think this is the area thats causing the problem for you (setq [color="blue"][color="darkorange"]saveFile [/color][/color]"c:\\data\\design.txt") (setq MSG (strcat "\nType file or hit enter to use [" saveFile "]")) (setq [color="blue"]input [/color](getstring t MSG)) (setq file (open [color="orange"]saveFile [/color]"a")) Regards Jammie Quote
jammie Posted November 13, 2012 Posted November 13, 2012 @Big AL, I hadn't seen your post when I started writing mine - didn't mean to double up on the info! Using J / p x y z do you propos passing a value for J into the function? Something similat to the following? (setq msg "\nA test expression") (DEFUN c:test (<msg> / c) (SETQ c 2) (REPEAT c (PRINC <msg>) ) (princ) ) (defun c:test2 () (c:test msg) ) Quote
jammie Posted November 13, 2012 Posted November 13, 2012 (edited) @kapat Maybe try inserting your own sub to handle the formatting. See the following for an idea (defun formatNumberForNetrology (<nr> / requiredStrLength tmpStr len) ;;Set by program requirements (setq requiredStrLength 12) ;;Convert number to a string ;;And determine its length (setq tmpStr (rtos <nr> 2 4) len (strlen tmpStr)) ;;The following will suffix the ;;number with the required number of digits ;; (if (< len requiredStrLength) (repeat (- requiredStrLength len) (setq tmpStr (strcat " " tmpStr)))) ) ;;Sample calling (setq x (formatNumberForNetrology (car p1)) Edited November 13, 2012 by jammie Moved smple calling to different window for clarity purpose Quote
kapat Posted November 13, 2012 Author Posted November 13, 2012 (edited) @jammie cool! but a little above my head, i'll let you know how it works! wait... do i make this into ANOTHER lsp, or do i just insert this within my original? Edited November 13, 2012 by kapat inserted question Quote
stevesfr Posted November 13, 2012 Posted November 13, 2012 Hi Steve, I think this is the area thats causing the problem for you (setq [color="blue"][color="darkorange"]saveFile [/color][/color]"c:\\data\\design.txt") (setq MSG (strcat "\nType file or hit enter to use [" saveFile "]")) (setq [color="blue"]input [/color](getstring t MSG)) (setq file (open [color="orange"]saveFile [/color]"a")) Regards Jammie I agree Jammie, what I can't figure out is: after I enter a new file save location, how to make this new file location show up in the "saveFile" location and continue to use it when one hits Enter (if one types a new location, then it will become the new "saveFile" location. In other works, how to keep from typing the new location over and over again. I know seen this work, but I can't find an example in my stash of lisp programs. Steve Quote
jammie Posted November 13, 2012 Posted November 13, 2012 Hi Steve, I've slightly changed your code from earlier on. See if this make sense (defun c:p2frev (/ p x y z j ptcoord textloc cs_from cs_to file text) ;;If statement added (if (not saveFile) (setq saveFile "c:\\data\\design.txt") ) (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 "P"(rtos j 2 1)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") ;(setq file (open "c:\\data\\design.txt" "a")) ;(setq saveFile "c:\\data\\design.txt") <=Moved to top of code (setq MSG (strcat "\nType file or hit enter to use [" saveFile "]")) (setq input (getstring t MSG)) ;;If statement added to check input (if (not (= input "")) (setq saveFile input) ) (setq file (open saveFile "a")) (write-line ptcoord file) (close file) (setq j (+ j 1)) (princ) ) ;end while ) Quote
jammie Posted November 13, 2012 Posted November 13, 2012 @jammie cool! but a little above my head, i'll let you know how it works! wait... do i make this into ANOTHER lsp, or do i just insert this within my original? You can do either. Its probably best to keep it in the same file, outside the function and towards the start of the lisp file Quote
stevesfr Posted November 13, 2012 Posted November 13, 2012 Hi Steve, I've slightly changed your code from earlier on. See if this make sense (defun c:p2frev (/ p x y z j ptcoord textloc cs_from cs_to file text) ;;If statement added (if (not saveFile) (setq saveFile "c:\\data\\design.txt") ) (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 "P"(rtos j 2 1)" "x" "y" "z)) (command "_leader" p textloc "" ptcoord "") ;(setq file (open "c:\\data\\design.txt" "a")) ;(setq saveFile "c:\\data\\design.txt") <=Moved to top of code (setq MSG (strcat "\nType file or hit enter to use [" saveFile "]")) (setq input (getstring t MSG)) ;;If statement added to check input (if (not (= input "")) (setq saveFile input) ) (setq file (open saveFile "a")) (write-line ptcoord file) (close file) (setq j (+ j 1)) (princ) ) ;end while ) Hi Jammie..... thanks much, Perfect now ! Steve Quote
kapat Posted November 14, 2012 Author Posted November 14, 2012 @ jammie I GOT IT TO WORK! i can't believe i did it by myself [with your help, of course] but here it is: (defun c:p2f(/ p x y z j ptcoord textloc cs_from cs_to file text filename rstr space xlen ylen zlen modspace) (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 rstr 12) (setq space (strcat " ")) (setq x (rtos (car p1))) (setq y (rtos (cadr p1))) (setq z (rtos (caddr P1))) (setq xlen (strlen x)) (setq ylen (strlen y)) (setq zlen (strlen z)) (setq modspace (substr space 1 (- rstr xlen))) (setq ptcoord (strcat "PT"(rtos j 2 0)"\t" modspace x"\t" modspace y"\t" modspace z)) (command "_leader" p textloc "" ptcoord "") (setq file (open filename "a")) (write-line ptcoord file) (close file) (setq j (+ j 1)) (princ) ) ;end while ) Quote
jammie Posted November 14, 2012 Posted November 14, 2012 You are both welcome! Glad to have been able to give some pointers but great to see the two of you producing the code and figuring things out for yourselves. Keep up the good work Jammie 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.