Jump to content

Sweeter code for copy, rotate, scale and paste blocks


sadhu

Recommended Posts

I'm using the following code to copy all the blocks in a drawing and then rotate, scale and paste then on the same drawing in an orderly manner (like in a legend).

I need to select all the blocks with the attribute "num" even repeating ones.

 

(setq blklst (ssget"_:L" (list (cons 0 "INSERT"))) ; select blocks
     numblk (sslength blklst)    
     cnt 0      
)


(setq pt1 (getpoint "\nSelect insertion point of first block ... ")
(setq x1 (car pt1)
     y1 (cadr pt1))

      


(while (< cnt numblk)
(setq ent (ssname num_blklst cnt))
(setq en2p (entnext ent))    
(setq enlist2p (entget en2p)) 
(while (/= (cdr(assoc 0 enlist2p)) "SEQEND")      
         (cond ((= "num" (cdr (assoc 2 enlist2p))) ; handle blocks with attribute "num"
          (setq ins_pt_ent (cdr(assoc 10 (entget ent)))) ; get insertion point of block
          (setq rot_pt_ent (* 0.0174611111(- (cdr(assoc 50 (entget ent)))))) ; rotatation angle of block 
          (command "._copy" ent "" ins_pt_ent pt1 "") ; copy
              (setq ent (entlast)) 
          (command "_.change" ent "" pt1 rot_pt_ent) ; rotate
          (command "_.scale" ent "" pt1 2 "") ; scale
    
 
        ));cond
         
                   
       (setq en2p(entnext en2p))                             ;- Get the next sub-entity
        (setq enlist2p(entget en2p)) 
)
(setq pt1 (list x1 (- y1 10)))  
(setq cnt (+ cnt 1))
);while        
      

There are about a 100 blocks and the process is "rather" slow. I can "see" the copy and paste process going on.

 

Any help to make the process faster is welcome.

 

Thank you.

Edited by sadhu
(setq pt1 (list x1 (- y1 10))) ; substituted +
Link to comment
Share on other sites

There are about a 100 blocks and the process is "rather" slow. I can "see" the copy and paste process going on.

 

Any help to make the process faster is welcome.

 

Thank you.

 

[EDIT]: Express Tool has similar command MOROCO !!! :facepalm:

 

or change these command call

...
(command "._copy" ent "" ins_pt_ent pt1 "") ; copy
              (setq ent (entlast)) 
          (command "_.change" ent "" pt1 rot_pt_ent) ; rotate
          (command "_.scale" ent "" pt1 2 "") ; scale
...

 

to activeX suggestion


(setq o ([color="blue"]vla-copy[/color] (setq o (vlax-ename->vla-object ent))))
       ([color="blue"]vla-put-Rotation[/color] o rot_pt_ent)
       (apply '[color="blue"]vla-move[/color] (vl-list* o (mapcar 'vlax-3d-point (list ins_pt_ent (trans pt1 1 0)))))

(foreach x '([color="blue"]XScaleFactor YScaleFactor[/color])
 (vlax-put o x (*(vlax-get o x) 2.))
 )

 

also

(setq pt1 (list x1 [color="red"](setq y1[/color] (- y1 10.)[color="red"])[/color]))

 

your COND also can IF ... PROGN

 

command ATTSYNC if you wish

 

[EDIT]: ssget also can add '(66 . 1) ,

lastly remember to LOCALIZE

Edited by hanhphuc
'(66 .1) & foreach instead of mapcar & moroco
Link to comment
Share on other sites

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