Jump to content

Deltrim Hatch Outside Boundary and keep all inside the boundary


Kokhanetz

Recommended Posts

Hi Guys,

 

I working on a code now, but im stuck... Hope you guys can help.

I have a .shp file wich has 1 big hatch (the dwg is 27mb). In the png file you can see a image of the hatch.

 

I have written a code, helped by google and a friend, but now we are stuck.

It wipes the complete hatch, and i just want to keep the hatch within the boundary.

 

Here's the code:

(defun c:DelTrimHatch ()
  (setq boundary (entsel "\nSelect the boundary polyline: "))
  (setq hatchlist (ssget "X" '((0 . "HATCH"))))
  (setq boundaryobj (vlax-ename->vla-object (car boundary)))
  
  (setq count 0)
  (repeat (sslength hatchlist)
    (setq hatchobj (vlax-ename->vla-object (ssname hatchlist count)))
    (setq hatchboundaries (vlax-invoke-method hatchobj 'GetLoopAt 0 0))
    
    (if (vl-catch-all-error-p hatchboundaries)
      (progn
        (setq count (1+ count))
        (setq hatchlist (ssdel (ssname hatchlist count) hatchlist))
      )
      (progn
        (setq hatchoutside t)
        (setq i 0)
        (while (and hatchoutside (< i (length hatchboundaries)))
          (if (vlax-curve-curve-intersect (nth i hatchboundaries) boundaryobj)
            (setq hatchoutside nil)
          )
          (setq i (1+ i))
        )
        (if hatchoutside
          (setq count (1+ count))
          (setq hatchlist (ssdel (ssname hatchlist count) hatchlist))
        )
      )
    )
  )
  
  (setq i 0)
  (while (< i (sslength hatchlist))
    (setq hatchent (ssname hatchlist i))
    (entdel hatchent)
    (setq i (1+ i))
  )
  
  (princ "\nHatches outside the boundary have been deleted.")
  (princ)
)

 

I hope someone can help me with solving this problem.

 

Thnx in advance.

 

Wouter

image.png

Link to comment
Share on other sites

I cant edit the text.. But i see its not always 1 hatch.. it can have multiple hatches to.

 

so it should wipe all outside the boundary 

Link to comment
Share on other sites

Was your friend ChatGPT ? 🤓

 

"vlax-curve-curve-intersect" is not a native function.

 

This should do what you want:

(defun c:foo (/ s s2)
  ;; RJP » 2023-06-13
  (cond	((setq s (ssget '((0 . "HATCH") (410 . "Model"))))
	 (setq s2 (ssget "_X" '((0 . "HATCH") (410 . "Model"))))
	 (foreach e (mapcar 'cadr (ssnamex s2)) (or (ssmemb e s) (entdel e)))
	)
  )
  (princ)
)

2023-06-13_16-26-25.thumb.gif.84f53be66f2a851bb077a1b534d87230.gif

Edited by ronjonp
  • Like 1
  • Funny 1
Link to comment
Share on other sites

Kinda made the same thing that inverts the current selection for things on screen. Useful for when its easier to select the things you don't want vs the things you do.

 

;;----------------------------------------------------------------------------;;
;; Invert Selection on Screen
(defun C:SEE (/ SS SS1)
  (if (setq SS (ssget "_I"))  
    (progn)
    (setq ss (ssadd))
  )
  (if (setq SS1 (ssget "_WP" (GetScreenCoords)))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (ssdel ent SS1)
    )
  )
  (sssetfirst nil SS1)
  (princ)
)
;;----------------------------------------------------------------------------;;
;Calculates Size of View Window
(defun GetScreenCoords (/ ViwCen ViwDim ViwSiz VptMin VptMax)
  (setq ViwSiz (/ (getvar 'VIEWSIZE) 2)
        ViwCen (getvar 'VIEWCTR)
        ViwDim (list (* ViwSiz (apply '/ (getvar 'SCREENSIZE))) ViwSiz)
        VptMin (mapcar '- ViwCen ViwDim)
        VptMax (mapcar '+ ViwCen ViwDim)
  )
  (list VptMin VptMax)
)

 

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

8 hours ago, ronjonp said:

Was your friend ChatGPT ? 🤓

 

"vlax-curve-curve-intersect" is not a native function.

 

This should do what you want:

(defun c:foo (/ s s2)
  ;; RJP » 2023-06-13
  (cond	((setq s (ssget '((0 . "HATCH") (410 . "Model"))))
	 (setq s2 (ssget "_X" '((0 . "HATCH") (410 . "Model"))))
	 (foreach e (mapcar 'cadr (ssnamex s2)) (or (ssmemb e s) (entdel e)))
	)
  )
  (princ)
)

2023-06-13_16-26-25.thumb.gif.84f53be66f2a851bb077a1b534d87230.gif

 

No my friend was not chatgpt :) I did use it for helping me out to give comments on what it does. Sometimes i need to search proper how things works.

And 'myfriend" is more a c## coder not lisp.

 

But you script works perfect.. (even with less lines.) Thanks

  • Like 1
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...