samifox Posted January 29 Posted January 29 (edited) hi i want to select hatch boundary by actually selecting the hatch object. Meaning, when i select the hatch, AutoCAD actually select and highlight its boundary instead. Any idea? (defun c:test ( ) "Selects the current hatch object and highlights its boundary." (setq ent (entsel) ; Get the selected entity bound (entget (car ent) 'BOUNDARY)) ; Get the hatch boundary (if bound (progn (ssget '((0 ent)) ; Select the hatch entity (entmod (car ent) 1) ; Highlight the hatch entity (command "_regen") ; Refresh the drawing to show the highlight ) (princ "No hatch object selected.\n") ) ) Edited January 29 by samifox Quote
Lee Mac Posted January 29 Posted January 29 There are so many issues with that code... almost every function has been used incorrectly - did you consult the developer reference when writing it? Quote
Lee Mac Posted January 29 Posted January 29 You can obtain the objects constituting the hatch boundary from the DXF group 330 entries which follow DXF group 97 (which itself indicates the number of boundary entities) in the DXF data list, e.g.: (defun c:selhatbound ( / bnd ent enx ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect hatch: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil ) ( (/= "HATCH" (cdr (assoc 0 (setq enx (entget ent))))) (princ "\nThe selected object is not a hatch.") ) ( (zerop (cdr (assoc 97 enx))) (princ "\nThe selected hatch has no associated boundary objects.") ) ( (progn (setq bnd (ssadd)) (foreach itm (member (assoc 97 enx) enx) (if (= 330 (car itm)) (ssadd (cdr itm) bnd) ) ) (zerop (sslength bnd)) ) (prompt "\nUnable to select boundary objects.") ) ( (sssetfirst nil bnd) nil ) ) ) ) (princ) ) 1 Quote
samifox Posted January 31 Author Posted January 31 Thanks Lee i have used your code for the following - ask user to select hatches - Iterate hatches -remove old boundary and recreate it (associative polyline) - select and highlight the new created boundaries this code prints an error about the dxf (defun c:selhatbound (/ ents ent enx bnd newboundary) ; Step 1: Prompt the user to select hatches (setq ents (ssget "_:L" '((0 . "HATCH")))) ; Step 2: Check if hatches are found in the selection set (if ents (progn ; Step 3: Loop through each hatch in the selection set (setq i 0) (while (< i (sslength ents)) (setq ent (ssname ents i)) (setq enx (entget ent)) ; Step 4: Check if the entity is a hatch (if (= "HATCH" (cdr (assoc 0 enx))) (progn ; Step 5: Create a new associative polyline boundary (setq newboundary (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(8 . "0") '(100 . "AcDbPolyline") '(90 . 4) '(10 0 0) '(10 10 0) '(10 10 10) '(10 0 10) '(10 0 0) ) ) ) ; Step 6: Get the entity name as a string (setq ename (cdr (assoc 330 enx))) ; Step 7: Modify the hatch entity to include the new polyline boundary (entmod (subst (cons 330 newboundary) (assoc 330 enx) enx)) ; Step 8: Display a message about the new boundary (prompt (strcat "\nNew boundary created for hatch " (itoa (1+ i)))) ) ) ; Step 9: Move to the next hatch (setq i (1+ i)) ) ) ; Step 10: If no hatches found, display a message (prompt "\nNo hatches found.") ) ; Step 11: End the AutoLISP command (princ) ) Quote
Steven P Posted January 31 Posted January 31 2 hours ago, samifox said: this code prints an error about the dxf That is the error? That gives a clue to the problem Quote
Lee Mac Posted January 31 Posted January 31 Your code here is just creating a square for every hatch... ; Step 5: Create a new associative polyline boundary (setq newboundary (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(8 . "0") '(100 . "AcDbPolyline") '(90 . 4) '(10 0 0) '(10 10 0) '(10 10 10) '(10 0 10) '(10 0 0) ) ) ) 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.