TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on December 08, 2010, 05:46:14 PM
-
Help will be appreciated
I am trying to code a lisp to add numbers in an attribute
(defun c:test () (vl-load-com)
(if (not NumStrt) (setq NumStrt "1"))
(setq oldStart NumStrt)
(setq NumStrt (getint "\nSpecify start number < 1 >: "))
(setq NumMlt (getint "\nSpecify Multiable number < 1 >: "))
(while
(if (and
(setq att (car (nentsel "\nSelect attribute OR Text: ")))
(setq el (entget att))
)
(progn
(vla-put-TextString (vlax-ename->vla-object el) NumStrt)
(setq NumStrt (+ NumStrt NumMlt))
)
))
)
-
You're trying to feed TextString an integer when it needs a string. Your variables are not localized. Your subject line: http://www.catb.org/~esr/faqs/smart-questions.html
This might help:
http://www.theswamp.org/index.php?topic=518.msg397071#msg397071
http://www.theswamp.org/index.php?topic=32788.msg382652#msg382652
http://www.theswamp.org/index.php?topic=28727.0
-
and you aren't testing to ensure you have an annotative object.
and the functionName is unimaginative .. perhaps use something like DoIt instead :lol:
sorry, couldn't help myself !
-
and you aren't testing to ensure you have an annotative object.
and the functionName is unimaginative .. perhaps use something like DoIt instead :lol:
sorry, couldn't help myself !
FWIW ... here's some comments:
(defun c:doit (/ att el oldstart)
;;nummlt <--Global if you want it to remember
;;numstrt <--Global if you want it to remember
(vl-load-com)
;;Set to integer rather than string. OR evaluates until non nil and it drives se7en mad :)
(or numstrt (setq numstrt 1))
(or nummlt (setq nummlt 1))
;;Where is oldstart being used?
;;(setq oldstart numstrt)
;;Check to make sure nummlt is set or it will bonk (should be set with defaults
(if (and (setq numstrt (cond ((getint (strcat "\nSpecify start number <" (itoa numstrt) ">: ")))
;;If enter is pressed the default value is used
(numstrt)
)
)
(setq nummlt (cond ((getint (strcat "\nSpecify Multiable number <" (itoa nummlt) ">: ")))
;;If enter is pressed the default value is used
(nummlt)
)
)
)
(while
(if (and (setq att (car (nentsel "\nSelect attribute OR Text: "))) (setq el (entget att)))
;;Check object type passed so it wont $h|+ the bed
(if (wcmatch (cdr (assoc 0 el)) "*TEXT,ATTRIB")
(progn (vla-put-textstring
;;Changed EL to ATT you need an ename to convert to vla-object not an entity list
(vlax-ename->vla-object att)
;;Convert integer to string with ITOA
(itoa numstrt)
)
(setq numstrt (+ numstrt nummlt))
)
(princ "\nObject selected not text or attribute!")
)
)
)
)
;;Add for clean exit
(princ)
)
And you could use this to account for missed picks:
http://www.theswamp.org/index.php?topic=6992.msg93574#msg93574
-
OR evaluates until non nil and it drives se7en mad :)
:-D
-
OR evaluates until non nil and it drives se7en mad :)
:-D
That reminds me, I need to have some more t-shirts printed
-
OR evaluates until non nil and it drives se7en mad :)
:-D
That reminds me, I need to have some more t-shirts printed
I want a large :-D
-
here is an oldie but goodie...
use it to renumber existing dtext "numbers" by entered value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; Renumber DText Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun NUMIT (/ ed es er)
(setq Ed nil
NUM nil
)
(setq NUM
(atoi
(getstring
"\n* Enter Number: <enter> for default of \"1000\" *"
)
)
)
(if (= NUM 0)
(setq NUM 1000)
)
(while NUM
(NUM-IT)
(setq ER (atoi (cdr (assoc 1 (entget ED)))))
(setq ES (rtos (+ ER NUM) 2 0))
(setq ED (subst (cons 1 ES) (assoc 1 (entget ED)) (entget ED)))
(entmod ED)
(prompt (strcat "\n* Text Renumbered to : " ES " *"))
)
(princ)
)
(defun NUM-IT ()
(setq ED (car (nentsel "\n* Select DText to Renumber *")))
(if (= ED nil)
(progn
(alert "NOTHING SELECTED")
(NUM-IT)
)
)
(while (/= "TEXT" (cdr (assoc 0 (entget ED))))
(princ "\n* Selected entity is not a TEXT *")
(NUM-IT)
)
(princ)
)
-
OR evaluates until non nil and it drives se7en mad :)
:-D
That reminds me, I need to have some more t-shirts printed
Six in X-large please :evil:
-
one dozen XL Size Please :-) :wink:
-
one dozen XL Size Please :-) :wink:
Did you get anything instructive out of my post or were you just looking for someone to write it for you?
-
...
Did you get anything instructive ...
Your post is very usefull but I didnt give any reply because I am trying to study the other rplies, links and adding the some addition like header, errorhandler, etc .... then upload to check.
Thanks
-
...
Did you get anything instructive ...
Your post is very usefull but I didnt give any reply because I am trying to study the other rplies, links and adding the some addition like header, errorhandler, etc .... then upload to check.
Thanks
Good deal ... happy coding :-)
-
.....
Good deal ... happy coding :-)
In fact it is first time for me to understand vla-put-textstring
Thanks
-
OR evaluates until non nil and it drives se7en mad :)
:-D
That reminds me, I need to have some more t-shirts printed
:-D
-
OR evaluates until non nil and it drives se7en mad :)
:-D
That reminds me, I need to have some more t-shirts printed
:-D
Alright, now you're just using OR on purpose.
And for the record I only have a problem with how you are using it (global vars; recalling previous entries is good in all...in moderation. and if you eliminate the need for global vars you can use the SETQ-COND construct). But part of this gets into that localization-global vars discussion where we "discovered" that there really isnt anything like "hygienic variable declaration" in AutoLisp so i'll leave you guys alone.
T-Shirts?! Haven't I spawned two now?
-
Oh and BTW, if you really want to make me angry keep coming up with well thought out thread-subject-lines like this one.
:)~
-
Oh and BTW, if you really want to make me angry keep coming up with well thought out thread-subject-lines like this one.
:)~
LoL