Author Topic: Quickly select contours with elevations ending in a selected number.....  (Read 2167 times)

0 Members and 1 Guest are viewing this topic.

jvillarreal

  • Bull Frog
  • Posts: 332
Hi everyone,
So I got a request to write a program to do as stated in the title...and i wrote the attached program that seemed to do the trick....up until someone needed it for a file containing 126,614 segments....it still worked, but it took about 50 seconds..at least on my computer..leaving the user wondering whether or not they should alt+ctrl+delete during the 20-30 seconds after the progress bar finishes and before the contours are gripped...Is there a quicker way to select them using lisp?

fyi: in case anybody questions some of the useless features...
     -The user requested I include options for #s 0-9 and that the contours were gripped.

pkohut

  • Guest
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #1 on: December 08, 2008, 12:00:37 PM »
String compares are usually expensive.  If you can get by
without doing them then that might help.

Suggestions:
1) Convert user entry to an INT
2) Don't convert "elev" to a string, just make it an INT
3) (setq elevn (rem elev 10))
4) compare elevn to user entered value

Paul

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #2 on: December 08, 2008, 12:36:49 PM »
Thanks for the reply Paul. I tried your suggestion and it definitely cleaned up the code by getting rid of 2 variables!
but as for the speed  :-( no luck..maybe not possible to work any faster in lisp?
Attached is the modified code..

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #3 on: December 08, 2008, 12:56:58 PM »
See if this helps.

Code: [Select]
(defun c:Test (/ Elev tempStr ss)
   
    (if
        (and
            (setq Elev (getint "\n Enter ending integer [0 - 9]: "))
            (<= 0 Elev 9)
            (setq Elev (itoa Elev))
            (setq ss (ssadd))
        )
        (vlax-for i (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object)))
            (if
                (and
                    (member (vla-get-ObjectName i) '("AcDbLine" "AcDbArc" "AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline"))
                    (setq tempStr (rtos (caddr (vlax-curve-getEndPoint i)) 2))
                    (= (substr tempStr (strlen tempStr)) Elev)
                )
                (setq ss (ssadd (vlax-vla-object->ename i) ss))
            )
        )
    )
    (if (> (sslength ss) 0)
        (sssetfirst nil ss)
    )
    (princ)
)

I couldn't get what Paul was suggesting to work.  I was trying to figure out how to not convert the objects elevation to a string for compare, but couldn't figure it out, and what was returned was a number like 0.0001 instead of just the 1.

Or I changed it once I was a little more awake, and reread your code.

Code: [Select]
(defun c:Test2 (/ Elev tempStr ss)
   
    (if
        (and
            (setq Elev
                (cond
                    ((getint "\n Select all contours with elevations ending in [0 - 9] <0>: "))
                    (t 0)
                )
            )
            (<= 0 Elev 9)
            ;(setq Elev (itoa Elev))
            (setq ss (ssadd))
        )
        (vlax-for i (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object)))
            (if
                (and
                    (member (vla-get-ObjectName i) '("AcDbLine" "AcDbArc" "AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline"))
                    ;(setq tempStr (rtos (caddr (vlax-curve-getEndPoint i)) 2))
                    ;(= (substr tempStr (strlen tempStr)) Elev)
                    (equal Elev (fix (caddr (vlax-curve-getEndPoint i))))
                )
                (setq ss (ssadd (vlax-vla-object->ename i) ss))
            )
        )
    )
    (if (> (sslength ss) 0)
        (sssetfirst nil ss)
    )
    (princ)
)
Tim

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

Please think about donating if this post helped you.

pkohut

  • Guest
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #4 on: December 08, 2008, 12:58:28 PM »
Build a selection set filter list for your first ssget
using logical groupings. Look at the "Selection Set
Filter Lists" and "Logical Grouping of Filter Test" in
the help docs for examples on how to build the filter.

Then you will be able to get rid of the whole (cond
statement and the building of the second selection
set because your first returned exactly what you
wanted.

Paul

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #5 on: December 08, 2008, 01:11:47 PM »
I forgot to add the division so that it will only return the last bit of numbers.  This one should work like you want it.

Code: [Select]
(defun c:Test3 (/ Elev tempStr ss)
   
    (if
        (and
            (setq Elev
                (cond
                    ((getint "\n Select all contours with elevations ending in [0 - 9] <0>: "))
                    (t 0)
                )
            )
            (<= 0 Elev 9)
            ;(setq Elev (itoa Elev))
            (setq ss (ssadd))
        )
        (vlax-for i (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object)))
            (if
                (and
                    (member (vla-get-ObjectName i) '("AcDbLine" "AcDbArc" "AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline"))
                    ;(setq tempStr (rtos (caddr (vlax-curve-getEndPoint i)) 2))
                    ;(= (substr tempStr (strlen tempStr)) Elev)
                    (equal Elev (rem (fix (caddr (vlax-curve-getEndPoint i))) 10))
                )
                (setq ss (ssadd (vlax-vla-object->ename i) ss))
            )
        )
    )
    (if (> (sslength ss) 0)
        (sssetfirst nil ss)
    )
    (princ)
)
Tim

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

Please think about donating if this post helped you.

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #6 on: December 08, 2008, 01:18:24 PM »
 :-o wow!! improved the speed by approx 20 seconds!! THANK YOU! You da man!

pkohut

  • Guest
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #7 on: December 08, 2008, 01:22:37 PM »
Hey T, "rem" is similar to "mod" or "modulus" in other languages.  Here is
a link to explain it a little.

Paul

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Quickly select contours with elevations ending in a selected number.....
« Reply #8 on: December 08, 2008, 01:42:31 PM »
:-o wow!! improved the speed by approx 20 seconds!! THANK YOU! You da man!
I think that is because you are only processing the objects once, instead of twice.  You're welcome.

Hey T, "rem" is similar to "mod" or "modulus" in other languages.  Here is
a link to explain it a little.

Paul
Thanks Paul.  The link didn't show up, but I can google it when I get a minute.
Tim

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

Please think about donating if this post helped you.