Jump to content

How to delete slots in dxf?


Recommended Posts

Posted
(defun c:deleteCirclesByDiameter (/ ss diaexception f x )
  (setq f 0.5000)
  (setq x globalCleanedValue)
  (setq ss (ssget "_X" '((0 . "CIRCLE"))))
  (setq diaexception '(0.6875 0.6880))
  (if ss
      (progn
        (prompt (strcat "\nFormatted Value of x: " (rtos x 2 4)))
        (setq index 0)
        (repeat (sslength ss)
          (setq ent (ssname ss index))
          (setq dia (* 2 (cdr (assoc 40 (entget ent)))))
          (if (and (> x f)
                   (> x dia)
                   (not (and (member dia diaexception) (= x 0.75))))
              (progn
                (entdel ent)
                (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                                ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4))))
              (prompt (strcat "\nSkipped Circle: " (itoa (1+ index))
                              ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4))))
          (setq index (1+ index))
        )
        (prompt "\nCircles with diameter less than x have been deleted.")
      )
      (prompt "\nNo circles found in the drawing.")
  )
  (princ) 
)

This is the code for deleting circles based on some condtion, i have attached sample dxf, in that dxf  file if my  condition is true circles will be deleted, now what i want is for the same condition slots also should be delete if conditions true....thanks in advance..

Sample dxf.jpg

Posted

Can you upload a dwg file of that?

Posted

So you want the cyan slot to also disappear, right?

 

Just one thing, what's globalCleanedValue ?  What value does it have?  It's glogal, so declared outside the function

Posted (edited)

Yes that cyan slot.

globalCleanedValue is a decimal value..for the above dwg, globalCleanedValue is 0.5 which I got from "1/2"  of "PROFILE:PL1/2". This value will varies depends on the dwg.

Edited by ajithkumar.t
Posted

It took me some time to handle some things I thought would be trivial.

 

See if this works as you want.

 

;; https://www.cadtutor.net/forum/topic/93789-how-to-delete-slots-in-dxf/


(setq globalCleanedValue  1.2)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; test of diameter_of_slot
(defun c:test_dos ( / ent)
	(setq ent (car (entsel)))
	(diameter_of_slot ent)
	
)

(defun same_list_float (l1 l2 / i res smallnumber)
	(setq smallnumber 0.000001)
	(setq i 0)
	(setq res T)
	(repeat (length l1)
		(if (<  (abs (- (nth i l1) (nth i l2))) smallnumber)
			(progn
			    ;;(princ " ")
				;;(princ (abs (- (nth i l1) (nth i l2))))
				(setq res nil)
			)
		)
		(setq i (+ i 1))
	)
	res
)

;; this function looks if the polyline is two parallel lines, connected by 2 arcs.
;; It will return the distance between the parallel lines, which is also the diameter of the arcs.
;; feel free to improve this function 
(defun diameter_of_slot (ent / pts blgs lst pair)

	(setq pts (list))
	(setq blgs (list))
	(setq lst (entget ent))
	(while (setq pair (assoc 42 lst))
		(setq blgs (append blgs (list (cdr pair))))
		(setq lst (cdr (member pair lst)))		;; removes the item we just looked at
	)
	(setq lst (entget ent))
	(while (setq pair (assoc 10 lst))
		(setq pts (append pts (list (cdr pair))))
		(setq lst (cdr (member pair lst)))		;; removes the item we just looked at
	)
	(setq dst nil)		
	(if 			;; line, arc, line, arc
		(or 
			(same_list_float  blgs (list -1.0 0.0 -1.0 0.0))
			(same_list_float  blgs (list 0.0 -1.0 0.0 -1.0))
			(same_list_float  blgs (list 1.0 0.0 1.0 0.0))
			(same_list_float  blgs (list 0.0 1.0 0.0 1.0))
		)
		(progn
			(setq dst (min 
					(distance (nth 0 pts) (nth 1 pts)) 
					(distance (nth 1 pts) (nth 2 pts)) 
			))
		)
	)
	;; return distance
	dst
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
(defun c:deleteCirclesByDiameter (/ ss diaexception f x tpe)
  (setq f 0.5000)
  (setq x globalCleanedValue)
  
  (setq ss (ssget "_X" '((0 . "CIRCLE,LWPOLYLINE"))))
  (princ ss)
  
  (setq diaexception '(0.6875 0.6880))
  (if ss
      (progn
		
		(princ "*")
        (prompt (strcat "\nFormatted Value of x: " (rtos x 2 4)))
        (setq index 0)
        (repeat (sslength ss)
          (setq ent (ssname ss index))
		  
		  ;; we split the tasks.  I leave CIRCCLEs alone, 
		  ;; but slots, which are polylines get their diameter calculated by the functions above 
		  ;; for the rest I don't touch the further handling
		  (setq tpe (cdr (assoc 0 (entget ent))))
		  (setq dia nil)
		  (if (= tpe "CIRCLE")
			  (setq dia (* 2 (cdr (assoc 40 (entget ent)))))
			  (setq dia (diameter_of_slot ent))
		  )
		  
		  (if dia (progn
				  ;; if diameter 
				  (if (and (> x f)
						   (> x dia)
						   (not (and (member dia diaexception) (= x 0.75))))
					  (progn
						(entdel ent)
						(prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
										", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4))))
					  (prompt (strcat "\nSkipped Circle: " (itoa (1+ index))
									  ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4))))
			))				 
          
		  (setq index (1+ index))
        )
        (prompt "\nCircles with diameter less than x have been deleted.")
      )
      (prompt "\nNo circles found in the drawing.")
  )
  (princ) 
)

 

Posted

Hi Emmanuel Delay, above code is working except this c:deleteCirclesByDiameter...it shows, bad argument type: numberp:nil

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