|
Replies:
27
-
Last Post:
Apr 1, 2009 10:10 AM
Last Post By: gxash
|
|
|
Posts:
41
Registered:
07/10/03
|
|
|
|
Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 9:16 AM
|
|
|
|
Does anyone have a lisp that can quickly pick all the arcs in a drawing and indicate the radius for all the arcs?
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 1:55 PM
in response to: esoh
|
|
|
|
Here's one way:
(setq arcset (ssget "_X" '((0 . "ARC")))) (while (> (sslength arcset) 0) (setq arcrads (append arcrads (list (cdr (assoc 40 (entget (ssname arcset 0))))) ); end append ); end setq (ssdel (ssname arcset 0) arcset) ); end while
That makes a list of all the radii, and would include more than one of the same value, if there are such. If you only want to know what radii are included, listing each value only once, you could apply (vl-sort) to the resulting list.
-- Kent Cooper
esther@wohadesigns.com wrote... Does anyone have a lisp that can quickly pick all the arcs in a drawing and indicate the radius for all the arcs?
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 3:11 PM
in response to: Kent Cooper
|
|
|
|
curious as to why you'd use append and list
why not just use cons?
(setq arcrads (cons (cdr (assoc 40 (entget (ssname arcset 0)))) arcrads))
PJ
"Kent Cooper" wrote in message news:6135709@discussion.autodesk.com... Here's one way:
(setq arcset (ssget "_X" '((0 . "ARC")))) (while (> (sslength arcset) 0) (setq arcrads (append arcrads (list (cdr (assoc 40 (entget (ssname arcset 0))))) ); end append ); end setq (ssdel (ssname arcset 0) arcset) ); end while
That makes a list of all the radii, and would include more than one of the same value, if there are such. If you only want to know what radii are included, listing each value only once, you could apply (vl-sort) to the resulting list.
-- Kent Cooper
esther@wohadesigns.com wrote... Does anyone have a lisp that can quickly pick all the arcs in a drawing and indicate the radius for all the arcs?
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 5:02 PM
in response to: Princess Jamie
|
|
|
|
Because I seemed to recall one or another of the two functions having a problem if the list variable didn't exist yet at the start, so I tried a simple comparison:
Command: (cons abc 27.1) (nil . 27.1)
but
Command: (append xyz (list 27.1)) (27.1)
I didn't want the nil and the dot in the end result. I even tried repeating the (cons):
Command: (setq abcd (cons abcd 23.4)) (nil . 23.4)
Command: (setq abcd (cons abcd 33)) ((nil . 23.4) . 33)
Command: (setq abcd (cons abcd pi)) (((nil . 23.4) . 33) . 3.14159)
So I went with the (append) approach to get a clean list.
But now I realize that it was all because I put the variable that started out at nil *first* in the (cons) function. If you put it *second* after the part that's going to result in a real number, as you suggest, then (cons) works fine. The (append) approach works the same whichever order you use, but (cons) is certainly more efficient, since (append) requires you to first put whatever you add into a list of its own.
[This is why I always say "Here's one way" when I send in things like this.]
-- Kent Cooper
"Princess Jamie" wrote... curious as to why you'd use append and list
why not just use cons?
(setq arcrads (cons (cdr (assoc 40 (entget (ssname arcset 0)))) arcrads))
PJ ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 5:29 PM
in response to: Kent Cooper
|
|
|
only you won't have a nil and append is about 350 to 360 times slower than cons and foreach is 7 times the speed of while with nth http://mfgcommunity.autodesk.com/blogs/blog/view/7/Boosting_AutoLISP_Performance_2/PJ "Kent Cooper" wrote in message news:6135939@discussion.autodesk.com... Because I seemed to recall one or another of the two functions having a problem if the list variable didn't exist yet at the start, so I tried a simple comparison: Command: (cons abc 27.1) (nil . 27.1) but Command: (append xyz (list 27.1)) (27.1) I didn't want the nil and the dot in the end result. I even tried repeating the (cons): Command: (setq abcd (cons abcd 23.4)) (nil . 23.4) Command: (setq abcd (cons abcd 33)) ((nil . 23.4) . 33) Command: (setq abcd (cons abcd pi)) (((nil . 23.4) . 33) . 3.14159) So I went with the (append) approach to get a clean list. But now I realize that it was all because I put the variable that started out at nil *first* in the (cons) function. If you put it *second* after the part that's going to result in a real number, as you suggest, then (cons) works fine. The (append) approach works the same whichever order you use, but (cons) is certainly more efficient, since (append) requires you to first put whatever you add into a list of its own. [This is why I always say "Here's one way" when I send in things like this.] -- Kent Cooper "Princess Jamie" wrote... curious as to why you'd use append and list why not just use cons? (setq arcrads (cons (cdr (assoc 40 (entget (ssname arcset 0)))) arcrads)) PJ ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 6:03 PM
in response to: The Dark Princess
|
|
|
|
I don't understand what you mean by "you won't have a nil." At the first iteration, when the list variable doesn't yet exist, you will, as in my examples, which I tried specifically to check for what would happen. It's just that if you put that *first* in the (cons) function, as I did, it makes a dotted pair starting with nil, but if you put it *second*, it ignores it and puts the first value, alone, into the list and establishes the variable for subsequent iterations to add values to. -- Kent Cooper
"The Dark Princess" wrote... only you won't have a nil .... PJ
"Kent Cooper" wrote... Because I seemed to recall one or another of the two functions having a problem if the list variable didn't exist yet at the start, so I tried a simple comparison:
Command: (cons abc 27.1) (nil . 27.1) .... Command: (setq abcd (cons abcd 23.4)) (nil . 23.4) ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 6:44 PM
in response to: Kent Cooper
|
|
|
|
Kent, (cons newitem yourlist)
not
(cons yourlist newitem)
During the first loop, if yourlist is nil, it goes
(cons newitem nil) (newitem)
Hope that helps.
"Kent Cooper" wrote in message news:6136009@discussion.autodesk.com... I don't understand what you mean by "you won't have a nil." At the first iteration, when the list variable doesn't yet exist, you will, as in my examples, which I tried specifically to check for what would happen. It's just that if you put that *first* in the (cons) function, as I did, it makes a dotted pair starting with nil, but if you put it *second*, it ignores it and puts the first value, alone, into the list and establishes the variable for subsequent iterations to add values to. -- Kent Cooper
"The Dark Princess" wrote... only you won't have a nil .... PJ
"Kent Cooper" wrote... Because I seemed to recall one or another of the two functions having a problem if the list variable didn't exist yet at the start, so I tried a simple comparison:
Command: (cons abc 27.1) (nil . 27.1) .... Command: (setq abcd (cons abcd 23.4)) (nil . 23.4) ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 7:25 PM
in response to: Doug Broad
|
|
|
|
Yeah, that's exactly what I found out, but hadn't yet gotten straight in my first post. -- Kent Cooper
"Doug Broad" wrote... Kent, (cons newitem yourlist) not (cons yourlist newitem) ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 3:29 PM
in response to: Kent Cooper
|
|
|
|
Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
Check these functions within a file which contains at least a few thousand lines.
(defun StartTimer () (setq *start* (getvar "date")))
(defun EndTimer (/ end) (setq end (* 86400 (- (getvar "date") *start*))) (princ (strcat "\nTimer: " (rtos end 2 8) " seconds\n")))
;; This is slow. (defun c:ssdel ( / ss lst) (setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (while (> (sslength ss) 0) (setq lst (cons (ssname ss 0) lst)) (ssdel (ssname ss 0) ss) ) (endtimer) (princ) )
;; This is much faster. (defun c:ssrep ( / i ss lst) (setq i 0) (setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (repeat (sslength ss) (setq lst (cons (ssname ss i) lst)) (setq i (1+ i)) ) (endtimer) (princ) )
Regards Joe
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 4:14 PM
in response to: Joe Burke
|
|
|
|
Hi Joe,
I would also add that care should be taken with this destructive method, just in case something else should be done one those selected entities and taking into consideration that creating a new selection set for this purpose, would be just redundant. Otherwise, the selection set variable should be set to nil, since only 128 selection sets can be opened at one time.
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view. "Joe Burke" a écrit dans le message de news: 6135829@discussion.autodesk.com... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
Check these functions within a file which contains at least a few thousand lines.
(defun StartTimer () (setq *start* (getvar "date")))
(defun EndTimer (/ end) (setq end (* 86400 (- (getvar "date") *start*))) (princ (strcat "\nTimer: " (rtos end 2 8) " seconds\n")))
;; This is slow. (defun c:ssdel ( / ss lst) (setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (while (> (sslength ss) 0) (setq lst (cons (ssname ss 0) lst)) (ssdel (ssname ss 0) ss) ) (endtimer) (princ) )
;; This is much faster. (defun c:ssrep ( / i ss lst) (setq i 0) (setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (repeat (sslength ss) (setq lst (cons (ssname ss i) lst)) (setq i (1+ i)) ) (endtimer) (princ) )
Regards Joe
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 5:12 PM
in response to: Some Buddy
|
|
|
|
You're right, if something else needs to be done with the selection set, and can't be done with it *before* getting information out of it. Given the original question, it doesn't seem very likely in their case, but you never know. And [again, in our particular situation] I can't even begin to imagine getting anywhere near having 128 selection sets open at once, so that limitation never enters my mind, but there will be those for whom it matters. -- Kent Cooper
"Some Buddy" wrote... Hi Joe,
I would also add that care should be taken with this destructive method, just in case something else should be done one those selected entities and taking into consideration that creating a new selection set for this purpose, would be just redundant. Otherwise, the selection set variable should be set to nil, since only 128 selection sets can be opened at one time.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 6:11 PM
in response to: Kent Cooper
|
|
|
|
The way I see it, is that although this one is just a small functionality, it could end up in some other bigger and more complex function, which could create more selection sets, let aside the fact that we don't know what happened prior to this point. And let's not forget that once created, the selection sets consume temporary file slots if they are not released, therefore reducing the number of selection sets available for other functions and programs. So I think that it's good practice to set selection set variables to nil once they become useless, no matter the context.
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view. "Kent Cooper" a écrit dans le message de news: 6135958@discussion.autodesk.com... You're right, if something else needs to be done with the selection set, and can't be done with it *before* getting information out of it. Given the original question, it doesn't seem very likely in their case, but you never know. And [again, in our particular situation] I can't even begin to imagine getting anywhere near having 128 selection sets open at once, so that limitation never enters my mind, but there will be those for whom it matters. -- Kent Cooper
"Some Buddy" wrote... Hi Joe,
I would also add that care should be taken with this destructive method, just in case something else should be done one those selected entities and taking into consideration that creating a new selection set for this purpose, would be just redundant. Otherwise, the selection set variable should be set to nil, since only 128 selection sets can be opened at one time.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 5:07 PM
in response to: Joe Burke
|
|
|
|
I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 8:32 PM
in response to: Kent Cooper
|
|
|
|
Here's a library list I use - from now on I call all selsets like this:
(foreach en (selsettolist (ssget .......)) .. .. )
when you nest statements like this lisp runs very fast
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents )
running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") ))))
(if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) )
took 0.032 seconds or double the time.
PJ
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 10:36 PM
in response to: The Dark Princess
|
|
|
|
Double the time, sure, but still, under a thirtieth of a second -- I can't manage to get too worked up over that. -- Kent Cooper
"The Dark Princess" wrote... Here's a library list I use - from now on I call all selsets like this: .... when you nest statements like this lisp runs very fast .... running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way .... took 0.032 seconds or double the time. ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 11:32 PM
in response to: Kent Cooper
|
|
|
|
that wasn't the issue - it was showing a way to do it very quickly and not have to deal with a ctr overhead. your code takes 3000 times as long. pn the same .dwg (22000+ objects)
Results from the two versions:
(setq arcset (ssget "x")) (setq s2 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (while (> (sslength arcset) 0) (setq arcrads (append arcrads (list (cdr (assoc 40 (entget (ssname arcset 0))))) ); end append ); end setq (ssdel (ssname arcset 0) arcset) ); end while (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s2)) )
time to make the list - 47.68647.686 seconds - an enternity just to make a list
"Kent Cooper" wrote in message news:6136322@discussion.autodesk.com... Double the time, sure, but still, under a thirtieth of a second -- I can't manage to get too worked up over that. -- Kent Cooper
"The Dark Princess" wrote... Here's a library list I use - from now on I call all selsets like this: .... when you nest statements like this lisp runs very fast .... running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way .... took 0.032 seconds or double the time. ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 10:53 PM
in response to: The Dark Princess
|
|
|
|
Hi Princess,
I'm just curious how long takes this one:
(defun sset->list (sset) (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))) )
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136225@discussion.autodesk.com... Here's a library list I use - from now on I call all selsets like this:
(foreach en (selsettolist (ssget .......)) .. .. )
when you nest statements like this lisp runs very fast
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents )
running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") ))))
(if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) )
took 0.032 seconds or double the time.
PJ
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 11:42 PM
in response to: Some Buddy
|
|
|
|
this snippet, although extremely elegant was not as fast as the native list
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) )
0.125004 seconds
I have found that when people make claims that vlisp is much faster that they have not tested lisp code that has been optimized.
In fact,
This got the selection set and made the list faster.
Command: (progn (_> (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (_> (setq ss (ssget "x")) (_> (repeat (setq ctr (sslength ss)) ((_> (setq l1 (cons (ssname ss (setq ctr (1- ctr))) l1)) ((_> ) (_> (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) (_> ) 0.04699230
Interesting eh? That's why I use that library function all the time
PJ
"Some Buddy" wrote in message news:6136328@discussion.autodesk.com... Hi Princess,
I'm just curious how long takes this one:
(defun sset->list (sset) (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))) )
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136225@discussion.autodesk.com... Here's a library list I use - from now on I call all selsets like this:
(foreach en (selsettolist (ssget .......)) .. .. )
when you nest statements like this lisp runs very fast
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents )
running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") ))))
(if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) )
took 0.032 seconds or double the time.
PJ
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 12:25 AM
in response to: The Dark Princess
|
|
|
|
OK, this is why I wanted to know. Speaking about measuring the time, do you know about this undocumented variable called MILLISECS ?
I think that this would be easier to use for yor measurement. It keeps returning the incremented time in miliseconds, so if you make the difference between two consecutive readings, you have the elapsed time between those readings.
(setq a (getvar 'millisecs)) => 211830765
;;; do your stuff here
(setq b (getvar 'millisecs)) => 211831156
(/ (- b a) 1000.0) => 0.391
Now it's up to you to measure which method is faster ;^)
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136367@discussion.autodesk.com... this snippet, although extremely elegant was not as fast as the native list
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) )
0.125004 seconds
I have found that when people make claims that vlisp is much faster that they have not tested lisp code that has been optimized.
In fact,
This got the selection set and made the list faster.
Command: (progn (_> (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (_> (setq ss (ssget "x")) (_> (repeat (setq ctr (sslength ss)) ((_> (setq l1 (cons (ssname ss (setq ctr (1- ctr))) l1)) ((_> ) (_> (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) (_> ) 0.04699230
Interesting eh? That's why I use that library function all the time
PJ
"Some Buddy" wrote in message news:6136328@discussion.autodesk.com... Hi Princess,
I'm just curious how long takes this one:
(defun sset->list (sset) (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))) )
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136225@discussion.autodesk.com... Here's a library list I use - from now on I call all selsets like this:
(foreach en (selsettolist (ssget .......)) .. .. )
when you nest statements like this lisp runs very fast
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents )
running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") ))))
(if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) )
took 0.032 seconds or double the time.
PJ
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 2:40 AM
in response to: Some Buddy
|
|
|
:-) the best fast is the time it takes to develop. All this yen for .net and java and nothing beats lisp for development speed. http://www.paulgraham.com/avg.htmlPJ "Some Buddy" wrote in message news:6136391@discussion.autodesk.com... OK, this is why I wanted to know. Speaking about measuring the time, do you know about this undocumented variable called MILLISECS ? I think that this would be easier to use for yor measurement. It keeps returning the incremented time in miliseconds, so if you make the difference between two consecutive readings, you have the elapsed time between those readings. (setq a (getvar 'millisecs)) => 211830765 ;;; do your stuff here (setq b (getvar 'millisecs)) => 211831156 (/ (- b a) 1000.0) => 0.391 Now it's up to you to measure which method is faster ;^) Regards -- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view. "The Dark Princess" a écrit dans le message de news: 6136367@discussion.autodesk.com... this snippet, although extremely elegant was not as fast as the native list (progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) ) 0.125004 seconds I have found that when people make claims that vlisp is much faster that they have not tested lisp code that has been optimized. In fact, This got the selection set and made the list faster. Command: (progn (_> (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (_> (setq ss (ssget "x")) (_> (repeat (setq ctr (sslength ss)) ((_> (setq l1 (cons (ssname ss (setq ctr (1- ctr))) l1)) ((_> ) (_> (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) (_> ) 0.04699230 Interesting eh? That's why I use that library function all the time PJ "Some Buddy" wrote in message news:6136328@discussion.autodesk.com... Hi Princess, I'm just curious how long takes this one: (defun sset->list (sset) (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))) ) Regards -- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view. "The Dark Princess" a écrit dans le message de news: 6136225@discussion.autodesk.com... Here's a library list I use - from now on I call all selsets like this: (foreach en (selsettolist (ssget .......)) .. .. ) when you nest statements like this lisp runs very fast ;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents ) running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds. conversely writing the lisp in the classic way (progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) ) took 0.032 seconds or double the time. PJ "Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."] -- Kent Cooper "Joe Burke" wrote... Hi Kent, Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise. ....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 1:55 PM
in response to: Some Buddy
|
|
|
|
and thnx for the millisecs tip
:-)
PJ "Some Buddy" wrote in message news:6136391@discussion.autodesk.com... OK, this is why I wanted to know. Speaking about measuring the time, do you know about this undocumented variable called MILLISECS ?
I think that this would be easier to use for yor measurement. It keeps returning the incremented time in miliseconds, so if you make the difference between two consecutive readings, you have the elapsed time between those readings.
(setq a (getvar 'millisecs)) => 211830765
;;; do your stuff here
(setq b (getvar 'millisecs)) => 211831156
(/ (- b a) 1000.0) => 0.391
Now it's up to you to measure which method is faster ;^)
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136367@discussion.autodesk.com... this snippet, although extremely elegant was not as fast as the native list
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) )
0.125004 seconds
I have found that when people make claims that vlisp is much faster that they have not tested lisp code that has been optimized.
In fact,
This got the selection set and made the list faster.
Command: (progn (_> (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (_> (setq ss (ssget "x")) (_> (repeat (setq ctr (sslength ss)) ((_> (setq l1 (cons (ssname ss (setq ctr (1- ctr))) l1)) ((_> ) (_> (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) (_> ) 0.04699230
Interesting eh? That's why I use that library function all the time
PJ
"Some Buddy" wrote in message news:6136328@discussion.autodesk.com... Hi Princess,
I'm just curious how long takes this one:
(defun sset->list (sset) (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))) )
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136225@discussion.autodesk.com... Here's a library list I use - from now on I call all selsets like this:
(foreach en (selsettolist (ssget .......)) .. .. )
when you nest statements like this lisp runs very fast
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents )
running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") ))))
(if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) )
took 0.032 seconds or double the time.
PJ
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 1:57 PM
in response to: Princess Jamie
|
|
|
|
You're welcome :)
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view. "Princess Jamie" a écrit dans le message de news: 6136643@discussion.autodesk.com... and thnx for the millisecs tip
:-)
PJ "Some Buddy" wrote in message news:6136391@discussion.autodesk.com... OK, this is why I wanted to know. Speaking about measuring the time, do you know about this undocumented variable called MILLISECS ?
I think that this would be easier to use for yor measurement. It keeps returning the incremented time in miliseconds, so if you make the difference between two consecutive readings, you have the elapsed time between those readings.
(setq a (getvar 'millisecs)) => 211830765
;;; do your stuff here
(setq b (getvar 'millisecs)) => 211831156
(/ (- b a) 1000.0) => 0.391
Now it's up to you to measure which method is faster ;^)
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136367@discussion.autodesk.com... this snippet, although extremely elegant was not as fast as the native list
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) )
0.125004 seconds
I have found that when people make claims that vlisp is much faster that they have not tested lisp code that has been optimized.
In fact,
This got the selection set and made the list faster.
Command: (progn (_> (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") )))) (_> (setq ss (ssget "x")) (_> (repeat (setq ctr (sslength ss)) ((_> (setq l1 (cons (ssname ss (setq ctr (1- ctr))) l1)) ((_> ) (_> (princ (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1)) (_> ) 0.04699230
Interesting eh? That's why I use that library function all the time
PJ
"Some Buddy" wrote in message news:6136328@discussion.autodesk.com... Hi Princess,
I'm just curious how long takes this one:
(defun sset->list (sset) (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))) )
Regards
-- Humans are born with a wide horizon. As time goes by, the horizon narrows and narrows, until it becomes a point of view.
"The Dark Princess" a écrit dans le message de news: 6136225@discussion.autodesk.com... Here's a library list I use - from now on I call all selsets like this:
(foreach en (selsettolist (ssget .......)) .. .. )
when you nest statements like this lisp runs very fast
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents )
running a test on 22000+ entities in 2009 it generated the list in 0.0158 seconds.
conversely writing the lisp in the classic way
(progn (setvar "cmdecho" 0) (setq ss (ssget "x")) (setq s1 (* 86400.0 (- (getvar "date") (fix (getvar "date") ))))
(if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (progn (setq ctr 0) (repeat (sslength ss) (setq ents (cons (ssname ss ctr) ents) ctr (1+ ctr) ) ) ) ) (- (* 86400.0 (- (getvar "date") (fix (getvar "date") ))) s1) )
took 0.032 seconds or double the time.
PJ
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 11:21 AM
in response to: Kent Cooper
|
|
|
|
Hi Kent,
Agreed, given a small selection set using ssdel, versus repeat with a counter, makes no significant difference speedwise.
I was just trying to point out ssdel will be much slower than the repeat alternative given a large selection set. For instance, given the functions I posted and 8,000 lines in the drawing, the ssrep function is more than 20 times faster than the ssdel function.
I'll trade an additional variable for the speed advantage any day. :-)
Regards Joe
"Kent Cooper" wrote in message news:6135956@discussion.autodesk.com... I usually prefer the (while) and (ssdel) approach simply because it doesn't require a variable for the counter. In our application, I can't imagine processing so much information that it could possibly make any detectable difference in the time it takes, but obviously there will be those for whom it would. [Yet another reason that I usually say "Here's one way...."]
-- Kent Cooper
"Joe Burke" wrote... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
....
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 4, 2009 5:23 PM
in response to: Joe Burke
|
|
|
|
here's a tweak
(setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (repeat (setq ctr (sslength ss)) (setq xtr (1- ctr) lst (cons (ssname ss ctr) lst)) ) )
PJ
"Joe Burke" wrote in message news:6135829@discussion.autodesk.com... Hi Kent,
Aside comment, I think using ssdel to step through a selection set is not a good idea speedwise.
Check these functions within a file which contains at least a few thousand lines.
(defun StartTimer () (setq *start* (getvar "date")))
(defun EndTimer (/ end) (setq end (* 86400 (- (getvar "date") *start*))) (princ (strcat "\nTimer: " (rtos end 2 8) " seconds\n")))
;; This is slow. (defun c:ssdel ( / ss lst) (setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (while (> (sslength ss) 0) (setq lst (cons (ssname ss 0) lst)) (ssdel (ssname ss 0) ss) ) (endtimer) (princ) )
;; This is much faster. (defun c:ssrep ( / i ss lst) (setq i 0) (setq ss (ssget "_X" '((0 . "LINE")))) (starttimer) (repeat (sslength ss) (setq lst (cons (ssname ss i) lst)) (setq i (1+ i)) ) (endtimer) (princ) )
Regards Joe
|
|
|
|
|
Posts:
41
Registered:
07/10/03
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 3:09 AM
in response to: The Dark Princess
|
|
|
|
Hi all
I think the lisp is not what I was looking for. Just a brief explanation.
We are working on a project with a lot of arcs in the drawings.and we are looking for a lisp that can allows us to pick all the arcs in the drawings and the radius of each arc (as in a dim/rad) will be indicated on the drawing.
Is it possible?
Regards Esther
|
|
|
|
|
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 5:50 AM
in response to: esoh
|
|
|
(defun c:rads (/ en obj) (vl-load-com) (setq *acad* (vlax-get-acad-object) *doc* (vla-get-activedocument *acad*) )
;------------given an ss return a list-------------------- (defun selsettolist ( ss / ctr ents) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0) ) (repeat (setq ctr (sslength ss)) (setq ents (cons (ssname ss (setq ctr (1- ctr))) ents)) ) ) ents ) (defun arctgv (dxf_code list_1)
(cond ((= (type list_1) 'ENAME) (cdr (assoc dxf_code (entget list_1))) ) ((= (type list_1) 'LIST) (cdr (assoc dxf_code list_1)) ) ((= (type list_1) 'VLA-OBJECT) (if (vlax-property-available-p list_1 dxf_code) (vlax-get-property list_1 dxf_code) nil ) ) (T nil) ) ) (foreach en (selsettolist (ssget "x" (list (cons 0 "ARC")))) (setq obj (vlax-ename->vla-object en)) (vl-cmdf "_dimradius" en (vlax-curve-getpointatdist obj (/ (vlax-curve-getdistatpoint obj (vlax-curve-getendpoint obj)) 2.0))) ) ) you're welcome....:-) PJ Hi all I think the lisp is not what I was looking for. Just a brief explanation. We are working on a project with a lot of arcs in the drawings.and we are looking for a lisp that can allows us to pick all the arcs in the drawings and the radius of each arc (as in a dim/rad) will be indicated on the drawing. Is it possible? Regards Esther
|
|
|
|
|
Posts:
41
Registered:
07/10/03
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Mar 5, 2009 8:01 AM
in response to: The Dark Princess
|
|
|
|
PJ - Thank you. It is what we are looking for.
Regards Esther
|
|
|
|
|
Posts:
1
Registered:
04/01/09
|
|
|
|
Re: Lisp that can output radius for all arcs in the drawing
Posted:
Apr 1, 2009 10:10 AM
in response to: esoh
|
|
|
|
This lsp works and it snaps radius label to radius mid point, but is it possible to make it snap to the radius endpoints?
|
|
|
|
|
|