Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

number lisp question

15 REPLIES 15
Reply
Message 1 of 16
brockh
798 Views, 15 Replies

number lisp question

I am making my own autonumber lisp and it seems to work good but for somereason when I try to use it on a textstyle that is tt arial it only gives me a dash. I am using autocad 2007. When I use the standard textstyle it works great. Any help would be great. Thanks.

(defun C:nn (/ inc start)
(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
(while T
(command "text" "j" "c" pause "" pause start)
(setq start (+ start inc))
);;while
)
15 REPLIES 15
Message 2 of 16
brockh
in reply to: brockh

OK after further research it seems there is not a prompt for the text height if the style is set a height. Is there a way around this. use this if it has a height. Can anyone point me in the right direction? Thanks
Message 3 of 16
Anonymous
in reply to: brockh

Use the following to collect each text style (setq
style_tbl(tblnext"style"))
Then check the 40 dxf code (setq style_ht(cdr(assoc 40 style_tbl)))
If the result = zero, then there is no text height in the style (if (zerop
style_ht)(progn...))

Paul

wrote in message news:5375034@discussion.autodesk.com...
OK after further research it seems there is not a prompt for the text height
if the style is set a height. Is there a way around this. use this if it
has a height. Can anyone point me in the right direction? Thanks
Message 4 of 16
brockh
in reply to: brockh

This is more complex than I have done before. I appreciate your help. I think I am close but Im doing something wrong. Any words of advice would be greatly appreciated.

(defun C:nn (/ inc style_tbl style_ht start)

(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblnext"style"))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop

(if
(zerop style_ht)

(while T
(command "text" "j" "c" pause "" pause start)
(setq start (+ start inc))
);End while
(progn)
(while T
(command "text" "j" "c" pause pause start)
(setq start (+ start inc))
);End while

);End IF
);End Defun
Message 5 of 16
brockh
in reply to: brockh

(defun C:nn (/ inc style_tbl style_ht start)

(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblnext"style"))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop

(if
(zerop style_ht)

(while T
(command "text" "j" "c" pause pause start)
(setq start (+ start inc))
);End while
(progn
(while T
(command "text" "j" "c" pause "" pause start)
(setq start (+ start inc))
);End while

);End Progn
);End IF
)
Message 6 of 16
brockh
in reply to: brockh

Sorry I posted that too soon. I think I am very close now. Can you show me the error in my ways. Sorry about the excess post


(defun C:nn (/ inc style_tbl style_ht start)

(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblnext"style"))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop
(if
(zerop style_ht)

(progn
(while T
(command "text" "j" "c" pause "" pause start)
(setq start (+ start inc))
);End while
);End Progn
(progn
(while T
(command "text" "j" "c" pause pause start)
(setq start (+ start inc))
);End while

);End Progn
);End IF
)
Message 7 of 16
Anonymous
in reply to: brockh

ok, the function you really need inlieu of (setq style_tbl(tblnext"style"))
is to find out if the current default text style has a height value:

(setq style_tbl(tblsearch"style"(getvar"textstyle")))

Paul

wrote in message news:5375096@discussion.autodesk.com...
Sorry I posted that too soon. I think I am very close now. Can you show me
the error in my ways. Sorry about the excess post


(defun C:nn (/ inc style_tbl style_ht start)

(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblnext"style"))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop
(if
(zerop style_ht)

(progn
(while T
(command "text" "j" "c" pause "" pause start)
(setq start (+ start inc))
);End while
);End Progn
(progn
(while T
(command "text" "j" "c" pause pause start)
(setq start (+ start inc))
);End while

);End Progn
);End IF
)
Message 8 of 16
brockh
in reply to: brockh

Hey that does the trick. thanks. I learned alot from your help thanks again
Message 9 of 16
brockh
in reply to: brockh

Here is the finished code. It works GREAT. The old one I had would mess up if the ucs wasnt world but this is perfect I got it to only prompt for text height. Again thanks a million.

;-----------------------------------------------------------------------------
;***************************** seq ******************************************
;*****************************************************************************
;-----------------------------------------------------------------------------
(defun C:seq (/ inc style_tbl style_ht textht start)
;Gets info
(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblsearch"style"(getvar"textstyle")))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop
(if
(zerop style_ht)

(progn
(setq textht (getstring "\Enter Text Height:"))
(while T
(command "text" "j" "c" pause textht pause start)
(setq start (+ start inc))
);End while
);End Progn
(progn
(while T
(command "text" "j" "c" pause pause start)
(setq start (+ start inc))
);End while

);End Progn
);End IF
);End Defun
Message 10 of 16
Anonymous
in reply to: brockh

Excellent ! ! !
Now to make sure this routine works on all language versions of AutoCAD,
precede all AutoCAD commands with an underscore "_".
To also force the original AutoCAD command to be issued in case another
function undefined the command, precede the command with a period ".".
ie:
(command "_.text" "_j" "_c" pause textht pause start)

Paul

wrote in message news:5375147@discussion.autodesk.com...
Here is the finished code. It works GREAT. The old one I had would mess up
if the ucs wasnt world but this is perfect I got it to only prompt for text
height. Again thanks a million.

;-----------------------------------------------------------------------------
;***************************** seq
******************************************
;*****************************************************************************
;-----------------------------------------------------------------------------
(defun C:seq (/ inc style_tbl style_ht textht start)
;Gets info
(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblsearch"style"(getvar"textstyle")))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop
(if
(zerop style_ht)

(progn
(setq textht (getstring "\Enter Text Height:"))
(while T
(command "text" "j" "c" pause textht pause start)
(setq start (+ start inc))
);End while
);End Progn
(progn
(while T
(command "text" "j" "c" pause pause start)
(setq start (+ start inc))
);End while

);End Progn
);End IF
);End Defun
Message 11 of 16
tader1
in reply to: brockh

