TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on December 08, 2010, 05:46:14 PM

Title: Whats wrong with this lisp?
Post 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
Code: [Select]
(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))
)
      ))
  )
Title: Re: Whats wrong with this lisp?
Post by: ronjonp on December 08, 2010, 05:57:56 PM
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
Title: Re: Whats wrong with this lisp?
Post by: Kerry on December 08, 2010, 06:43:13 PM

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 !
Title: Re: Whats wrong with this lisp?
Post by: ronjonp on December 08, 2010, 06:49:52 PM

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:

Code: [Select]
(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
Title: Re: Whats wrong with this lisp?
Post by: Lee Mac on December 08, 2010, 06:51:47 PM
Code: [Select]
OR evaluates until non nil and it drives se7en mad :)

 :-D
Title: Re: Whats wrong with this lisp?
Post by: Kerry on December 08, 2010, 06:54:06 PM
Code: [Select]
OR evaluates until non nil and it drives se7en mad :)

 :-D

That reminds me, I need to have some more t-shirts printed
Title: Re: Whats wrong with this lisp?
Post by: ronjonp on December 08, 2010, 07:00:11 PM
Code: [Select]
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
Title: Re: Whats wrong with this lisp?
Post by: GDF on December 08, 2010, 07:12:13 PM
here is an oldie but goodie...

use it to renumber existing dtext "numbers" by entered value

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; 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)
)
Title: Re: Whats wrong with this lisp?
Post by: CAB on December 09, 2010, 12:18:10 AM
Code: [Select]
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:
Title: Re: Whats wrong with this lisp?
Post by: HasanCAD on December 09, 2010, 08:03:14 AM
one dozen XL Size Please  :-)  :wink:
Title: Re: Whats wrong with this lisp?
Post by: ronjonp on December 09, 2010, 10:06:28 AM
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?
Title: Re: Whats wrong with this lisp?
Post by: HasanCAD on December 09, 2010, 11:19:30 AM
...
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
Title: Re: Whats wrong with this lisp?
Post by: ronjonp on December 09, 2010, 11:21:29 AM
...
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  :-)
Title: Re: Whats wrong with this lisp?
Post by: HasanCAD on December 09, 2010, 11:24:47 AM
.....
Good deal ... happy coding  :-)

In fact it is first time for me to understand vla-put-textstring
Thanks
Title: Re: Whats wrong with this lisp?
Post by: alanjt on December 09, 2010, 11:36:24 AM
Code: [Select]
OR evaluates until non nil and it drives se7en mad :)

 :-D

That reminds me, I need to have some more t-shirts printed

:-D
Title: Re: Whats wrong with this lisp?
Post by: JohnK on December 09, 2010, 03:26:02 PM
Code: [Select]
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?
Title: Re: Whats wrong with this lisp?
Post by: JohnK on December 09, 2010, 03:28:26 PM
Oh and BTW, if you really want to make me angry keep coming up with well thought out thread-subject-lines like this one.


:)~
Title: Re: Whats wrong with this lisp?
Post by: alanjt on December 09, 2010, 03:29:04 PM
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