Author Topic: Whats wrong with this lisp?  (Read 6461 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1420
Whats wrong with this lisp?
« 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))
)
      ))
  )

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Whats wrong with this lisp?
« Reply #1 on: December 08, 2010, 05:57:56 PM »
« Last Edit: December 08, 2010, 06:09:28 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Whats wrong with this lisp?
« Reply #2 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 !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Whats wrong with this lisp?
« Reply #3 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
« Last Edit: December 08, 2010, 06:59:48 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Whats wrong with this lisp?
« Reply #4 on: December 08, 2010, 06:51:47 PM »
Code: [Select]
OR evaluates until non nil and it drives se7en mad :)

 :-D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Whats wrong with this lisp?
« Reply #5 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
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Whats wrong with this lisp?
« Reply #6 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

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Whats wrong with this lisp?
« Reply #7 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)
)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Whats wrong with this lisp?
« Reply #8 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:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Whats wrong with this lisp?
« Reply #9 on: December 09, 2010, 08:03:14 AM »
one dozen XL Size Please  :-)  :wink:

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Whats wrong with this lisp?
« Reply #10 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?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Whats wrong with this lisp?
« Reply #11 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

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Whats wrong with this lisp?
« Reply #12 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  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Whats wrong with this lisp?
« Reply #13 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

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Whats wrong with this lisp?
« Reply #14 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
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox