Author Topic: [XDrX-Function(15)]Deep clone objects between arbitrary spaces (3) - BLOCK TO PS  (Read 370 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

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

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

The following demonstrates cloning the original text position of BLOCK to model space and paper space at the same time.



The demonstration is to clone the original position and size of text From BLOCK into ModelSpace and PAPERSPACE.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt_block->ps ()
  2.   (if (and (= (getvar "cvport") 1)
  3.            (setq txt (xdrx-nentselex "\nPick Text Object IN Block<Exit>:" '((0 . "text"))))
  4.            (setq blkref (car (last txt));Insert
  5.                  vport  (last (last txt));VPort object (if executed in paper space, this data will be generated)
  6.            )
  7.            (setq txt (car txt))
  8.            (setq mat-block->ms (xdrx-matrix-block2wcs blkref);WCS->BLOCK transform Matrix
  9.                  mat-block->ms (xdrx-matrix-inverse mat-block->ms));BLOCK->MSPACE transform Matrix
  10.            (setq mat-ms->ps (xdrx-matrix-ms2ps vport));;;MSPACE->PAPERSPACE transform Matrix
  11.            (setq paperspace (xdrx-get-paperspace)
  12.                  modelspace (xdrx-get-modelspace)
  13.            )
  14.            ;;ms->ps,mat-block->ms,Multiply the matrix to the left
  15.            (setq mat-block->ps (xdrx-matrix-product mat-ms->ps mat-block->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 model space and paperspace.
  22.        |;
  23.       (setq e (xdrx-object-deepclone modelspace TXT mat-block->ms));;Clone into modelspace
  24.        (xdrx-setpropertyvalue (car e)
  25.         "textstring" (xdrx-string-format "I'm In MS")
  26.         "color" 6
  27.       )    
  28.       (setq e (xdrx-object-deepclone paperspace TXT mat-block->ps));;Clone into paperpace
  29.       (xdrx-setpropertyvalue (car e)
  30.         "textstring" (xdrx-string-format "I'm In PS")
  31.         "color" 1
  32.       )
  33.     )
  34.   )
  35.   (princ)
  36. )
« Last Edit: December 10, 2023, 09:50:19 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