Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert existing object in Dwg to blocks 1

Status
Not open for further replies.

sprinkman

Mechanical
Mar 24, 2001
2
I want to use the windows or crossing command to convert several hundred circles (fire sprinklers) on a drawing to individual blocks, that are all the same, so that I can use the "count" command to get an accurate count of fire sprinklers in a warehouse
 
Replies continue below

Recommended for you

;COMMAND: SPRINKLER
;FOR ALL VERSIONS OF AUTOCAD
;SAVE AS sprinkler.lsp to directory \SUPPOTRT;and from command line: (load "sprinkler")
;then, on command line, type SPRINKLER AND FOLLOW SELLECT-OBJECT PROMPTS
;ERASES ALL PICKED CIRCLES AND REPLACES EACH WITH A CIRCLE BLOCK OF R=100
;SCALED TO THE RADIUS OF EACH ERASED CIRCLE
;AND INSERTED AT ITS CENTER POINT,
;APPEARANCE REMAINS THE SAME BUT NOW CIRCLES ARE BLOCKS
;RICHLY COMMENTED FOR YOUR CONVENIENCE AND MODIFICATIONS
;FOR QUESTIONS please call at:
;;I am home most of the time.


;Get circles by any method you like - follow prompts to get objects
;only circles will be taken seriously, others will be ignored
(defun C:SPRINKLER()
;this allows select objects by any way you like
;first big IF
(IF (setq sset (ssget (list (cons 0 "CIRCLE"))))(PROGN
;this tells how many circles were caught, picked, windowed, crossed
(setq ssetl (sslength sset))
;just for information, to see the circle count on command line
(print ssetl)(princ " Circles found...")

(circlo)
(setq i 0)

(while (< i ssetl)
(setq Edna (ssname sset i))
(setq Eddy (entget Edna))

(setq Typy (dxf 0 Eddy)
; this is not really used. Was for debugging
Insy (dxf 10 Eddy)
; Insertion point of circle we are going to erase
Rady (dxf 40 Eddy)
;radius of circle we are going to erase
)
;this is tricky (x Y) = (10 20) will be converted into &quot;10,20&quot;
(setq Insy (strcat
(rtos (car Insy) 2)
&quot;,&quot;
(rtos (cadr Insy))
)
)
;remember, the block CIRCO has radius 100. Why not 1?
;well, snap complications I suppose - too tiny
(setq rady (/ rady 100))
;and this converts R= 25.5 into &quot;25.5&quot;
(setq rady (rtos rady 2))

;this was for debugging. Don't need anymore
;(print Insy)(print Rady)

;erase the circle
(COMMAND &quot;_erase&quot; Edna &quot;&quot;)
;insert block circle with scale factor
;to correspond to radius of erased circle
(COMMAND &quot;_insert&quot; &quot;CIRCLO&quot; Insy rady &quot;&quot; &quot;&quot; )
(setq i (+ 1 i));NEXT CIRCLE
);while ends here
)(print &quot;No Circles Found!&quot; ));first big IF ends here
(princ);suppress repeated prompt
);end of main function

;THIS makes a block of r=100 circle, if it does not exist IN THIS DRAWING
(defun Circlo()
(setq Blocky (tblobjname &quot;block&quot; &quot;CIRCLO&quot;))
(if (not Blocky)(progn
(command &quot;_circle&quot; &quot;0,0&quot; &quot;100&quot;)
(command &quot;_block&quot; &quot;CIRCLO&quot; &quot;0,0&quot; &quot;_L&quot; &quot;&quot;)
;(command &quot;_erase&quot; &quot;_L&quot; &quot;&quot;)
))
)


;Useful function to extract-
;Entity name &quot;CIRCLE n= 0
;Insy InsertionPoint n= 10
;rady radious n= 40
;ed is full entity data
(defun dxf (n ed) (cdr (assoc n ed)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor