Jump to content

Is programmatically possible to know if there's a hatch inside a closed 2dpolyline?


Recommended Posts

Posted

Maybe i'm not right he's got another post going on :ouch:

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • CesarA

    12

  • CadFrank

    9

  • Tharwat

    5

  • Lee Mac

    3

Top Posters In This Topic

Posted
Maybe i'm not right he's got another post going on :ouch:

 

You are right.. it's not everyday I laugh on a forum :) Keep the jokes coming. :)

Posted

I can't understand a few things on your code Tharwat, if you can help me out

(defun c:test (/ ss i sn e)
 (if (setq ss (ssget '((0 . "POLYLINE")))) ;;selects all the polylines in a window
   (repeat (setq i (sslength ss))  ;;cycles trough each polyline?
    
     (if (ssget "_CP" ;;???defines a crossing poligon inside wich the polylines will be considered???
                      (mapcar 'cdr ;;??? 
                                (vl-remove-if-not '(lambda (p) (= (car p) 10)) ??? this will go to the "rest" of the list of every element???
                                 (entget (setq sn (ssname ss (setq i (1- i)))))
                          )
                       )
                       '((0 . "HATCH"))
         )
       (ssdel sn ss) ;;deletes the entities wich belong to the previous condition
     )
   )
 )
 (sssetfirst nil ss)
 (princ)
)

 

I don't understand why I need a second ssget because I had the objects selected already. And theres those 2 demon lines

 

 (mapcar 'cdr 
                                (vl-remove-if-not '(lambda (p) (= (car p) 10)) 

 

Apparently this code would go to every "rest" of the elements of every polyline i've selected. But I haven't a polyline defined by setq as I usually have, so I'm not really sure of what this is doing. And you are removing from each polyline it's elements if the first is 10? I'm sorry I don't get this code

Posted

Hi,

 

The first ssget function is to make a selection set of polylines that you want to check out if any one of them is having a hatch object in them or not.

After the selection set being made , we cycle through each polyline , then retrieve all coordinate points of each polyline to feed them with the next ssget function , then I used the string mode "_CP" which means Cpolygon Selection, so with this ssget function we will make a new selection set to on each polyline and if there is any Hatch object within the polyline , its entity name of the polyline would be removed from the first selection set and this process would iterate through all the selected polylines .

 

At last I used the sssetfirst function to select the remaining of the polylines that did not removed from the first selection since they do not have Hatch object within.

 

Hope this clear enough for you.

Posted

Here is a commented version of Tharwat's code:

(defun c:test (/ ss i sn e)
   ;; define function, declare local variables

   (if ;; If the following expression returns a non-nil value
       (setq ss (ssget '((0 . "POLYLINE"))))
       ;; Prompt the user for a selection of POLYLINE entities (using any selection method)

       ;; For every selected polyline
       (repeat (setq i (sslength ss))
           (if ;; If there exists a Crossing Polygon selection of HATCH entities
               (ssget "_CP" ;; obtain a Crossing Polygon selection
                   (mapcar 'cdr ;; Evaluate 'cdr' on every item in the following list (i.e. returning the associated values)
                       (vl-remove-if-not ;; Remove items in the following list if the following predicate function evaluates to nil
                          '(lambda (p) (= (car p) 10)) ;; Test whether the first element of the DXF group is 10
                           (entget (setq sn (ssname ss (setq i (1- i))))) ;; Return the DXF data for the polyline
                       ) ;; end vl-remove-if-not
                   ) ;; end mapcar
                  '((0 . "HATCH")) ;; Filter the Crossing Polygon selection for HATCH entities only
               ) ;; end ssget
               (ssdel sn ss) ;; If a HATCH is found, remove the polyline from the selection set (this doesn't delete the polyline)
           ) ;; end if
       ) ;; end repeat
   ) ;; end if
   (sssetfirst nil ss) ;; Select/highlight the modified selection set (if it exists)
   (princ) ;; Suppress the value returned by the last evaluated expression
)

"POLYLINE" should be "LWPOLYLINE" for the code to work correctly.

Posted

To account for both, you can use the following function to obtain a list of the polyline vertices:

;; Polyline Vertices  -  Lee Mac
;; Returns a list of vertices for a POLYLINE or LWPOLYLINE entity

(defun LM:polyvertices ( ent )
   (apply '(lambda ( foo bar ) (foo bar))
       (if (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
           (list
               (lambda ( lst / itm )
                   (if (setq itm (assoc 10 lst))
                       (cons (cdr itm) (foo (cdr (member itm lst))))
                   )
               )
               (entget ent)
           )
           (list
               (lambda ( ent / enx )
                   (if (= "VERTEX" (cdr (assoc 0 (setq enx (entget ent)))))
                       (cons (cdr (assoc 10 enx)) (foo (entnext ent)))
                   )
               )
               (entnext ent)
           )
       )
   )
)

Therefore the program would become:

(defun c:test ( / e i s )
   (if (setq s (ssget '((0 . "*POLYLINE"))))
       (repeat (setq i (sslength s))
           (if (ssget "_CP" (LM:polyvertices (setq e (ssname s (setq i (1- i))))) '((0 . "HATCH")))
               (ssdel e s)
           )
       )
   )
   (sssetfirst nil s)
   (princ)
)

;; Polyline Vertices  -  Lee Mac
;; Returns a list of vertices for a POLYLINE or LWPOLYLINE entity

(defun LM:polyvertices ( ent )
   (apply '(lambda ( foo bar ) (foo bar))
       (if (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
           (list
               (lambda ( lst / itm )
                   (if (setq itm (assoc 10 lst))
                       (cons (cdr itm) (foo (cdr (member itm lst))))
                   )
               )
               (entget ent)
           )
           (list
               (lambda ( ent / enx )
                   (if (= "VERTEX" (cdr (assoc 0 (setq enx (entget ent)))))
                       (cons (cdr (assoc 10 enx)) (foo (entnext ent)))
                   )
               )
               (entnext ent)
           )
       )
   )
)

Posted

I worked around it by converting them to polylines first, so it kinda fixed it. But your code will too be useful Lee, I will now try to fill those selected with a different hatch, since no one could do it with simple commands http://www.cadtutor.net/forum/archive/index.php/t-53348.html I'll re-look on your elipse hatch code and I think I'll be able to do it with it and the vertice points.

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...