Author Topic: [XDrX-Function(14)]Deep clone objects between arbitrary spaces (2) - MS TO Block  (Read 382 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:

http://www.theswamp.org/index.php?topic=58859.0

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

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



The above animations respectively demonstrate adding text to the BLOCK in model space, and using the xdrx-nentselex function in paper space to select text in model space and add it to the BLOCK.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if (and (setq obj (xdrx-nentselex "\nPick Text Object To Block<Exit>:" '((0 . "text"))))
  3.            (setq obj (car obj))
  4.            (setq txth (xdrx-getpropertyvalue obj "textheight"))
  5.            (setq e (xdrx-nentselex
  6.                      "\nPick Block <Exit>:"
  7.                    )
  8.            )
  9.            (setq blkref (cadr (last e));Insert
  10.                  scl (xdrx-getpropertyvalue blkref "scalefactors")
  11.                  blkrecord (xdrx-getpropertyvalue blkref "blocktablerecord" t)
  12.                  blkname (xdrx-getpropertyvalue blkrecord "name")
  13.                  vport  (last (last e));VPort object (if executed in paper space, this data will be generated)
  14.            )
  15.            (setq mat-block2wcs (xdrx-matrix-block2wcs blkref));WCS->BLOCK transform Matrix
  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 circle from the block's block table record to the model space.
  22.        |;
  23.       (setq e (xdrx-object-deepclone blkrecord obj mat-block2wcs))
  24.       (xdrx-object-regen blkref)
  25.       (xdrx-setpropertyvalue (car e)
  26.         "textstring" (xdrx-string-format "I'm In %s" blkname)
  27.         "textheight" (* (/ 1.0 (car scl))txth)
  28.         "color" 5
  29.       )
  30.     )
  31.   )
  32.   (princ)
  33. )
« Last Edit: December 09, 2023, 05:09:28 PM 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