Kokhanetz Posted June 13, 2023 Posted June 13, 2023 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 Quote
Kokhanetz Posted June 13, 2023 Author Posted June 13, 2023 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 Quote
ronjonp Posted June 13, 2023 Posted June 13, 2023 (edited) 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) ) Edited June 13, 2023 by ronjonp 1 1 Quote
mhupp Posted June 13, 2023 Posted June 13, 2023 (edited) 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 June 13, 2023 by mhupp 2 Quote
marko_ribar Posted June 13, 2023 Posted June 13, 2023 OP, are you sure this is standard Visual Lisp function : (vlax-curve-curve-intersect)? Quote
mhupp Posted June 14, 2023 Posted June 14, 2023 (edited) That's what ronjonp said @marko_ribar ChatGPT is a little confused. after about 2 mins and linking to lee mac site about intersection points. Edited June 14, 2023 by mhupp 1 Quote
Kokhanetz Posted June 14, 2023 Author Posted June 14, 2023 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) ) 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 1 Quote
Recommended Posts
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.