Author Topic: Road crossing count  (Read 165 times)

0 Members and 1 Guest are viewing this topic.

Wianhm

  • Mosquito
  • Posts: 1
Road crossing count
« on: October 13, 2020, 03:55:55 AM »
Good day all,

This is my first post to this forum and I need a little help with a lisp that I'm making

The goal of this lisp is select all the roads in the drawing, then to count every single road crossing.

On small scale (0 - 50 roads) it works, but when handling larger projects I get error: bad argument type: lselsetp nil. Which tells me that it's most likely my selection set that isn't working.

Could someone please guide me on where I went wrong?

Code: [Select]
(defun c:RC_count ( / sel s1 ctr2 ss ctr )
(if (setq sel (ssget "x" '((0 . "LWPOLYLINE") (8 . "Streets"))))
(progn
(setq ctr 0)
(setq s1 (ssadd))
(repeat (sslength sel)

(setq ss
(ssget "_F"
(mapcar 'cdr
(vl-remove-if-not '(lambda ( x ) (= 10 (car x)))
(entget (ssname sel ctr))
)
)
   '((0 . "LWPOLYLINE")(8 . "2F Aerial,4F Aerial,12F Aerial,18F Aerial,36F Aerial,48F Aerial,72F Aerial,96F Aerial,144F Aerial,12F,24F,36F,48F,72F,96F,144F"));checks the crossing lines
);ssget
);setq
;sssetfirst
(setq ctr2 0)
(repeat (sslength ss)
(ssadd (ssname ss ctr2) s1)
(setq ctr2 (1+ ctr2))
)
(setq ctr (1+ ctr))
);repeat
);progn
);if
   
   (print (sslength s1))
   (princ)
)

Thanks in advance and I apologize that I'm asking for help on my first post.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1086
  • Marco
Re: Road crossing count
« Reply #1 on: October 13, 2020, 09:13:09 AM »
Try this (not tested):
Code: [Select]
(defun c:RC_count ( / sel s1 ctr2 ss ctr )
(if (setq sel (ssget "x" '((0 . "LWPOLYLINE") (8 . "Streets"))))
(progn
(setq ctr 0)
(setq s1 (ssadd))
(repeat (sslength sel)
   (and ; <<<<<<<<<
(setq ss
(ssget "_F"
(mapcar 'cdr
(vl-remove-if-not '(lambda ( x ) (= 10 (car x)))
(entget (ssname sel ctr))
)
)
         '((0 . "LWPOLYLINE")
          (8 . "2F Aerial,4F Aerial,12F Aerial,18F Aerial,36F Aerial,48F Aerial,72F Aerial,96F Aerial,144F Aerial,12F,24F,36F,48F,72F,96F,144F"));checks the crossing lines
        );ssget
);setq
              (progn ; <<<<<
(setq ctr2 0)
(repeat (sslength ss)
(ssadd (ssname ss ctr2) s1)
(setq ctr2 (1+ ctr2))
)
(setq ctr (1+ ctr))
           ) ) ; <<<<<<<<<<<
);repeat
);progn
);if
   
   (print (sslength s1))
   (princ)
)

BIGAL

  • Swamp Rat
  • Posts: 537
  • 30 + years of using Autocad
Re: Road crossing count
« Reply #2 on: October 13, 2020, 09:05:03 PM »
Also posted at Cadtutor see solution.
A man who never made a mistake never made anything