Jump to content

Recommended Posts

Posted

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))
)

  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

  • jammie

    12

  • kapat

    12

  • stevesfr

    7

  • BIGAL

    3

Top Posters In This Topic

Posted

@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

Posted

jammie & BIGAL.... thanks guys.... all is fine now... due to your help

Steve

Posted

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.

Posted

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.
Posted

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
)

Posted

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

Posted

@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)
 )

Posted (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 by jammie
Moved smple calling to different window for clarity purpose
Posted (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 by kapat
inserted question
Posted
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

Posted

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
)

Posted
@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

Posted
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

Posted

@ 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
)

Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...