Thousands of intersections

Thousands of intersections

Rob_Durham
Enthusiast Enthusiast
4,789 Views
64 Replies
Message 1 of 65

Thousands of intersections

Rob_Durham
Enthusiast
Enthusiast

Hi,

 

I am trying to get AutoCAD to draw a great many circles of differing radii with the centre point of the circles at a common foci point along the semi-major axis of an ellipse. The radius of all the circles are such that they will intersect the ellipse at some point.

 

The XYZ coordinates of these intersections are ultimately what I want to extract using AutoCADs data extraction utility.

 

I have successfully used Lee Macs intersections Lisp routine to draw ‘points’ at these intersections however it doesn’t like it when I have thousands of circles….it just crashes.

 

;; Intersections in Set  -  Lee Mac
;; Returns a list of all points of intersection between all objects in a supplied selection set.
;; sel - [sel] Selection Set

(defun LM:intersectionsinset ( sel / id1 id2 ob1 ob2 rtn )
    (repeat (setq id1 (sslength sel))
        (setq ob1 (vlax-ename->vla-object (ssname sel (setq id1 (1- id1)))))
        (repeat (setq id2 id1)
            (setq ob2 (vlax-ename->vla-object (ssname sel (setq id2 (1- id2))))
                  rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn)
            )
        )
    )
    (apply 'append (reverse rtn))
)

