Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Making a script that automatically trims back intersection lines

10 REPLIES 10
Reply
Message 1 of 11
JBW_AIScripts
285 Views, 10 Replies

Making a script that automatically trims back intersection lines

I am attempting to create a script that detects intersecting lines on a specified layer (in the code it is "LED PATH") and removes a specified amount of length from deadends in intersections. I want it to be able to work on a filtered selection and have some tolerance for line ends not being exactly on the crossing line.

For example:

Before

JBW_AIScripts_0-1735675982918.png

After

JBW_AIScripts_1-1735676088437.png

 

I have comments in my attempted code that explains my thought process for how to achieve my desired results but the syntax is all messed up.

 

I think the biggest problems I am facing involve the syntax for creating a polygon point list to check for intersecting lines and if the lines are far enough away to stop trimming. I suspect I can't call commands inside a function that returns a value directly to another command, and also that my point list loop is not using "append" correctly.

 

Thanks for any help or insights you can offer!

Labels (1)
10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: JBW_AIScripts

A couple of things....

I think you can do without the (splp) function, if you use LENGTHEN with the Delta option and with a negative Delta value.  LENGTHEN won't make a Spline longer, but it will make it shorter.  That would mean you don't need to check whether an object is a Spline, but could just use what you have in the 'else' argument in (pacman) for any object type.  Without studying it in detail, I think it would just mean reversing the arguments in the (angle) function in setting the 'dir' variable.

But if you keep the (splp) function, yes, the syntax is wrong in using it.  This:

(setq outlist splp(obj pt1))

should have one of its parentheses in a different place:

(setq outlist (splp obj pt1))

[I haven't studied (pacman) and its application enough to say whether there might be a better way to find what it's made to look for.]

A small thing:  This, for setting the negative Delta value in LENGTHEN:

(- 0 (/ td p))

can be simply:

(- (/ td p))

A (-) function with only one argument makes the negative of that argument, without the need to explicitly subtract it from zero.

In your R shape in the drawing, the P-shaped red part is a Polyline that dead-ends on itself.  Is it going to be a problem that searching around that endpoint finds something but not a different something than the object in question?  [Maybe I can figure that out if I study (pacman) further.]

In the (repeat) function that starts at line 42, you have (if) functions that are given more than the maximum two arguments they can take.  You need some (progn) wrappers to make some of those multiple operations into single arguments.

Kent Cooper, AIA
Message 3 of 11
JBW_AIScripts
in reply to: Kent1Cooper

Thanks for your reply! That is a big help. I knew about the (progn ) wrappers but I totally forgot to apply them there. Good catch!

 

I came up with the "pacman" shape for the selection window in order to exclude the end of the line to be trimmed from the selection, thus being able to detect itself for intersections, as you noted in the "P" shape in the "R." In order for it to really work, the selection window needs that tiny bit of separation from the end it is checking to make sure it is not crossing that end. Also, the circular part of the shape gives a tolerance for the deadend of the intersection to not be exactly on the line(s) that cross there, making the script more user-friendly.

 

Is there a way to get a tangent direction from the endpoint of a curve (including splines) without my lengthening workaround? If so, I could generate that point without calling commands in the subfunction that reports the point list and I would really have no need for splp.

Message 4 of 11
Kent1Cooper
in reply to: JBW_AIScripts


@JBW_AIScripts wrote:

.... Is there a way to get a tangent direction from the endpoint of a curve (including splines) without my lengthening workaround? ....


Yes.  If 'obj' is the VLA-object conversion of the path object, and 'pt' is the endpoint in question, then this:

(angle '(0 0) (vlax-curve-getFirstDeriv obj (vlax-curve-getParamAtPoint obj pt)))

will give you the direction it's headed at that point, in radians.  If it's at the start of the object, that will aim along it; if the end, away from it.  You'll find many examples of this kind of first-derivative usage for object direction in this Forum.

For one way of determining whether you're at the start or end of a path object, you can see PolylineContinue.lsp, >here<.

Kent Cooper, AIA
Message 5 of 11
JBW_AIScripts
in reply to: Kent1Cooper

Thank you! I'm going to try to work that in.

 

Here's a diagram of the selection window I'm trying to use to capture crossing lines. The (pacman) function generates an approximation of the yellow shape as a point list that the (ssget) can use as a selection window.

JBW_AIScripts_0-1735826130810.png

Message 6 of 11

Updated version-

 

A few things have been fixed with help from @Kent1Cooper. I removed the (splp) and (pointcast) subfunctions as they are pointless workarounds for the (polar) function and the tangent angle reporter.

 

I am now trying to troubleshoot why it is giving me a "bad argument type: numberp: nil" error.

 

I still need help getting (pacman) to work. My main suspect for what is wrong is still the way I attempted to append the points together in a list.

 

Also, does the polar command need the direction reported in a certain value range, such as 0 to 2pi? If so, is there an operator that translates out-of-range numbers back into that range?

Message 7 of 11
Kent1Cooper
in reply to: JBW_AIScripts


@JBW_AIScripts wrote:

.... does the polar command need the direction reported in a certain value range, such as 0 to 2pi? ....


No, it will accept angles of greater than 2pi radians.

Kent Cooper, AIA
Message 8 of 11
Kent1Cooper
in reply to: JBW_AIScripts


@JBW_AIScripts wrote:

....

I still need help getting (pacman) to work. My main suspect for what is wrong is still the way I attempted to append the points together in a list.

....


UNTESTED, and even if correct, there may also be other issues, but try replacing this much:

 

(setq outlist pt2) ;; Set first point - center of "Pac-Man"
(setq j 0)
;; Generate point list from data shaped like "Pac-Man" with a "mouth" angle of 120 degrees, facing the endpoint
(repeat 20 ;; 10 times per side
  (setq outlist
    (append
      (list outlist)
      (list (polar ....

 

with this:

 

(setq outlist (list pt2)) ;; Set first point into a list - center of "Pac-Man"
(setq j 0)
;; Generate point list from data shaped like "Pac-Man" with a "mouth" angle of 120 degrees, facing the endpoint
(repeat 20 ;; 10 times per side
  (setq outlist
    (append
      outlist
      (list (polar ....

Kent Cooper, AIA
Message 9 of 11
JBW_AIScripts
in reply to: Kent1Cooper

Oh good. What about negative values? For example, -pi?

Message 10 of 11
Kent1Cooper
in reply to: JBW_AIScripts


@JBW_AIScripts wrote:

Oh good. What about negative values? For example, -pi?


You can try it yourself easily enough, but yes, it will take negative values.  But -pi is not a valid format as it would be for a raw number with a minus sign preceding -- rather, it would need to be (- pi).

Kent Cooper, AIA
Message 11 of 11
Kent1Cooper
in reply to: JBW_AIScripts


@JBW_AIScripts wrote:

.... Here's a diagram of the selection window I'm trying to use to capture crossing lines. The (pacman) function generates an approximation of the yellow shape as a point list ....


Another [and I think simpler] approach you could take:  Build a simple Crossing window around the endpoint in question [only two points needed], letting the object in question be part of the resulting selection.  Then if it finds more than one thing, remove the object in question from the set, or if it finds only one, then it must be dead-ending on itself, however you want to handle that.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report