Elevation symbol's hatch save

Elevation symbol's hatch save

Anonymous
Not applicable
875 Views
1 Reply
Message 1 of 2

Elevation symbol's hatch save

Anonymous
Not applicable

Greetings!


I am quite new to coding, treat it as such.
I would like to delete all the solid hatch from an arhitect drawing, except the elevation symbol's. I made a solution, but its quite convoluted. It works for my tailored problem, but with real drawings, not so much.
Common errors are:
- doesnt always puts in layers, or finds them when it is needed
- stops after the bursts
- runs in a loop have to cancel it
Can it work, or is there an easy solution? Any suggestion will do fine.

Thank you in advance!

AutoCAD 2016, Windows 10 pro

Working code before and afterWorking code before and after

 

(defun c:kota ( / a b1 b2 sset i ent obj obj2 b c)

(command "_.-layer" "_Thaw" "*" "_ON" "*" "_UNLOCK" "*" "")			;unlocks all layers

(setq a 0)									;eliminates all blocks 
(while
  (and
    (setq b1 (ssget "_X" '((0 . "Insert"))))
    (<= a 6)
  )
  (sssetfirst nil b1)
  (c:burst)
  (if
    (setq b2 (ssget "_X" '((0 . "Insert"))))		
    (if (= (sslength b1) (sslength b2))		
      (setq a (+ a 1)); then
      (setq a 0); else
    )								
  )								
)					

(layerstate-import "P:\\Adatok2\\ANG\\Tudástár\\base.las")			;brings in desired layers			
(layerstate-restore "base" viewport 1)											
(layerstate-delete "base")														

	(setq sset (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))) i 0)		;filters elevation symbol hatches
		(repeat (sslength sset)
			(setq ent (ssname sset i))
			(setq obj (entget ent))
		(if (/= 42 
								(car (cadr (member (assoc 10 (member (assoc 2 obj) obj)) obj)))
			)
			(if (= 75  												;arbitrary length 
						(abs
							(-
								(cadr (car (member (assoc 10 (member (assoc 2 obj) obj)) obj)))
								(cadr (cadr (member (assoc 10 (member (assoc 2 obj) obj)) obj)))
							)
						)	
				)
				(progn
					(command "setbylayer" "al" "" "n" "y")		
					(setq obj2 (reverse obj))						
				
					(setq a (cdr (car (member (assoc 10 obj2) obj2))))		;selects and moves hatch to desired layer
					(setq b (cdr (caddr (member (assoc 10 obj2) obj2))))
					(setq c (ssget "F" (list a b) '((0 . "HATCH"))))
					(command "change" c "" "p" "la" "_E0_epitesz" "")													
				)
			)
		)
		(setq i (1+ i))
		
		)
		(setq i nil)

				(if (setq a (ssget "_X" '((0 . "HATCH")(2 . "SOLID") (-4 . "<NOT") (8 . "_E0_epitesz") (-4 . "NOT>"))))  ;deletes every other solid hatch 
				(repeat (setq i (sslength a)) (entdel (ssname a (setq i (1- i)))))
			)
	(alert "Kész") 		;ready
)
	
0 Likes
876 Views
1 Reply
Reply (1)
Message 2 of 2

hencoop
Advisor
Advisor

A couple of points:

  • The file that DEFUN's c:burst is not included.  It may show why this quits after (C:BURST).
  • The only thing in what you have provided that can cause you to get stuck in a loop is (WHILE ...).  You increment the value of 'a' unless (= SSLENGTH b1)(SSLENGTH b2)), otherwise you reset it to 0 which tells the WHILE to continue as long as there are still INSERT's in the drawing.  As long as there are inserts and 'a' is less than or equal to 6, you will continue the loop.

 

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes