Author Topic: [Block Problem] How to Add Selection Set to Block which insert scale is not 1.0  (Read 3322 times)

0 Members and 1 Guest are viewing this topic.

chlh_jd

  • Guest
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 .
Code: [Select]
(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 . 

fixo

  • Guest
Just a hint: use vlax-tmatrix
Something along this way, almost not tested  though:
Code: [Select]
  (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))   
    )


chlh_jd

  • Guest
Thanks fixo !
Thanks Lee Mac !
I was a business trip , I'll test yours 4 days later , thank you very much ! :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
No worries! Have a good trip  :-)

chlh_jd

  • Guest
Hi Lee Mac !
Nice programe !
However the returns block can't be used by the command "_.refedit" , is it some codes to change ?

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
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?

chlh_jd

  • Guest
Hi Lee Mac !
See the first post , I've send the test drawing . :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
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.

chlh_jd

  • Guest
Hi Lee Mac !
I'm so sorry for my wrong test way !
I noted this statement
Code: [Select]
(vla-regen doc acAllViewports) because it take a few time  in my drawing . So it take the mistaken ...above ... :oops:

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
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  :-)

chlh_jd

  • Guest
Seriously agree Lee Mac's !!!