TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: chlh_jd on February 03, 2011, 12:32:46 AM
-
Hi All
How to Add selection Set to block which insert scale is not 1:1 , don't change the selected objects's Location & size .
Here's a rough code to add selection set to block which inserted by 1:1 sc .
(defun ax:AddObjectsToBlock (blk ss / doc blkref blkdef inspt refpt ss-obj-list)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
blkref (vlax-ename->vla-object blk)
blkdef (vla-Item (vla-get-Blocks doc) (vla-get-Name blkref))
inspt (vlax-variant-value (vla-get-InsertionPoint blkref))
refpt (vlax-3d-point '(0 0 0))
)
(setq ss-obj-list nil)
(foreach en (wjm_ss2lst ss)
(setq ss-obj-list (cons (vlax-ename->vla-object en) ss-obj-list))
)
(setq ss-obj-list
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbobject
(cons 0 (1- (length (wjm_ss2lst ss))))
)
ss-obj-list
)
)
)
(foreach en (wjm_ss2lst ss)
(setq obj (vlax-ename->vla-object en))
(vla-Move obj inspt refpt)
)
(vla-CopyObjects doc ss-obj-list blkdef)
(foreach en (wjm_ss2lst ss)
(setq obj (vlax-ename->vla-object en))
(vla-Delete obj)
)
(princ)
)
(defun wjm_ss2lst (ss / i e lst)
(if (= (type ss) 'PICKSET)
(progn
(setq i -1)
(while (setq e (ssname ss (setq i (1+ i))))
(if (= (type e) 'ENAME) (setq lst (cons e lst)) nil)
)
lst
)
nil
)
)
I've uploaded the test drawing .
-
Just a hint: use vlax-tmatrix
Something along this way, almost not tested though:
(vl-load-com)
(setq ent (nentselp "\nSelect a block >> ")
blk (last ent)
mtx (vlax-tmatrix (caddr ent))
blkref (vlax-ename->vla-object (car blk))
inspt (vla-get-insertionpoint blkref)
ss (ssget)
refpt (vlax-3d-point (getpoint "\n Pick reference point>> "))
objs(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar'cadr (ssnamex ss))))
)
(foreach obj objs
(vl-catch-all-apply 'vla-move (list obj refpt inspt))
(vl-catch-all-apply 'vla-transformby (list obj mtx))
)
-
http://lee-mac.com/addobjectstoblock.html (http://lee-mac.com/addobjectstoblock.html)
-
Thanks fixo !
Thanks Lee Mac !
I was a business trip , I'll test yours 4 days later , thank you very much ! :-)
-
No worries! Have a good trip :-)
-
Hi Lee Mac !
Nice programe !
However the returns block can't be used by the command "_.refedit" , is it some codes to change ?
-
Nice programe !
Thanks :-)
However the returns block can't be used by the command "_.refedit" , is it some codes to change ?
All seems fine for me - I'm not sure what could really go wrong, as I am only adding objects to the Block Definition... In what situation is the problem occurring?
-
Hi Lee Mac !
See the first post , I've send the test drawing . :-)
-
See the first post , I've send the test drawing . :-)
I tried my program on the first drawing and all seems to work fine - I was able to use the refedit command following the addition of the extra objects and all worked without error.
-
Hi Lee Mac !
I'm so sorry for my wrong test way !
I noted this statement (vla-regen doc acAllViewports)
because it take a few time in my drawing . So it take the mistaken ...above ... :oops:
-
I suppose the Regen could be removed from the code and performed at a later time, but a Regen is necessary to update all Instances of the selected block :-)
-
Seriously agree Lee Mac's !!!