Author Topic: QUICK TEXT LISP ROUTINE NEEDED  (Read 7770 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #15 on: January 18, 2010, 05:48:00 PM »
When in a loop that pauses for user input there is no time penalty, so what is the harm?

I've read (from one of Kerry's posts) that every time you call it, it increments the reference count of the object, and you have to call vlax-release-object the same amount of times to release it - or until the ACAD Garbage collection does so. So I avoid calling it excessively.

rhino

  • Guest
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #16 on: January 18, 2010, 09:56:22 PM »
Quote
Hi Rhino,

I have just tidied up your routine a bit, I hope you don't mind:

not at all - i'll just add the fac variable to it - thanks! I have much to learn  8-)

Lee I think he wants is a companion routine to reverse the process.
Or at lease some undo marks.  
I could be mistaken. 8-)


PS I like the vl version when dealing with COLOR. :-)

I like the vlisp version too.

@CAB
I don't want a separate func to reverse the process - the vl-undo works well but after you exit the loop/function

i'd like it to work within the loop itself - as a user  might click some text string like those under the grid line column...

lee's routine is fine otherwise - and has thought me quite a bit.

Thanks 

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #17 on: January 18, 2010, 10:22:24 PM »
Alan, I would be inclined to save the vla-ActiveDocument as a variable, instead of calling vlax-get-acad-object over and over  :wink:



Lee,
You could try something like this, which saves a few process ticks ...
Code: [Select]
(vl-load-com)
(or *AcadApplication
    (setq *AcadApplication (vlax-get-acad-object))
)
(OR *activeDocument
    (SETQ *activeDocument (VLA-GET-ACTIVEDOCUMENT *AcadApplication))
)

Then just use the variable.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #18 on: January 18, 2010, 11:21:25 PM »
When in a loop that pauses for user input there is no time penalty, so what is the harm?

I've read (from one of Kerry's posts) that every time you call it, it increments the reference count of the object, and you have to call vlax-release-object the same amount of times to release it - or until the ACAD Garbage collection does so. So I avoid calling it excessively.
I don't think it's that big a deal in this case. As with many things it depends where you use them.
In a loop dealing with user input the loop will not be executed much compared to a sub function that may executed a 1000 times or more.
Take a look at this thread:  http://www.theswamp.org/index.php?topic=2005.msg25790#msg25790

All I am saying is that I pick & choose when  & where I use a variable that can be released. 8-)

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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #19 on: January 19, 2010, 04:03:24 AM »
Alan, I would be inclined to save the vla-ActiveDocument as a variable, instead of calling vlax-get-acad-object over and over  :wink:



Lee,
You could try something like this, which saves a few process ticks ...
Code: [Select]
(vl-load-com)
(or *AcadApplication
    (setq *AcadApplication (vlax-get-acad-object))
)
(OR *activeDocument
    (SETQ *activeDocument (VLA-GET-ACTIVEDOCUMENT *AcadApplication))
)

Then just use the variable.


Thanks Kerry - thats pretty much what I have used in my example above  :wink:

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #20 on: January 19, 2010, 04:04:45 AM »
When in a loop that pauses for user input there is no time penalty, so what is the harm?

I've read (from one of Kerry's posts) that every time you call it, it increments the reference count of the object, and you have to call vlax-release-object the same amount of times to release it - or until the ACAD Garbage collection does so. So I avoid calling it excessively.
I don't think it's that big a deal in this case. As with many things it depends where you use them.
In a loop dealing with user input the loop will not be executed much compared to a sub function that may executed a 1000 times or more.
Take a look at this thread:  http://www.theswamp.org/index.php?topic=2005.msg25790#msg25790

All I am saying is that I pick & choose when  & where I use a variable that can be released. 8-)

I tend to just stick to a way of doing things - I realise performance doesn't matter here, but if you can get better performance, why not  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #21 on: January 19, 2010, 08:46:54 AM »
That's true. I suppose that it was lazy of me to just cut & paste those items from my template file and knowing
it met minimum requirements figured it was OK. Knowing that everyone that looks at the code doesn't know the
rules behind some of the things done makes this a bad example.
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: QUICK TEXT LISP ROUTINE NEEDED
« Reply #22 on: January 19, 2010, 11:19:48 AM »
Another approach  8-)

Code: [Select]
(defun c:ft nil (c:fixtext))

(defun c:fixtext (/ *error*

                    CODE DATA ENT GR LAST_ENT MSG NUM OBJ OCM UFLAG)

  ;; Lee Mac  ~  19.01.10
  (vl-load-com)

  (defun *error* (msg)
    (and uFlag (vla-EndUndoMark *doc))
    (and ocm   (setvar "CMDECHO" ocm))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ))

  (setq  ocm (getvar "CMDECHO")

        *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))
        *fac (cond (*fac) (1.1))

        *fac (cond ((getreal (strcat "\nSpecify Factor <" (rtos *fac 2 2) "> : "))) (*fac)))
 
  (setvar "CMDECHO" 0)

  (princ (eval (setq msg '(strcat "\n<< Current Factor: " (rtos *fac 2 2) ">>"
                                  "\nSelect Text, [F]actor [U]ndo <Exit> : "))))
                   
  (while
    (progn
      (setq gr (grread 't 15 2) code (car gr) data (cadr gr))

      (cond (  (and (= 3 code) (listp data))

               (if (setq ent (car (nentselp data)))

                 (if (and (vl-position (cdr (assoc 0 (entget ent))) '("TEXT" "MTEXT"))
                          (numberp (setq num (distof (cdr (assoc 1 (entget ent)))))))
                   (progn
                     (setq uFlag (not (vla-StartUndoMark *doc)) last_ent (cons ent last_ent))

                     (vla-put-TextString
                       (setq obj (vlax-ename->vla-object ent)) (rtos (* *fac num) 2 2))

                     (vla-put-color obj 1)
                     (setq uFlag (vla-EndUndoMark *doc)) t)

                   (princ (strcat "\n** Object Must be Numerical Text **" (eval msg))))

                 (princ (strcat "\n** Nothing Selected **" (eval msg)))))

            (  (= code 25) nil)

            (  (= code 2)

               (cond (  (vl-position data '(85 117))

                        (if last_ent (vl-cmdf "_.undo" 1)
                          (princ (strcat "\n** Nothing to Undo **" (eval msg))))

                        (setq last_ent (cdr last_ent)) t)                     

                     (  (vl-position data '(70 102))

                        (setq *fac (cond ((getreal (strcat "\nSpecify Factor <" (rtos *fac 2 2) "> : ")))

                                         (*fac)))

                        (princ (eval msg)))

                     (  (vl-position data '(13 32)) nil)

                     (t )))

            (t ))))
 

  (and ocm (setvar "CMDECHO" ocm))
  (princ))
« Last Edit: January 19, 2010, 11:29:15 AM by Lee Mac »