PDA

View Full Version : is there a replace command?



gib65
26th Jan 2007, 08:15 pm
Is there a command that allows you to replace one object with another? I mean, suppose you had an object and you wanted to substitute it with another. Rather than delete the first object and then put the new one in its place, is there a way to do it in one step?

StykFacE
26th Jan 2007, 08:20 pm
what type of object are you talking about? there is a BLOCKREPLACE command if you want to use blocks.

the ber
26th Jan 2007, 08:47 pm
you can use the properties palette for changing some objects. for example if you have some circles with radius = 2, you can select them, go to the properties palette, change the radius to 4, and all the selected circles will be changed. hope this helps.

gib65
26th Jan 2007, 08:51 pm
what type of object are you talking about? there is a BLOCKREPLACE command if you want to use blocks.

Well, I not sure. I want to replace a set of trees with different trees. I've got a landscape plan with about 50 or so trees and I want to replace each and every one of them. Each tree is grouped. I don't know if that's what you mean by block.

StykFacE
26th Jan 2007, 08:58 pm
upload the file please :)

profcad
26th Jan 2007, 09:02 pm
Type LIST and select a tree and it will list the information. For example if it is a block it will display...BLOCK REFERENCE

Command: list
Select objects: 1 found
Select objects:
BLOCK REFERENCE Layer: "0"
Space: Model space
Handle = 1f02
Block Name: "AC01_073104jh"

gib65
27th Jan 2007, 12:36 am
No, it didn't say BLOCK REFERENCE.

Tried to upload the file, but I couldn't.

profcad
27th Jan 2007, 12:49 am
What did it say?

If they are not block you will not be able to replace the objects with another object.

ASMI
28th Jan 2007, 10:33 am
It not the stupid question and sometimes such is required. However it is impossible by standard AutoCAD tools, but possible to use lisp.


(defun c:frto(/ ACTDOC COPOBJ ERRCOUNT EXTLST
EXTSET FROMCEN LAYCOL MAXPT CURLAY
MINPT OBJLAY OKCOUNT OLAYST
SCLAY TOCEN TOOBJ VLAOBJ *ERROR*)

(vl-load-com)

(defun *ERROR*(msg)
(if olaySt
(vla-put-Lock objLay olaySt)
); end if
(vla-EndUndoMark actDoc)
(princ)
); end of *ERROR*


(defun GetBoundingCenter(vlaObj / blPt trPt cnPt)
(vla-GetBoundingBox vlaObj 'minPt 'maxPt)
(setq blPt(vlax-safearray->list minPt)
trPt(vlax-safearray->list maxPt)
cnPt(vlax-3D-point
(list
(+(car blPt)(/(-(car trPt)(car blPt))2))
(+(cadr blPt)(/(-(cadr trPt)(cadr blPt))2))
0.0
); end list
); end vlax-3D-point
); end setq
); end of GetBoundingCenter

(if(not(setq extSet(ssget "_I")))
(progn
(princ "\n>>> Select distination objects and press Enter: ")
(setq extSet(ssget))
); end progn
); end if
(if(not extSet)
(princ "\nDistination objects isn't selected!")
); end if
(if
(and
extSet
(setq toObj(entsel "\n>>> Select source object: "))
); and and
(progn
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-Acad-object))
layCol
(vla-get-Layers actDoc)
extLst
(mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp
(mapcar 'cadr(ssnamex extSet))))
vlaObj(vlax-ename->vla-object(car toObj))
objLay(vla-Item layCol
(vla-get-Layer vlaObj))
olaySt(vla-get-Lock objLay)
fromCen(GetBoundingCenter vlaObj)
errCount 0
okCount 0
); end setq
(vla-StartUndoMark actDoc)
(foreach obj extLst
(setq toCen(GetBoundingCenter obj)
scLay(vla-Item layCol
(vla-get-Layer obj))
);end setq
(if(/= :vlax-true(vla-get-Lock scLay))
(progn
(setq curLay(vla-get-Layer obj))
(vla-put-Lock objLay :vlax-false)
(setq copObj(vla-copy vlaObj))
(vla-Move copObj fromCen toCen)
(vla-put-Layer copObj curLay)
(vla-put-Lock objLay olaySt)
(vla-Delete obj)
(setq okCount(1+ okCount))
); end progn
(setq errCount(1+ errCount))
); end if
); end foreach
(princ
(strcat "\n" (itoa okCount) " were changed. "
(if(/= 0 errCount)
(strcat (itoa errCount) " were on locked layer! ")
""
); end if
); end strcat
); end princ
(vla-EndUndoMark actDoc)
); end progn
(princ "\nSource object isn't selected! ")
); end if
(princ)
); end of c:frto