(while testexpr [expr...])

The while function continues until testexpr is nil.

I don't think you need a (while T
Message 12 of 16
tader1
in reply to: brockh

this will quit the loop if there's no value for getpoint:

(defun C:seq (/ inc style_tbl style_ht textht start)
;Gets info
(setq start (getint "\nStarting number:")
inc (getint "\nSet Increment value: ")
)
;checks if text height is fixed
(setq style_tbl(tblsearch"style"(getvar"textstyle")))
(setq style_ht(cdr(assoc 40 style_tbl)))
;Starts if text height fixed


;start loop
(if
(zerop style_ht)

(progn
(setq textht (getstring "\Enter Text Height:"))
(while (setq pt (getpoint "\nPick Point for text"))
(command "text" "j" "c" pt textht pause start)
(setq start (+ start inc)))
(princ))

(progn
(while (setq pt (getpoint "\nPick Point for text"))
(command "text" "j" "c" pt pause start)
(setq start (+ start inc)))))
(princ))
Message 13 of 16
tader1
in reply to: brockh

here's on I did, same principle just a few more options-maybe it'll give ya some ideas.

(defun c:seq (/ *error* ent ans dis point1 point start)
(setq oldos (getvar "osmode"))

(defun *error* (msg)
(cond
((or (not msg)
(member msg '("console break" "Function cancelled" "quit / exit abort")
))(setvar "osmode" oldos))

((princ (strcat "\nError: " Msg))
(setvar "osmode" oldos)
)))
(setq start (getint "\nEnter Starting Point #"))
(initget "I S P")
(setq ans (getkword "\nSequetial Numbering Program \nInsert text / Select text / Paragraph numbering :"))

(cond ((= ans "S")
(print "Select text")
(while (= (cdr (assoc 0 (setq ent (entget (car (entsel)))))) "TEXT")
(setq ent (subst (cons '1 (strcat (rtos start 2 0) ".")) (assoc 1 ent) ent))
(entmod ent)
(entupd (cdr (nth 0 ent)))
(setq start (1+ start))))

((= ans "P")
(setvar "osmode" 64)
(setq dis (getdist "\nEnter offset distance or Pick two points"))

(while
(setq point (getpoint "\nPick displacement point"))
(setq point1 (polar point pi dis))

(command "text" point1 "" (strcat (rtos start 2 0) "."))
(setq start (1+ start))))

((= ans "I")
(while
(setq point (getpoint "n\Pick text placement point :"))
(command "text" point 0 start)
(setq start (1+ start))))))
Message 14 of 16
tader1
in reply to: brockh

fixed a couple things.
(defun c:seq (/ *error* ent ans dis point1 point start)
(setq oldos (getvar "osmode"))

(defun *error* (msg)
(cond
((or (not msg)
(member msg '("console break" "Function cancelled" "quit / exit abort")
))(setvar "osmode" oldos))

((princ (strcat "\nError: " Msg))
(setvar "osmode" oldos)
)))
(setq start (getint "\nEnter Starting Point #"))
(initget "I S P")
(setq ans (getkword "\nSequetial Numbering Program \nInsert text / Select text / Paragraph numbering :"))

(cond ((= ans "S")
(print "Select text")
(while (= (cdr (assoc 0 (setq ent (entget (car (entsel)))))) "TEXT")
(setq ent (subst (cons '1 (strcat (rtos start 2 0) ".")) (assoc 1 ent) ent))
(entmod ent)
(entupd (cdr (nth 0 ent)))
(setq start (1+ start))))

((= ans "P")
(setvar "osmode" 64)
(setq dis (getdist "\nEnter offset distance or Pick two points"))

(while
(setq point (getpoint "\nPick displacement point"))
(setq point1 (polar point pi dis))

(command "text" point1 "" (strcat (rtos start 2 0) "."))
(setq start (1+ start))))

((= ans "I")
(while
(setq point (getpoint "n\Pick text placement point :"))
(command "text" point 0 start)
(setq start (1+ start))))))
Message 15 of 16
tader1
in reply to: brockh

thought i did
(defun c:seq (/ *error* ent ans dis point1 point start)
(setq oldos (getvar "osmode"))

(defun *error* (msg)
(cond
((or (not msg)
(member msg '("console break" "Function cancelled" "quit / exit abort")
))(setvar "osmode" oldos))

((princ (strcat "\nError: " Msg))
(setvar "osmode" oldos)
)))
(initget 1)
(setq start (getint "\nEnter Starting Point #"))
(initget "I S P")
(setq ans (getkword "\nSequetial Numbering Program \nInsert text / Select text / Paragraph numbering :"))

(cond ((= ans "S")
(print "Select text")
(while (= (cdr (assoc 0 (setq ent (entget (car (entsel)))))) "TEXT")
(setq ent (subst (cons '1 (strcat (rtos start 2 0) ".")) (assoc 1 ent) ent))
(entmod ent)
(entupd (cdr (nth 0 ent)))
(setq start (1+ start))))

((= ans "P")
(setvar "osmode" 64)
(setq dis (getdist "\nEnter offset distance or Pick two points"))

(while
(setq point (getpoint "\nPick displacement point"))
(setq point1 (polar point pi dis))

(command "text" point1 "" (strcat (rtos start 2 0) "."))
(setq start (1+ start))))

((= ans "I")
(while
(setq point (getpoint "\nPick text placement point :"))
(command "text" point 0 start)
(setq start (1+ start)))))
(*error* nil))
Message 16 of 16
brockh
in reply to: brockh

Hey thanks alot everyone. I appreciate the input. This was a great Lisp to help me learn. That was my first if statement and I am now understanding the condition on this one. Again thanks alot.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost