Author Topic: vLISP vs VBA performance gap  (Read 9378 times)

0 Members and 1 Guest are viewing this topic.

Chuck Gabriel

  • Guest
vLISP vs VBA performance gap
« on: May 24, 2007, 09:51:24 PM »
I was just wondering if anybody could explain to me why the following lisp code takes somewhere between ten and twenty times as long to execute as the roughly equivalent VBA code below it.

Code: [Select]
;;Erase all text entities with null values

(defun c:EraseEmptyText (/ count)

  (startUndo)  ;; defined externally
  (setq count 0)
  (vlax-for block (vla-get-blocks *ThisDrawing*)
    (vlax-for ent block
      (if (and
    (vlax-property-available-p ent 'TextString)
    (setq txtVal (vla-get-textstring ent))
    (or
      (= "" txtVal)
      (= " " txtVal)
      (= "  " txtVal)
      (= "\\A1;" txtVal)
    )
  )
(progn
  (setq count (1+ count))
  (vla-erase ent)
)
      )
    )
  )
  (endUndo) ;; defined externally
 
  (princ (strcat (itoa count) " blank text entities erased."))
  (princ)
)

Code: [Select]
Option Explicit

Private Const ERR_METHOD_NOT_SUPPORTED As Long = 438

Sub EraseEmptyText()
  On Error GoTo ERROR_HANDLER
 
  Dim count As Long
  count = 0
  ThisDrawing.StartUndoMark
  Dim block As AcadBlock
  For Each block In ThisDrawing.Blocks
    Dim ent As AcadEntity
    For Each ent In block
      Dim txtVal As String
      txtVal = ent.TextString
      If txtVal = vbNullString Or _
      txtVal = "\\A1;" Or _
      txtVal = " " Or _
      txtVal = "  " Then
        count = count + 1
        ent.Erase
      End If
NOT_APPLICABLE:
    Next ent
    Set ent = Nothing
  Next block
  Set block = Nothing
  ThisDrawing.EndUndoMark
  ThisDrawing.Utility.Prompt CStr(count) & " blank text entities erased."

  Exit Sub

ERROR_HANDLER:

  Select Case Err
    Case ERR_METHOD_NOT_SUPPORTED
      Resume NOT_APPLICABLE
    Case Else
      Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
  End Select
End Sub

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: vLISP vs VBA performance gap
« Reply #1 on: May 24, 2007, 10:50:42 PM »
Don't know.
Is this any faster?
Code: [Select]
(defun c:EraseEmptyText (/ ss)
  (and
    (setq ss (ssget "_X"
                    '((0 . "*text")
                      (-4 . "<or")
                      (1 . ",")
                      (1 . "{}")
                      (1 . "{ }")
                      (1 . "{  }")
                      (-4 . "or>")
                     )
             )
    )
    (mapcar 'entdel (mapcar 'cadr (ssnamex ss)))
  )
  (princ)
)
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.

LE

  • Guest
Re: vLISP vs VBA performance gap
« Reply #2 on: May 24, 2007, 11:46:45 PM »
Chuck;

Might be, because that code is trying to erase empty text from blocks (not the model or paper) and it is not possible to access them, because that property is in the attributes.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #3 on: May 25, 2007, 12:02:56 AM »
Don't know.
Is this any faster?
Code: [Select]
(defun c:EraseEmptyText (/ ss)
  (and
    (setq ss (ssget "_X"
                    '((0 . "*text")
                      (-4 . "<or")
                      (1 . ",")
                      (1 . "{}")
                      (1 . "{ }")
                      (1 . "{  }")
                      (-4 . "or>")
                     )
             )
    )
    (mapcar 'entdel (mapcar 'cadr (ssnamex ss)))
  )
  (princ)
)

Sorry.  I should have mentioned this before.  I started out using selection sets, but switched to iterating the database to solve a problem that I now realize actually had nothing to do with how I was collecting the objects I wanted to work with.

Thanks for the nudge CAB.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #4 on: May 25, 2007, 12:08:16 AM »
Chuck;

Might be, because that code is trying to erase empty text from blocks (not the model or paper) and it is not possible to access them, because that property is in the attributes.

Yes, I actually gave that possibility some thought, but decided to ignore it until I have worked out some other issues.

The reason I'm even doing this is that I've recently been experiencing a renewed fascination with LISP, so I've attempting to make improvements to some old routines (like this one) that don't work exactly like I'd prefer.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vLISP vs VBA performance gap
« Reply #5 on: May 25, 2007, 01:29:46 AM »
......................
The reason I'm even doing this is that I've recently been experiencing a renewed fascination with LISP, so I've attempting to make improvements to some old routines .................

now, THAT is interesting. ! :-)

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.

VVA

  • Newt
  • Posts: 166
Re: vLISP vs VBA performance gap
« Reply #6 on: May 25, 2007, 03:22:10 AM »
Quote
Might be, because that code is trying to erase empty text from blocks (not the model or paper) and it is not possible to access them, because that property is in the attributes.
First variant, Erase empty text from model, layouts, blocks and cleare atribute
Code: [Select]
;_Unformat Mtext
(defun mip_MTEXT_Unformat ( Mtext / text Str )(setq Text "")
   (while (/= Mtext "")(cond
          ((wcmatch (strcase (setq Str (substr Mtext 1 2))) "\\[\\{}]")
            (setq Mtext (substr Mtext 3) Text   (strcat Text Str)))
          ((wcmatch (substr Mtext 1 1) "[{}]")(setq Mtext (substr Mtext 2)))
          ((wcmatch (strcase (setq Str (substr Mtext 1 2))) "\\[LO`~]")
   (setq Mtext (substr Mtext 3)))
          ((wcmatch (strcase (substr Mtext 1 2)) "\\[ACFHQTW]")
            (setq Mtext (substr Mtext (+ 2 (vl-string-search ";" Mtext)))))
          ((wcmatch (strcase (substr Mtext 1 2)) "\\P")
            (if (or(= " " (substr Text (strlen Text)))
   (= " " (substr Mtext 3 1)))
               (setq Mtext (substr Mtext 3))
               (setq Mtext (substr Mtext 3) Text (strcat Text " "))))
  ((wcmatch (strcase (substr Mtext 1 2)) "\\S")
            (setq Str   (substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
                  Text  (strcat Text (vl-string-translate "#^\\" "/^\\" Str))
                  Mtext (substr Mtext (+ 4 (strlen Str)))))
  (t (setq Text (strcat Text (substr Mtext 1 1)) Mtext (substr Mtext 2)))
  )) Text)
(defun EraseEmptyText (Doc / tempObjType tempValue count)
  (vl-load-com)(setq count 0)
  (vlax-for Blk (vla-get-blocks Doc)
    (if (= (vla-get-isxref Blk) :vlax-false)
      (vlax-for Obj Blk
        (setq tempObjType (vla-get-objectname Obj))
        (cond
          ((vl-position tempObjType '("AcDbText" "AcDbMText"))
           (setq
             tempValue (mip_MTEXT_Unformat (vla-get-textstring Obj))
           ) ;_Remove formatting Mtext
           (setq tempValue (vl-string-trim " \t\n" tempValue)) ;_Remove space, tab
           (if (and
                 (vl-position tempValue '("" "," ".")) ;_Pattern for remove
                 (vlax-write-enabled-p Obj)
               ) ;_ end of and
             (progn
               (vla-delete obj)
               (setq count (1+ count))
             )
           ) ;_ end of if
          )
          ((= tempObjType "AcDbBlockReference")
           (foreach Att (append (vlax-invoke Obj 'GetAttributes)(vlax-invoke Obj 'GetConstantAttributes))
             (setq
               tempValue (mip_MTEXT_Unformat (vla-get-textstring Att))
             ) ;_Remove formatting Mtext
             (setq tempValue (vl-string-trim " \t\n" tempValue)) ;_Remove space, tab
             (if (and
                   (vl-position tempValue '("" "," ".")) ;_Pattern for remove
                   (vlax-write-enabled-p Att)
                 ) ;_ end of and
               (progn
               (vla-put-textstring Att "")
                (setq count (1+ count))
               )
             ) ;_ end of if
           ) ;_ end of foreach
          )
          (t nil)
        ) ;_cond
      ) ;_ end of vlax-for
    ) ;_ end of if
  ) ;_ end of vlax-for
  (princ (strcat "\nDeleted " (itoa count) " empty text in blocks, texts or atributes"))
) ;_ end of defun
(defun c:EraseEmptyText ( )
  (EraseEmptyText (vla-get-activedocument (vlax-get-acad-object)))
  (princ)
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: vLISP vs VBA performance gap
« Reply #7 on: May 25, 2007, 07:35:50 AM »
Now that's a robust routine VVA.  :-)
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.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #8 on: May 25, 2007, 07:39:19 AM »
......................
The reason I'm even doing this is that I've recently been experiencing a renewed fascination with LISP, so I've attempting to make improvements to some old routines .................

now, THAT is interesting. ! :-)


Have I given the impression that I am a LISP hater in the past?  If I did, I was just teasing.  In reality, I'm just a pragmatist.  Once I had learned VBA (to make GUI programming easier), I tended to use it even for non-GUI work simply because the paradigms had become so familiar (path of least resistance you know).  Lately though, I've begun to take an interest in LISP's unique qualities.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: vLISP vs VBA performance gap
« Reply #9 on: May 25, 2007, 08:06:28 AM »
If it's a robust GUI your looking for - that you can use with lisp - look no further:

http://sourceforge.net/projects/opendcl

 :wink:

jb
James Buzbee
Windows 8

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #10 on: May 25, 2007, 08:23:42 AM »
I think I have settled on this:

Code: [Select]
(defun c:EraseEmptyText (/ selSet)
  (startUndo)
  (setq selSet (ssget "X"
      '((-4 . "<OR")
(-4 . "<AND")
(0 . "*TEXT")
(-4 . "<OR")
(1 . "")
(1 . " ")
(1 . "  ")
(-4 . "OR>")
(-4 . "AND>")
(-4 . "<AND")
(0 . "MTEXT")
(1 . "\\A1;")
(-4 . "AND>")
(-4 . "OR>")
       )
       )
  )
  (princ
    (strcat
      "\n"
      (itoa
(cond
  (selSet
   (mapcar 'entdel (mapcar 'cadr (ssnamex selSet)))
   (sslength selSet)
  )
  (T 0)
)
      )
      " blank text entities erased.\n"
    )
  )
  (endUndo)
  (princ)
)

The thing I don't like about it is, technically you could have a line of text that was nothing but 100 spaces, and this routine wouldn't pick it up.  With the database iteration method, since you test each TextString value manually rather than filtering for specific ones, you can do a test like the following, but it's probably too expensive to justify.

Code: [Select]
(= 0
 (length
   (vl-remove-if
     '(lambda (x)
(= x 32)
      )
     (vl-string->list txtVal)
   )
 )
)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: vLISP vs VBA performance gap
« Reply #11 on: May 25, 2007, 08:32:32 AM »
This is what I use:

Code: [Select]
(defun c:delnul (/ ss)
  (if (setq ss (ssget "x" '((0 . "text") (1 . ", ,%%u,%%U"))))
    (mapcar '(lambda (x)
       (vla-delete
(vlax-ename->vla-object x)
       )
     )
    (mapcar 'cadr (ssnamex ss))
    )
  )
  (princ)
)

I don't think this deletes everything (per thread somewhere else...and limited testing):

(mapcar 'entdel (mapcar 'cadr (ssnamex selSet)))

*edit* Found it:

http://www.theswamp.org/index.php?topic=12771.msg179567#msg179567

Ron
« Last Edit: May 25, 2007, 08:36:32 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #12 on: May 25, 2007, 08:37:19 AM »
I don't think this deletes everything (per thread somewhere else...and limited testing):

(mapcar 'entdel (mapcar 'cadr (ssnamex selSet)))


I have seen some inconsistent behavior with entdel (plus entmod and a few others), but I figured I could swap in something like the lambda function you used if I started seeing significant failures.  Using equivalent VLISP functions in place of standard AutoLISP functions has remedied past issues like that for me.

BTW, thanks for the input and pointers everybody.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #13 on: May 25, 2007, 09:04:34 AM »
Chuck;

Might be, because that code is trying to erase empty text from blocks (not the model or paper) and it is not possible to access them, because that property is in the attributes.

I guess you could change this

Code: [Select]
(vlax-property-available-p ent 'TextString)

to this

Code: [Select]
(and
  (vlax-property-available-p ent 'TextString)
  (not (vlax-property-available-p ent 'PromptString))
)

to get around that problem.

Attribute references shouldn't be a problem, because you can't get at them just by iterating over the database.  You have to call vla-GetAttributes on the block references they belong to.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #14 on: May 25, 2007, 09:52:14 AM »
I changed my mind again.  Here is what I've ended up with.  I seems like a good compromise between completeness and speed (which is only an issue on really big drawings with lots of text).

Code: [Select]
(defun c:EmptyText (/ count selSet index text txtVal)
  (startUndo)
  (setq count  0
selSet (ssget "x" '((0 . "*TEXT")))
index  (if selSet
(sslength selSet)
0
       )
  )
  (while (> index 0)
    (setq index (1- index)
  text (vlax-ename->vla-object
   (ssname selSet index)
)
  txtVal (vla-get-textstring
   text
)
    )
    (if
      (or
(= 0 (strlen txtVal))
(= "\\A1;" txtVal)
(= " " txtVal)
(= "  " txtVal)
(= 0
   (length
     (vl-remove-if
       '(lambda (x)
  (= x 32)
)
       (vl-string->list txtVal)
     )
   )
)
      )
       (progn
(setq count (1+ count))
(vla-erase text)
       )
    )
  )
  ;|
  (mapcar '(lambda (entName)
     (setq text   (vlax-ename->vla-object entName)
   txtVal (vla-get-textstring
    text
  )
     )
     (if
       (or
(= 0 (strlen txtVal))
(= "\\A1;" txtVal)
(= " " txtVal)
(= "  " txtVal)
(= 0
    (length
      (vl-remove-if
'(lambda (x)
   (= x 32)
)
(vl-string->list txtVal)
      )
    )
)
       )
(progn
  (setq count (1+ count))
  (vla-erase text)
)
     )
   )
  (mapcar 'cadr (ssnamex selSet))
  )
  |;
  (endUndo)
  (princ
    (strcat "\n" (itoa count) " blank text entities erased.")
  )
  (princ)
)

I left some commented code in there to show another approach I investigated using mapcar instead of a while loop.  The performance of the two approaches seems to be about even, but the while loop is more easily understandable to my C and Basic hardwired mind.  It's hard for me to think in LISP, but I guess I should try to get used to it if I ever want to be any good at it.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vLISP vs VBA performance gap
« Reply #15 on: May 25, 2007, 10:35:30 AM »
<Quick2>Hi Chuck, some quick code to muse --

Code: [Select]
(defun c:DeleteEmptyText ( / ss count i )

    (StartUndo)
   
    (setq count 0)

    (if (setq ss (ssget "x" '((0 . "text,mtext")(1 . ", ,\\A1;"))))
        (repeat (setq i (sslength ss))
            ;;  trap unsuccessful deletion because
            ;;  object is on a locked layer
            (if (entdel (ssname ss (setq i (1- i))))
                (setq count (1+ count))
            )                                   
        )
    )
   
    (princ
        (strcat
            (itoa count)
            " blank text entity(s) erased."
        )
    )
   
    (EndUndo)
   
    (princ)
   
)

Edit: Revised to reflect entdel on a layer locked entity doesn't chuck a wobbly, just doesn't result in successful deletion.

Cheers and hi all.</Quick2>
« Last Edit: May 25, 2007, 10:56:42 AM by MP »
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #16 on: May 25, 2007, 10:58:29 AM »
Thanks MP.

I never considered (and didn't pick up on it in ronjonp's post) that you could provide a comma-delimited list of string values for group code 1 in the filter.  I routinely do that for group code 0, but for some reason it didn't click that I could apply the same technique in other ways.  Also, I think I'll incorporate a vl-catch-all-apply to trap unexpected errors like you did above.

I decided to only filter for entity type, and then manually examine the textstring values, so that I could catch lines of text consisting of an arbitrary number of spaces.

Thanks again for all the support everybody.

Oh yeah.  Also, thanks CAB for showing me that wildcards can be used in filter criteria.  I don't believe I've ever seen that trick before.
« Last Edit: May 25, 2007, 11:01:50 AM by Chuck Gabriel »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vLISP vs VBA performance gap
« Reply #17 on: May 25, 2007, 11:06:03 AM »
If you wanted to go the ActiveX way with lisp, and only wanted items of text within the spaces (tabs) like you get with 'ssget', then I would have coded it differently.  I would use this
Code: [Select]
(vlax-for Lo (vla-get-Layouts *ThisDrawing*)
 (vlax-for Obj (vla-get-Block Lo)
   .......
  )
)
I think this way is better because I have had problems (and has been pointed out by others) with trying to use 'entdel' on objects in other spaces than the one calling the routine.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #18 on: May 25, 2007, 11:22:06 AM »
If you wanted to go the ActiveX way with lisp, and only wanted items of text within the spaces (tabs) like you get with 'ssget', then I would have coded it differently.  I would use this
Code: [Select]
(vlax-for Lo (vla-get-Layouts *ThisDrawing*)
 (vlax-for Obj (vla-get-Block Lo)
   .......
  )
)
I think this way is better because I have had problems (and has been pointed out by others) with trying to use 'entdel' on objects in other spaces than the one calling the routine.

That would certainly cut down on the amount of iteration required.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vLISP vs VBA performance gap
« Reply #19 on: May 25, 2007, 11:28:45 AM »
If you were going activex, a quick bash ...

Code: [Select]
(defun c:DeleteEmptyText ( / count )

    (StartUndo)
   
    (setq count 0)
   
    (vlax-for layout
   
        (vlax-get
            (vlax-get
                (vlax-get-acad-object)
                'ActiveDocument
            )
           'Layouts
        )
   
        (vlax-for object (vlax-get layout 'Block)
       
            (if
           
                (and
                    (wcmatch
                        (vlax-get object 'ObjectName)
                        "AcDbText,AcDbMText"
                    )
                    (wcmatch
                        (vlax-get object 'TextString)
                        ", ,\\A1;"
                    )
                )   
               
                ;;  here we do have to trap an error
                ;;  unless we've unlocked all layers
                ;;  prior to running the routine
               
                (vl-catch-all-apply
                   '(lambda ( )
                        (vlax-invoke object 'Delete)
                        (setq count (1+ count))
                    )
                )
            )
        )
    )   

    (princ
        (strcat
            (itoa count)
            " empty text entities erased."
        )
    )
   
    (EndUndo)
   
    (princ)
   
)

Untested but should work. To answer the inevitable "Why vlax versus vla?" question in advance, I found when doing objectdbx stuff way back that on average vlax calls executed faster than equivalent vla calls. How much I don't recall, but it was enough to make me use the former in code that does a lot of iteration through collections et al.
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: vLISP vs VBA performance gap
« Reply #20 on: May 25, 2007, 11:32:17 AM »
By taking again the filter MP's selection

Code: [Select]
(defun c:DeleteEmptyText(/ sel)
  (if (ssget "x" '((0 . "text,mtext")(1 . ", ,\\A1;")))
    (progn
      (vla-erase (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))))
      (vla-delete sel)
    )
  )
)

@+

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vLISP vs VBA performance gap
« Reply #21 on: May 25, 2007, 11:34:44 AM »
<snip>
Untested but should work. To answer the inevitable "Why vlax versus vla?" question in advance, I found when doing objectdbx stuff way back that on average vlax calls executed faster than equivalent vla calls. How much I don't recall, but it was enough to make me use the former in code that does a lot of iteration through collections et al.
Thanks for this little tidbit Michael.  I never knew that one.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vLISP vs VBA performance gap
« Reply #22 on: May 25, 2007, 11:38:24 AM »
By taking again the filter MP's selection ...

For the record I think it was Mr. Tanzillo who first revealed the succinct filter string of  ", " for nabbing null text.

I like the compact code Patrick but I'd guess it will crash if any null text entities reside on locked layers.

=)
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vLISP vs VBA performance gap
« Reply #23 on: May 25, 2007, 11:39:52 AM »
Thanks for this little tidbit Michael.  I never knew that one.

You're very welcome Tim. If I know you you're testing the claim right now.

:lmao:
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: vLISP vs VBA performance gap
« Reply #24 on: May 25, 2007, 11:46:20 AM »
Very cool thread guys!!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Patrick_35

  • Guest
Re: vLISP vs VBA performance gap
« Reply #25 on: May 25, 2007, 11:48:04 AM »
Quote
I like the compact code Patrick but I'd guess it will crash if any null text entities reside on locked layers.
*
Yes, exactly
A corrected version

Code: [Select]
(defun c:DeleteEmptyText(/ sel)
  (if (ssget "x" '((0 . "text,mtext")(1 . ", ,\\A1;")))
    (progn
      (vlax-map-collection (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) '(lambda (x) (vl-catch-all-apply 'vla-delete (list x))))
      (vla-delete sel)
    )
  )
)

@+

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vLISP vs VBA performance gap
« Reply #26 on: May 25, 2007, 12:09:02 PM »
Thanks for this little tidbit Michael.  I never knew that one.

You're very welcome Tim. If I know you you're testing the claim right now.

:lmao:
Nothing to see here, move along.  :roll:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: vLISP vs VBA performance gap
« Reply #27 on: May 25, 2007, 01:04:37 PM »
One more version:
Code: [Select]
(defun c:DeleteEmptyText (/ ss)
  (and
    (setq ss (ssget "x" '((0 . "text,mtext") (1 . ", ,\\A1;"))))
    (mapcar '(lambda (x) (vl-catch-all-apply 'vla-delete
                         (list (vlax-ename->vla-object x))))
          (mapcar 'cadr (ssnamex ss)))
  )
)
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.

Chuck Gabriel

  • Guest
Re: vLISP vs VBA performance gap
« Reply #28 on: May 25, 2007, 01:20:15 PM »
Wow!  That is one thoroughly skinned cat!

I didn't realize the true power of ", " when I first saw it.  I thought it would grab null strings and strings with a value of " ", but it will actually grab any string that is either null or made entirely of spaces.  That is awesome!

This really has been a great thread.  I've learned a lot.  Thanks again everybody.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vLISP vs VBA performance gap
« Reply #29 on: May 25, 2007, 01:28:38 PM »
re: ", " ... as noted previously, another great tip you can attribute to Tony.

re: Error trapping the attempt to delete on an entity by entity basis can yield a significant performance hit. An alternative is to delete only those (matching) entities that reside on unlocked layers (quick knock off):

Code: [Select]
(defun c:DeleteEmptyText ( / count doc selection )

    (setq count 0)

    (vlax-for layer
   
        (vlax-get
            (setq doc (vlax-get (vlax-get-acad-object) 'ActiveDocument))
           'Layers
        )
       
        (if
            (and
                (zerop (vlax-get layer 'Lock))
                (ssget "x"
                    (list
                       '(0 . "text,mtext")
                       '(1 . ", ,\\A1;")
                        (cons 8 (vlax-get layer 'Name))
                    )
                )
            )
            (progn
                (setq count
                    (+ count
                        (vla-get-count
                            (setq selection
                                (vlax-get doc 'ActiveSelectionset)
                            )
                        )
                    )       
                )
                (vlax-invoke selection 'Erase)
                (vlax-invoke selection 'Delete)
            )   
        )
    )
   
    (princ
        (strcat
            (itoa count)
            " empty text entity(s) erased."
        )
    )
   
    (princ)

)

Subtitle: Smaller isn't always better.

:)
« Last Edit: May 25, 2007, 01:55:05 PM by MP »
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst