How to modify this lisp?

How to modify this lisp?

Anonymous
Not applicable
2,684 Views
11 Replies
Message 1 of 12

How to modify this lisp?

Anonymous
Not applicable

Hello!! My name is Bruno and is my First post here!! Smiley Happy

 

This Lisp (integral.lisp) evaluates the area of a curve (Numerical Integral) and generates a output file (CSV). I got this Lisp yesterday from Lee Mac, and I want to do some little modifications, but I don't know how. So please, if you could help me, I'll be very grateful. (watch the video to see how it works. Then I'll resume below)

 

https://youtu.be/sX3FKtfHmbc

 

 

 

 

This is how It works:
After load the Lisp, type " integrate ". Then, click on a curve (red), and click on the axis (cian). (axis = a Line with the same width of the curve [Width = "linear dimension", not the total length] , placed parallel to the curve. The same width of the curve is to get divide it into " n " uniforms divisions, as an Integral does)
Then, choose the number of divisions and press enter. So, the CSV file is generated.

 

 

I want to improve 3 things:

1-) The gray lines are created one by one. The logic of the program is begin to create the lines from start point to the end point of the axis (cian). I want to change this logic. Something like subtract the coordinates... Make the program subtracting not the end/start point, but the upper point of the lower point, or the point at right to the point more in the left, got it?

 

2-) As I said, we need a axis with the same "linear dimension" (width) of the curve. I mean, if I use a bigger line then the curve, ( or even a smaller, the calculations will be wrong. As the lisp needs to know the width, I'm thinking again in subtract the coordinates (the same I said above, Upper minus lower, or Right minus left), but the coordinates from the curve itself, not the axis.

 

3-) There is a weird bug on the code. For some reason, the Lisp isn't running fine with the curves inside the green rectangle (Open the drawning "bugs.dwg" ) attached to visualize it), but worked perfectly with the others (out of the rectangle). Why this happens? How to fix?

 

 

Thank you so much for you attention. You have no Idea on how this will help me!!! 🙂

 

 

Cheers!!

 

0 Likes
Accepted solutions (1)
2,685 Views
11 Replies
Replies (11)
Message 2 of 12

rkmcswain
Mentor
Mentor

 

Let's give @Lee_Mac first shot here   Smiley Wink

 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 12

Anonymous
Not applicable

I'd love if he would take a look, but he already make this code by himself!! Man, this lisp is awesome! I want to solve this problem by myself, to learn a little more of autolisp...

0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

3-) There is a weird bug on the code. For some reason, the Lisp isn't running fine with the curves inside the green rectangle (Open the drawning "bugs.dwg" ) attached to visualize it), but worked perfectly with the others (out of the rectangle). Why this happens? How to fix?

 

....

On that particular issue, the intersectwith method can be sensitive to the tiniest differences in postitions of things, and it could be that the calculated Y coordinate of the end of the curve that it's not drawing a line at is just short [many decimal places down] of the Y coordinate of the end of the axis, so that it doesn't find an intersection.  Just a guess [I haven't tried this] -- try changing:

 

acextendotherentity

 

to:

 

acextendboth

Kent Cooper, AIA
0 Likes
Message 5 of 12

Anonymous
Not applicable
Hello Kent Cooper

Thank you for your help. I've tried changing that line, but it doesn't worked.

The weirdest thing about this bug is that in some curves the program works perfectly every time. But there are some curves that the lisp doesn't work, after use "mirror" command, and in some curves the program always fails, and fails always the same way - The very last gray line is not generated.
0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

My next guess is that, again because of way-down-many-decimal-places-deep tiny differences in the results of calculations, the last Line is not being drawn because the 'dis' value at the end is just barely beyond the end of the axis Line.  Try this, to make it use the endpoint of the Line if that distance calculation overshoots that end:

 

;;; .... keep all the stuff before this ....
            (repeat (1+ num)
;;;                (if (setq pt1 (vlax-curve-getpointatdist axs dis))
;;; above returns nil if 'dis' overshoots the end, even minimally ;;; (progn ;;; REPLACE above two lines with: (setq pt1 (or (vlax-curve-getpointatdist axs dis) (vlax-curve-getEndPoint axs))) ;;; continue [no (progn) wrapper needed when not a 'then'/'else' argument in (if) function]: (setq tmp (entmakex ;;; .... keep all the stuff in here .... ) (entdel tmp) ;;; ); progn [no longer needed] ;;; ); if (setq dis (+ dis inc)) ); repeat ;;; .... keep all the stuff after this ....
Kent Cooper, AIA
Message 7 of 12

Anonymous
Not applicable
Hi Kent.
I get your point about the decimal places.... I'm really sure that this is the problem issue.

And about the code you've posted earlier, it doesn't work for me. Also, this message appears when I use the code:

Command: INTEGRATE

Select curve to 'integrate':
Select axis:
Specify number of divisions <10>: 10

Error: bad argument type: listp T

Personally, I never saw it. What could it be?
0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
....
Error: bad argument type: listp T
....

Sorry -- my mistake.  The (or) function doesn't return the value in expressions in it, just T or nil.  The listp in the error message is because something that's looking for a point [a list of coordinates] is getting the T from that (or) function instead.  Do this instead:

  (setq pt1 (cond ((vlax-curve-getpointatdist axs dis)) ((vlax-curve-getEndPoint axs))))

Kent Cooper, AIA
Message 9 of 12

Anonymous
Not applicable
HAHAHA YESSS!!!!!! 🙂

Kent, I've changed that line and now the lisp is running fine.
It doesn't works with all curves yet (For example, in my dwg file attached above, the first drawing inside the green rectangle - red arc - is with the same bug).
Others, however, that before had the error, they are now ok (For example, the 2 drawing inside the green rectangle, below the red arc)

I think that it is fine to me, Thank you very much for your help, you were very kind!!!
However, before to close the topic, do you have a last shot to fix the error on the red arc?
0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:
.... before to close the topic, do you have a last shot to fix the error on the red arc?

The only thing I can think of is that the top end of the axis Line, again to a very tiny degree, overshoots the level of the top end of the curve.  I suppose the routine could be forced to make that truly line up, if that's the cause.  But trying that by grip-editing the Line with the .Y point filter to force its top end to match the Y coordinate of the top of the curve, it still didn't work, and their original bounding box upper bounds are the same down to as many significant figures as AutoCAD can handle, so presumably that's not the issue.

 

If you can ensure that the vertical extent of both curve and axis Line will match [within whatever small tolerance works for you], maybe it could be made to just draw a Line between the ends of each, rather than draw the last Line in the same fashion as the others.  Considering the tiny differences involved, that would probably give you just as good results.

Kent Cooper, AIA
Message 11 of 12

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... it could be made to just draw a Line between the ends of each, rather than draw the last Line in the same fashion as the others. ....


Here's a version that does it that way [at both ends just in case, not just the last Line], in limited testing [successfully for me, in all the situations in your sample drawing].

Kent Cooper, AIA
Message 12 of 12

Anonymous
Not applicable
I couldn't be happier, Kent!!

Your improvements are awesome! You are awesome!!
Thank you very much!!
0 Likes