Not able select only required lights passing through Roads

Not able select only required lights passing through Roads

Anonymous
Not applicable
1,000 Views
6 Replies
Message 1 of 7

Not able select only required lights passing through Roads

Anonymous
Not applicable

Dear Experts,

I tied and failed to update the code to select only Bollard lightings those are passing through Road-2 as shown in attachments. The code is below.

(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)

(defun C:SEP (/ ss1 ss pt1 pt2 pt_list)
(setvar "cmdecho" 0)
(setq ss1 (entget (car (entsel "\nselect entity"))))
(if (= (cdr (assoc 0 ss1)) "LINE")
(progn
(setq pt1 (cdr (assoc 10 ss1)))
(setq pt2 (cdr (assoc 11 ss1)))
(setq ss (ssget "F" (list pt1 pt2)))
) ; end progn
) ; end if line
(if (= (cdr (assoc 0 ss1)) "LWPOLYLINE")
(progn
(setq pt_list (massoc 10 ss1))
(setq ss (ssget "F" pt_list))
) ; end progn
) ; end if polyline
(command "_pselect" ss "")
(setvar "cmdecho" 1)
(princ)
)
0 Likes
Accepted solutions (1)
1,001 Views
6 Replies
Replies (6)
Message 2 of 7

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

after selection the pline the road path (it's a lwpolyline not a line) you will have to convert it to vla-object

than collect all bollards in (ssget) and use this function to find if the insertion point of bollard is close to road

 

(vlax-curve-getClosestPointTo) ; see online-help

 

also explore the (vlax-curve-xxxxx) functions, these functions are the best AutoLISP/ActiveX has to deal with this kind of problems.

 

enjoy

moshe

 

 

 

Message 3 of 7

Anonymous
Not applicable

Sir, Do you have any other nearly matching programe, So I can update the code.

0 Likes
Message 4 of 7

dlanorh
Advisor
Advisor

The (c:sep) lisp does nothing but attempt to pre select a selection set. Without knowing what you intend to do with the items afterwards it is difficult to work out how to present the results. The below code collects the items into a list, but this is lost once the lisp ends. It would be better if this was a sub function and could return the list to the main function, but again it depends on how it is going to be used down the line.

 

(defun c:blksonline ( / ent blk b_name b_lyr ss b_lst)
  (setq ent (car (entsel "\nSelect Line Entity : "))
        blk (car (entsel "\nSelect Blocks to Find on Line : "))
  )
  (cond ( (and (wcmatch (cdr (assoc 0 (entget ent))) "*LINE")
               (wcmatch (cdr (assoc 0 (entget blk))) "INSERT")
          )
          (setq b_name (cdr (assoc 2 (entget blk)))
                b_lyr (cdr (assoc 8 (entget blk)))
                ss (ssget "_X" (list '(0 . "INSERT") (cons 2 b_name) (cons 8 b_lyr)))
          )
          (repeat (setq cnt (sslength ss))
            (setq blk (ssname ss (setq cnt (1- cnt)))
                  i_pt (cdr (assoc 10 (entget blk)))
                  param (vlax-curve-getparamatpoint ent i_pt)
            )
            (if param (setq b_lst (cons blk b_lst)))
          );end_repeat
        )
  );end_cond
);end_defun  
(defun rh:blksonline ( / ent blk b_name b_lyr ss b_lst)
  (setq ent (car (entsel "\nSelect Line Entity : "))
        blk (car (entsel "\nSelect Blocks to Find on Line : "))
  )
  (cond ( (and (wcmatch (cdr (assoc 0 (entget ent))) "*LINE")
               (wcmatch (cdr (assoc 0 (entget blk))) "INSERT")
          )
          (setq b_name (cdr (assoc 2 (entget blk)))
                b_lyr (cdr (assoc 8 (entget blk)))
                ss (ssget "_X" (list '(0 . "INSERT") (cons 2 b_name) (cons 8 b_lyr)))
          )
          (repeat (setq cnt (sslength ss))
            (setq blk (ssname ss (setq cnt (1- cnt)))
                  i_pt (cdr (assoc 10 (entget blk)))
                  param (vlax-curve-getparamatpoint ent i_pt)
            )
            (if param (setq b_lst (cons blk b_lst)))
          );end_repeat
        )
  );end_cond
  b_lst
);end_defun  
            

The above version is a sub function and will return the list to the calling lisp

I am not one of the robots you're looking for

0 Likes
Message 5 of 7

Anonymous
Not applicable

Thanks for help Sir, But it's not working at my end. 

0 Likes
Message 6 of 7

dbhunia
Advisor
Advisor
Accepted solution

Try this.... Roughly done...... (hopefully you can localised the variables and manage the rest) 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 7 of 7

Anonymous
Not applicable

Thanks alot Sir. You saved me alot of time. 

0 Likes