(defun LM:intersections ( ob1 ob2 mod / lst rtn )
    (if (and (vlax-method-applicable-p ob1 'intersectwith)
             (vlax-method-applicable-p ob2 'intersectwith)
             (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
        )
        (repeat (/ (length lst) 3)
            (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
                  lst (cdddr lst)
            )
        )
    )
    (reverse rtn)
)

(defun c:interset ( / sel )
    (if (setq sel (ssget))
        (foreach pnt (LM:intersectionsinset sel)
            (entmake (list '(0 . "POINT") (cons 10 pnt)))
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

 

Since I don’t ultimately need the circles (only the intersection points they make with the ellipse) I thought I would try using the lisp below to delete the last circle drawn (actually the second to last entity after the ‘point’) which seems to work if I run it manually. This way, the first lisp routine only needs to find one intersection each time.

 

 

(defun countback(steps / ms)
(vl-load-com)
(setq ms (vla-get-modelspace (vla-get-activedocument
(vlax-get-acad-object))))
(vlax-vla-object->ename (vla-item ms (- (vla-get-count ms) steps)))
)
 (command ".erase" (countback 2) "")
(princ)

 

 

The trouble is I am using a copy paste method from excel to the command line to draw the circles. I thought I would try and also call the above routines from the spreadsheet but I can’t seem to get it to work, it will draw the points at the intersections but then won’t delete the last circle drawn.

 

Capture.JPG

 

Since I’m no expert in Lisp and I found both of these routines on the web, can someone possibly a) help me combine them into 1 lisp adding the erase command to delete the 2nd to last entity (countback 2) or b) suggest a better way of doing this whole process?

 

Thanks in advance

 

Rob

0 Likes
Accepted solutions (1)
4,790 Views
64 Replies
Replies (64)
Message 21 of 65

Kent1Cooper
Consultant
Consultant

@roland.r71 wrote:

@Kent1Cooper wrote:

Or:

 

(setq lastCirc (entlast))


I tried that first, but doesn't work, as it is an entity, not a selectionset. (so erase says: *invalid selection*)

.... So, you need to turn it into a set. Which i did 😉


It may not matter at this point, but....  It certainly works for me to use (entlast).  You [at least I] can give individual entity names to object-selection prompts in editing commands, and I do it often -- they don't require only selection sets.  I wonder what's different with your setup, or whether you might have typed a variable name a little differently, or....

Kent Cooper, AIA
0 Likes
Message 22 of 65

john.uhden
Mentor
Mentor

I agree with @Kent1Cooper.  With respect to commands that take selections, it matters not whether the selection is a selection set or a single entity name.

John F. Uhden

0 Likes
Message 23 of 65

roland.r71
Collaborator
Collaborator

@Kent1Cooper wrote:

@roland.r71 wrote:

@Kent1Cooper wrote:

Or:

 

(setq lastCirc (entlast))


I tried that first, but doesn't work, as it is an entity, not a selectionset. (so erase says: *invalid selection*)

.... So, you need to turn it into a set. Which i did 😉


It may not matter at this point, but....  It certainly works for me to use (entlast).  You [at least I] can give individual entity names to object-selection prompts in editing commands, and I do it often -- they don't require only selection sets.  I wonder what's different with your setup, or whether you might have typed a variable name a little differently, or....


When used with (command ...) it works.

Straight from the commandline it doesn't.

 

I do believe i just messed up with methods... as using (ssget "L") gets me the same result at the moment as the entget did before.

I've been testing by

1. typing the command and values directly,

2. using (command ...)

3. using the lisp file

 

Possibly i tested the ssget using the (command ...) method & tested the entget straight from the command line.

 

& i forgot to use "all" as selection for the interset function...

 

All in all not having my best day Smiley Sad

 

 

Command: (setq lastCirc (entlast))
<Entity name: 7ff7341fe320>
Command: ERASE
Select objects: lastCirc
*Invalid selection*
Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SIngle/SUbobject/Object
Select objects: *Cancel*
Command: (command "erase" lastCirc "")
erase
Select objects:   1 found
Select objects:
Command:
0 Likes
Message 24 of 65

Rob_Durham
Enthusiast
Enthusiast

Ok I have set the routine off drawing the points and although it hasn't crashed, it is very slow.

 

I understand that it is executing a number of commands but it'd be nice if it was a bit faster.

 

Its currently up to about 15,000 points and has been running about 20 minutes.

 

Probably wishful thinking and perhaps I'm being over ambitious but can it be sped up?

0 Likes
Message 25 of 65

roland.r71
Collaborator
Collaborator

@Rob_Durham wrote:

Ok I have set the routine off drawing the points and although it hasn't crashed, it is very slow.

 

I understand that it is executing a number of commands but it'd be nice if it was a bit faster.

 

Its currently up to about 15,000 points and has been running about 20 minutes.

 

Probably wishful thinking and perhaps I'm being over ambitious but can it be sped up?


Yes, but ...

For that you need to compile the lisp file.

 

edit:

Possibly you can speed it up by using a script too, instead of an excel file to call the commands.
(it would surprise me if it didn't, but i never used excel that way with AutoCAD, so i can't say it will)

0 Likes
Message 26 of 65

Kent1Cooper
Consultant
Consultant

@roland.r71 wrote:
....

When used with (command ...) it works.

Straight from the commandline it doesn't.

 

....

Hmmm....  It also works for me to give (entlast) to a typed-in editing command's object-selection prompt at the command line.

Kent Cooper, AIA
0 Likes
Message 27 of 65

Rob_Durham
Enthusiast
Enthusiast

Can you estimate by how much compiling the code will speed it up? 50%?

0 Likes
Message 28 of 65

roland.r71
Collaborator
Collaborator

@Kent1Cooper wrote:

@roland.r71 wrote:
....

When used with (command ...) it works.

Straight from the commandline it doesn't.

 

....

Hmmm....  It also works for me to give (entlast) to a typed-in editing command's object-selection prompt at the command line.


Yes, same here

Command: ERASE
Select objects: (entlast)
<Entity name: 7ff7341fe420>
1 found
Select objects:

but if you catch the entlast in a variable and pass the variable, it will not accept the variable as a selection.

0 Likes
Message 29 of 65

Anonymous
Not applicable

How many objects are in your drawing not including points?

0 Likes
Message 30 of 65

Rob_Durham
Enthusiast
Enthusiast

Just the ellipse!

0 Likes
Message 31 of 65

Anonymous
Not applicable

Can you post it and the excel so I can take a look?

0 Likes
Message 32 of 65

Rob_Durham
Enthusiast
Enthusiast

Here you go.

 

BTW it crashed after approximately 25,000 points....and it was doing so well!

 

The ellipse was drawn with the pellipse system variable set to 1 so its actually a polyline....cut in half!

 

 

0 Likes
Message 33 of 65

roland.r71
Collaborator
Collaborator

@Rob_Durham wrote:

Can you estimate by how much compiling the code will speed it up? 50%?


I realy couldn't say. Although 50% should be easy to achieve.

...but i think in your situation the excel file is a bigger bottleneck.

 

A script/lisp file with the commands would most likely run a lot faster. Especially if you have hundreds (if not thousands) of circles to calculate the intersections for in this way. However, that's a choice between ease of use & editing .vs. processing speed.

0 Likes
Message 34 of 65

Anonymous
Not applicable

He's copying and pasting which is essentially the same as if he made a script. Compiling wouldn't speed it up that drastically either. The think that's slowing it down the most is physically drawing the circle and having to delete it.

0 Likes
Message 35 of 65

roland.r71
Collaborator
Collaborator

@Rob_Durham wrote:

Here you go.

 

BTW it crashed after approximately 25,000 points....and it was doing so well!

 

The ellipse was drawn with the pellipse system variable set to 1 so its actually a polyline....cut in half!

 

 


Did AutoCAD realy crash, or does windows just think it's "not responding"?

If its the latter, just ignore windows. Smiley Wink

0 Likes
Message 36 of 65

Rob_Durham
Enthusiast
Enthusiast

I was monitoring the memory usage in task manager and it appeared to freeze, whereas before it was constantly changing. I was also unable to maximise ACAD from my taskbar any longer whereas I could up until about 25,000 points.

0 Likes
Message 37 of 65

john.uhden
Mentor
Mentor

When you type in a symbol name in response to a command prompt you must prefix the name with an exclamation point, "!"...

 

Command: erase

"Select objects: " !lastcirc

 

whereas, as part of a lisp statement, you don't use the prefix...

(command ".erase" lastcirc "")

John F. Uhden

0 Likes
Message 38 of 65

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

He's copying and pasting which is essentially the same as if he made a script. Compiling wouldn't speed it up that drastically either. The think that's slowing it down the most is physically drawing the circle and having to delete it.


In that case it wouldn't matter much, no, but I'm not so sure about that.

Since calculating 1 circle's intersections with 1 ellipse does not take 20+ minutes ... neither does it generate 25.000 points in a single go...

& that's what it does with the excel. Create a circle. Calculate intersections. create a circle, calc. intersection, create circle, ... etc.etc.

 

So, It sounds to me he's using the excel like a batch, which means there's an interpretor/compiler inbetween. (which slows things down)

... but then again, i've been wrong before today 😛

0 Likes
Message 39 of 65

john.uhden
Mentor
Mentor

Try adding a (gc) into your function.

 

Or, maybe creating and deleting circles is too much activity.  How about using one circle and moving it around, not via the MOVE command but by changing its center location either via entmod or active-x property.

 

Or both.

John F. Uhden

0 Likes
Message 40 of 65

roland.r71
Collaborator
Collaborator

@john.uhden wrote:

When you type in a symbol name in response to a command prompt you must prefix the name with an exclamation point, "!"...

 

Command: erase

"Select objects: " !lastcirc

 

whereas, as part of a lisp statement, you don't use the prefix...

(command ".erase" lastcirc "")


Yep. Tried it & works.

Well, at least (1 of) my reason for trying to help others is validated.

It helps ME to learn more 😉

0 Likes