Making a script that automatically trims back intersection lines

Making a script that automatically trims back intersection lines

JBW_AIScripts
Contributor Contributor
2,204 Views
34 Replies
Message 1 of 35

Making a script that automatically trims back intersection lines

JBW_AIScripts
Contributor
Contributor

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!

0 Likes
Accepted solutions (4)
2,205 Views
34 Replies
Replies (34)
Message 21 of 35

Kent1Cooper
Consultant
Consultant

Try taking 'csel' out of the localized variables list temporarily, so what's in it will still be around after the routine quits, run the routine, and check what's in it [at the command line, type !csel].  If that reports nil, it's probably because (pacman) didn't find anything.

But are you still getting the same error message as before?  If so, I suspect that's not the issue, because if I do this with 'csel' being nil:

(< (sslength csel) 1)

I get a different error message, about the selection set being nil, not about a number being nil.

Kent Cooper, AIA
0 Likes
Message 22 of 35

JBW_AIScripts
Contributor
Contributor

Going over my script again, I realized I only fixed one of many instances of trying to get (sslength csel). I'm testing it again after more thoroughly fixing it...

 

*EDIT* Found typo - "linspace2" instead of "linespace2".

 

After fixing, I am getting a syntax error again.

 

*EDIT EDIT* finding other problems with my code... Attached is the most recent version. I am now dealing with a "too few arguments" error...

0 Likes
Message 23 of 35

Kent1Cooper
Consultant
Consultant
Accepted solution

@JBW_AIScripts wrote:

.... I am getting a syntax error ....


That often means a parentheses problem.  I didn't notice anything in a quick overview, but I did notice this:

 

(setq

  outlist ;; Generate point list .... ;;; first variable name
  (list pt2) ;; Set first point - center of "Pac-Man"  ;;; value for first variable
  (polar ;;; next variable name!

    pt1

    (-
      (+ dir (/ (* 135 pi) 180)) ;; 135 degree offset
      (* j (/ (* 27 pi) 180)) ;; 27 degree step offset
    ); -
    r
  ); polar
); setq

 

That amounts to trying to use a point as a variable name, but then not giving it a value.  That could well be the syntax error.  If that's meant to put both the center and the first around-the-perimeter point into the 'outlist' to be appended to, then it should be:

 

(setq

  outlist ;; Generate point list .... ;;;; variable name
  (list  ;;; value for it

    pt2 ;; Set first point - center of "Pac-Man"  ;;; first item in list [no right parenthesis after it]
    (polar  ;;; second item in list

      pt1

      (-
        (+ dir (/ (* 135 pi) 180)) ;; 135 degree offset
        (* j (/ (* 27 pi) 180)) ;; 27 degree step offset
      ); -
      r
    ); polar

  ); list
); setq

Kent Cooper, AIA
0 Likes
Message 24 of 35

JBW_AIScripts
Contributor
Contributor

Looks like a version of my script I accidently attached where I tried to remove the repeat function.

 

Now I'm getting an error where it thinks I'm trying to call "outlist" as a function instead of just returning it as a point list.

 

I attached that version here.

0 Likes
Message 25 of 35

Kent1Cooper
Consultant
Consultant

@JBW_AIScripts wrote:

.... I'm getting an error where it thinks I'm trying to call "outlist" as a function instead of just returning it as a point list. ....


Remove the parentheses around it at the next-to-last line.

Kent Cooper, AIA
0 Likes
Message 26 of 35

JBW_AIScripts
Contributor
Contributor

I've combed through it some more. I discovered that I had commented out the repeat in (pacman) and brought it back. Now the error is a malformed list on input.

 

*EDIT* Updated slightly. Still have the same problem.

 

*UPDATE* Turns out "dist" was not recognized as an operator. I needed to use (distance ) instead. I'm back to getting a bad argument type: numberp: nil error though. I think I'm close to figuring it out!

0 Likes
Message 27 of 35

john.uhden
Mentor
Mentor

@JBW_AIScripts ,

I recently submitted a solution including determining if a segment of a polyline was passing through a vertex of the same polyline.  I made a fence function just like @Sea-Haven described...

(defun @fence (p w)

  ;; where p is the point in question
  ;; where w is actually half width
  (list
    (mapcar '+ p (list w w)) ;; upper right
    (mapcar '+ p (list (- w) w)) ;; upper left
    (mapcar '- p (list w w)) ;; lower left
    (mapcar '+ p (list w (- w))) ;; lower right
    (mapcar '+ p (list w w)) ;; upper right (beginning but not closed)
  )
)

The idea is that if (ssget (fence p w)'((0 . 'POLYLINE")))) returns more than 2 selection points (via ssnamex) then there are more than 2 segments (of the same polyline)  that meet or cross at the same point.

John F. Uhden

0 Likes
Message 28 of 35

JBW_AIScripts
Contributor
Contributor

Will this work with splines? What about circles and ovals?

0 Likes
Message 29 of 35

Kent1Cooper
Consultant
Consultant
Accepted solution

I haven't dug deeply into how to fix it, but....  Something seems to be off in the 'dir' determination.  With the red Line going to lower right as 'obj' and the red meeting point as 'pt1', the white is the outline of what (pacman) comes up with:

Kent1Cooper_0-1736519885314.png

You want that spun around the endpoint 180°, so the 'obj' Line reaches into PacMan's mouth but is not crossed by the outline?  It's the same if I reverse the direction of the 'obj' Line.  [If it matters, the two red lines are independent Lines, not part of the same Polyline.]

Kent Cooper, AIA
0 Likes
Message 30 of 35

JBW_AIScripts
Contributor
Contributor

This is massively helpful! I know exactly how to fix this. It looks like I got the end detection wrong for if it should flip around- I just need to reverse the boolean logic to fix it. Also, I need to adjust creating points in the pacman list to get symmetry around the line.

0 Likes
Message 31 of 35

JBW_AIScripts
Contributor
Contributor

I got around to working on this again. Most recent version is attached.

 

I'm still getting a "bad argument type: numberp: nil" error. I think something is not being passed in a correct format somewhere, OR something is taking a "nil" argument that can't handle it.

 

Could you post your code for drawing the PacMan shape? I tried to re-create it myself and got a little snagged up.

0 Likes
Message 32 of 35

Kent1Cooper
Consultant
Consultant

@JBW_AIScripts wrote:

....  Could you post your code for drawing the PacMan shape? ....


[I don't have any.  I was just illustrating what yours gave me.]

Kent Cooper, AIA
0 Likes
Message 33 of 35

JBW_AIScripts
Contributor
Contributor

Ok, I have it actually responding now. The problem was the line where I check for minimum length. It works now except that the PacMan is not reliably facing the correct direction, as noted earlier.

0 Likes
Message 34 of 35

JBW_AIScripts
Contributor
Contributor
Accepted solution

I made a new logical fix for the unpredictable direction of the Pac-Man and that is working. I discovered when selecting single lines that it will de-extend the lines it overlaps instead of the deadending line. The culprit is (command "._LENGTHEN" "Delta" ...) applying to the wrong line. I'm going to try to send the selected line to the front of the draw order when it is on its step of the repeat and see if that fixes it.

 

*EDIT* I tried that and it works! Thanks everybody for your help!

0 Likes
Message 35 of 35

Kent1Cooper
Consultant
Consultant

@JBW_AIScripts wrote:

.... I'm going to try to send the selected line to the front of the draw order when it is on its step of the repeat and see if that fixes it. ....


I think, without analyzing your latest code or testing, that instead of pulling the Line to the front in the drawing order, you can just give the LENGTHEN command a list of entity name and point, like what (entsel) returns, instead of just the point, and it will "see" only that entity at that point.  At least there are some commands where that works.  It should take less code and fewer commands than the Draworder approach.

Kent Cooper, AIA
0 Likes