- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I posted about syntax error resulting from this code last week - We solved the syntax issue and now I'm looking for help on improving the LISP for my application so I figured I'd title it something new.
The end goal of the LISP is to prompt the user to select a polyline, automatically select all or likely intersecting lines, count the intersections, and then print the # of intersections to an mtext object at the halfway point of the polyline. If the code could cycle through a # of selected polylines that would be a bonus but as long as it is one-click it will fit into our workflow fine.
What I have right credit to @Kent1Cooper now counts intersections of selected polyline and lines and prints to the command line. It worked very well when i selected only a small portion of the lines in the drawing near the polyline but counts many extra intersections if i use a command to automatically select ALL lines.
(defun c:EONEinterscountKC ( / c i l s x ent sel2 ) ;;define function
(if
(and
(setq ent (car (entsel))) ;;selects Zone polyline
(setq sel2 (ssget '((0 . "LINE") (8 . "LPSLAT")))) ;;selects lateral lines
)
(progn ; wrap into ONE 'then' expression
(setq s (ssadd ent sel2)) ;;adds zone and laterals to same selection set
(repeat (setq i (sslength s)) ; selection set to list of VLA objects
(setq
i (1- i)
l (cons (vlax-ename->vla-object (ssname s i)) l)
) ; setq
) ; repeat
(setq c 0)
(while (setq x (car l))
(foreach y (setq l (cdr l))
(setq c (+ c (/ (length (vlax-invoke x 'intersectwith y acextendnone)) 3)))
)
)
(princ (strcat "\n" (itoa c) " intersection" (if (= 1 c) "" "s") " between " (itoa (sslength s)) " objects."))
) ; progn [end of 'then' expression]
(princ "\nPlease select more than one object.") ; 'else' expression
) ; if
(princ) ;;clean exit
) ; defun
My questions are as follows:
1. Is there a good way to select all lines in the vicinity of the polyline instead of all lines in the drawing?
2. Is there any reason it might be returning incorrect #s when all lines are selected?
3. What is the easiest way to create an Mtext object with the number of intersections 5 units below the center of the pline?
4. can the code be adjusted easily to loop through all selected polylines?
Any advice that anyone can provide is massively appreciated by me. I am doing my best to get a crash course in Autolisp so that I can do more of this myself.
lease also let me know if there is any more information I can provide or if the format of my post is not appropriate for the forum and I will adjust.
Thanks!
Solved! Go to Solution.