Author Topic: [XDrX-Function(16)]Clone objects between arbitrary spaces (4) - Block to Block  (Read 412 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 527
Last time I talked about the principle of deep cloning and cloning objects from tiles to model space. For details, see:

============

Deep clone objects between arbitrary spaces (1) - Block TO MS:
http://www.theswamp.org/index.php?topic=58859.0

Deep clone objects between arbitrary spaces (2) - MS TO Block:
http://www.theswamp.org/index.php?topic=58860.0

Deep clone objects between arbitrary spaces (3) - BLOCK TO PS:
http://www.theswamp.org/index.php?topic=58862.0

============

Today, we will continue to talk about the opposite operation, cloning objects from block to block.

The following demonstrates cloning the original text position of BLOCK1 to another BLOCK2.



Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt-block->block ()
  2.   (if (and
  3.            (setq txt1 (xdrx-nentselex "\nPick source Text Object IN Block<Exit>:" '((0 . "text"))))
  4.            (setq blkref1 (car (last txt1)));Insert
  5.            (setq txt1 (car txt1))
  6.            (setq blkref2 (car (xdrx-entsel "\nPick Dest Block<Exit>:" '((0 . "insert")))))
  7.            
  8.            (setq mat-block1->ms (xdrx-matrix-block2wcs blkref1);wcs->block transform Matrix
  9.                  mat-block1->ms (xdrx-matrix-inverse mat-block1->ms));block->mspace transform Matrix
  10.            (setq mat-ms->block2 (xdrx-matrix-block2wcs blkref2));wcs->block transform Matrix
  11.  
  12.            (setq block2space (xdrx-getpropertyvalue blkref2 "blocktablerecord" t))
  13.  
  14.            ;;ms->ps,mat-block->ms,Multiply the matrix to the left
  15.            (setq mat-block1->block2 (xdrx-matrix-product mat-ms->block2 mat-block1->ms))
  16.       )
  17.     (progn
  18.        ;|
  19.         1.Deep cloning, clone objects in any space (block table records, symbol table records, dictionary)
  20.         2.ownerid is the model space block table record, and the transformation matrix is mat-block2wcs
  21.         3.Complete the in-situ cloning of the text from the block's block table record to the another Block.
  22.        |;
  23.       (setq txt-block2 (xdrx-object-deepclone block2space txt1 mat-block1->block2));;Clone into Block2
  24.       (xdrx-setpropertyvalue (car txt-block2)
  25.         "textstring" (xdrx-string-format "I'm In %s" block2name)
  26.         "color" 2
  27.       )    
  28.       (xdrx-object-regen blkref2)
  29.     )
  30.   )
  31.   (princ)
  32. )
« Last Edit: December 10, 2023, 10:40:59 AM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net