Jump to content

Selecting objects within multiple selected closed polylines


Johnnytarno

Recommended Posts

I have scoured the net for a way to select all objects within a selected closed polyline as well objects that are touching the polyline, which i have found, but i need to be able to select more than one closed polyline at a time ,as I work on thousand of circles (drill holes) and shapes at any given time a lot of the time. If someone could please help me it would be greatly greatly appreciated. I am hoping for a modified lisp file that has been out there already.

Link to comment
Share on other sites

This is very close it finds text inside multiple polygons so feel free to pull it part. I have changed the line that makes the selection set SS to ignore text. Time to go home now. You will need to add "Circle" to selection set filter.

 

(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
) ; end defun
; program starts here
; choose output file change acdatemp to what you want
(setq fname (strcat "c:/acadtemp/" (getstring "\nEnter file name ")))
(setq fout (open fname "w"))
(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)
(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
(co-ords2xy)
; write pline co-ords here
(setq numb3 (length co-ords))
(setq z numb3)
(setq ansco-ords "")
(repeat numb3 
(setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
)
(setq ans (strcat "Pline " ansco-ords))
(write-line ans fout)
(setq ansco-ords "")
;(setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
(setq ss (ssget "WP" coordsxy )) ; selection set within polygon
(if (= ss nil) 
(princ "\nnothing inside")
(progn 
(setq coordsxy nil) ; reset for next time
(setq numb2 (sslength ss))
(setq y numb2)
(repeat numb2
(setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
(princ anstext) ; change to write text to file
(write-line (strcat "text " anstext) fout)
(princ "\n")
) ; end repeat2
(setq ss nil) ; reset for next poly
)
)
) ; end repeat1
(close fout)
(princ)

Link to comment
Share on other sites

Welcome to CADTutor .

 

Try this and let me know .

 

(defun c:Test (/ s ss sel)
 ;;    Tharwat 30. May. 2014        ;;
 (if (setq s  (ssadd)
           ss (ssget (list '(0 . "LWPOLYLINE")
                           '(-4 . "&=")
                           '(70 . 1)
                           (cons 410 (getvar 'CTAB))
                     )
              )
     )
   ((lambda (j / sn n d l pts)
      (while (setq sn (ssname ss (setq j (1+ j))))
        (setq l   (vlax-curve-getdistatparam sn (vlax-curve-getendparam sn))
              d   (/ l 250.)
              n   d
              pts nil
        )
        (repeat 250
          (setq pts (cons (vlax-curve-getpointatdist sn n) pts)
                n   (+ n d)
          )
        )
        (if (setq sel (ssget "_WP" pts))
          ((lambda (i / en)
             (while (setq en (ssname sel (setq i (1+ i))))
               (ssadd en s)
             )
           )
            -1
          )
        )
      )
    )
     -1
   )
 )
 (sssetfirst nil s)
 (princ)
)

Link to comment
Share on other sites

I have scoured the net for a way to select all objects within a selected closed polyline as well objects that are touching the polyline, which i have found, but i need to be able to select more than one closed polyline at a time ,as I work on thousand of circles (drill holes) and shapes at any given time a lot of the time. If someone could please help me it would be greatly greatly appreciated. I am hoping for a modified lisp file that has been out there already.

 

 

Try this one

;; change layer to suit, for this code:
;; the circles placed on layer "M-HOLES" 
;; the closed lw polylines placed on layer "M-PANEL"
(vl-load-com)

(defun C:DEMOSET (/ acapp adoc c fcode fdata i n points poly pts pt_list sscirc sscoll ssitem )

(setq acapp           (vlax-get-acad-object)

   adoc           (vla-get-activedocument acapp))
 (setq sscoll (vla-get-selectionsets adoc))
 (not (vl-catch-all-error-p
  (vl-catch-all-apply '(lambda()(progn (vla-delete(vla-item sscoll "LWSELECT")))
    (vlax-release-object (vla-item sscoll "LWSELECT"))))))
 (not (vl-catch-all-error-p
  (vl-catch-all-apply '(lambda()(progn (vla-delete(vla-item sscoll "CURRENT")))
    (vlax-release-object (vla-item sscoll "CURRENT"))))))
(setq ssitem (vla-add (vla-get-selectionsets adoc) "LWSELECT"))
(setq fcode   (vlax-safearray-fill
  (vlax-make-safearray vlax-vbinteger '(0 . 3))
  (list 0 70 8 410)
  )
      
   fdata  (vlax-safearray-fill
     (vlax-make-safearray vlax-vbvariant '(0 . 3))
     (list "LWPOLYLINE" 1 "M-PANEL" (getvar "ctab")))
      )
(vla-select ssitem acselectionsetall nil nil fcode fdata)
 (setq i -1)
 (repeat (vla-get-count ssitem)
   (setq poly (vla-item ssitem (setq i (1+ i))))
      (setq n (/ (vlax-curve-getdistatparam poly (vlax-curve-getendparam poly)) 128)
         c (- n)
   )
   (repeat 128
       (setq pts (cons (trans (vlax-curve-getpointatdist poly (setq c (+ c n))) 0 1) pts))
   )
(not (vl-catch-all-error-p
  (vl-catch-all-apply '(lambda()(progn (vla-delete(vla-item sscoll "CIRCSELECT")))
    (vlax-release-object (vla-item sscoll "CIRCSELECT"))))))
   (setq fcode   (vlax-safearray-fill
  (vlax-make-safearray vlax-vbinteger '(0 . 2))
  (list 0 8 410)
  )
      
   fdata  (vlax-safearray-fill
     (vlax-make-safearray vlax-vbvariant '(0 . 2))
     (list "CIRCLE" "M-HOLES" (getvar "ctab")))
      )
  (setq sscirc (vla-add (vla-get-selectionsets adoc) "CIRCSELECT"))
   
 (vla-clear(vla-item sscoll "circSet"))
   
 (setq pt_list (apply 'append pts))
 (setq points (vlax-safearray-fill
  (vlax-make-safearray
    vlax-vbdouble
    (cons 0 (1- (length pt_list)))
  )
  pt_list
       )
 )
   (setq pts nil)
   
   (vla-selectbypolygon sscirc acSelectionSetCrossingPolygon  points fcode fdata)
   
(if (> (vla-get-count sscirc) 0)
 (alert (itoa (vla-get-count sscirc))))
 )
 (alert "END")
 (princ)
)

Link to comment
Share on other sites

This is very close it finds text inside multiple polygons so feel free to pull it part. I have changed the line that makes the selection set SS to ignore text. Time to go home now. You will need to add "Circle" to selection set filter.

 

(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
) ; end defun
; program starts here
; choose output file change acdatemp to what you want
(setq fname (strcat "c:/acadtemp/" (getstring "\nEnter file name ")))
(setq fout (open fname "w"))
(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)
(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
(co-ords2xy)
; write pline co-ords here
(setq numb3 (length co-ords))
(setq z numb3)
(setq ansco-ords "")
(repeat numb3 
(setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
)
(setq ans (strcat "Pline " ansco-ords))
(write-line ans fout)
(setq ansco-ords "")
;(setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
(setq ss (ssget "WP" coordsxy )) ; selection set within polygon
(if (= ss nil) 
(princ "\nnothing inside")
(progn 
(setq coordsxy nil) ; reset for next time
(setq numb2 (sslength ss))
(setq y numb2)
(repeat numb2
(setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
(princ anstext) ; change to write text to file
(write-line (strcat "text " anstext) fout)
(princ "\n")
) ; end repeat2
(setq ss nil) ; reset for next poly
)
)
) ; end repeat1
(close fout)
(princ)

 

 

I appreciate your fast response. I'm not expert at LISP routines yet, I only know very basic funtionality. I havent got it working the way i think it should be. I understand that you use it to select text which it looks as if you have commented that line out, so as soon as i load the program it asks me to type a name, which is fine, but after I select the polylines (which at this point in time look right) it has an error ": ActiveX server returned error: unknown name: Textstring". I am tryin to get it to select points within multiple closed poly line shapes first then i have a separate routine to convert the points to a circle. Thanks again for your help either way.

Link to comment
Share on other sites

That's exactly what I needed Tharwart. I have a separate routine that converts my points to circles, so that is excellent. Thanks so much for your help. All I changed was "_WP" to "_CP" so that it selects points that fall right on the border of the PLINE, as the center of the circle that falls on the border we keep. Thanks again.

Link to comment
Share on other sites

Thanks for your input fixo, i haven't got it to work properly. I didn't want to have to assign the objects to layers as that takes a bit too much time, because I could be drawing and erasing objects just as fast. But one of the other posts actually has what I needed. I appreciate your help either way. The post was from Tharwat

Link to comment
Share on other sites

Actually I just realized that when a point falls exactly on a corner (Perpendicular point) it will not recognize the point, so it doesn't select it. Is there a way around this? It does select the other points that fall on the vector but not the actual corner. We can get around it for now as it does stand out once i apply a circle to the point, but it would be great if i wouldn't have to worry about possibly missing out on a couple points when I'm not my usual pedantic self :)

Link to comment
Share on other sites

Johnnytarno you can also use "F" option fence this will pick up points on a line, only problem may be that you will end up with a point twice, as you mention if its just missing those pts then should be ok. It will meant though either two programs or adding the "F" routine as well.

Link to comment
Share on other sites

That's exactly what I needed Tharwart. I have a separate routine that converts my points to circles, so that is excellent. Thanks so much for your help. All I changed was "_WP" to "_CP" so that it selects points that fall right on the border of the PLINE, as the center of the circle that falls on the border we keep. Thanks again.

 

Excellent , you're welcome .

Link to comment
Share on other sites

  • 7 months later...

Hello

I have a similar problem I have millions of holes that needs to be deleted inside a pattern of polylines.

 

My only problem is that I don't understand how to use LISP, and therefor I don't understand how to take your code (Tharwat) into Autodesk and what I need to type in the command field when I need to use the command...

 

Is there any way that I can buy someone to help me get this command working on my computer?

Maybe by making a video or something like that / or by saving a file that I can work on when the command works.

 

I know that I sound like an amateur, and actually this is what i am regarding Autocad - my knowledge lies in Inventor, so please help an amateur!

 

Best regards

Mads

Link to comment
Share on other sites

Hello

My only problem is that I don't understand how to use LISP, and therefor I don't understand how to take your code (Tharwat) into Autodesk and what I need to type in the command field when I need to use the command...

 

 

Welcome to CADTutr .

 

To run any Lisp program , just save the codes in a lisp file format with the use of notepad then go back to Autocad and type ap or appload and select the lisp file .

 

To know the command name of any lisp program , just search at the top of the program for

[color="#ff00ff"]([/color][color="blue"]defun[/color] c:xxx

so the command name here should be xxx .

 

Have a nice day :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...