Author Topic: Copy text from model to layout  (Read 1027 times)

0 Members and 1 Guest are viewing this topic.

civil.eng

  • Newt
  • Posts: 66
Copy text from model to layout
« on: September 01, 2022, 04:45:04 AM »
Hello everyone,
I have had a method for copy an object in model space :

Quote
(setq newtxtobj (vla-copy txtobj))
(setq bp_txtobj (vlax-get txtobj 'InsertionPoint))
(vla-move newtxtobj(vlax-3d-point bp_owner) (vlax-3d-point pt_owner))

It's been working fine so far , with a project I have to copy a text from model to layout, but the copy of the text is created on the model after using this code while I intend to create it on "Layout1" (although I'm using CTAB to make current the layout) :

Code: [Select]
(setq obj (vlax-ename->vla-object (car (entsel))))

  (setq newobj (vla-copy obj))
  (setq bp (vlax-get obj 'InsertionPoint))

  (setvar "ctab" "Layout1")
  (setq pt (getpoint))
  (vla-move newobj
    (vlax-3d-point bp)
    (vlax-3d-point pt)
  )

Could someone tell me what the problem is with the codes ?

Thanks in advance.
« Last Edit: September 01, 2022, 04:48:07 AM by civil.eng »

dexus

  • Bull Frog
  • Posts: 208
Re: Copy text from model to layout
« Reply #1 on: September 01, 2022, 07:23:42 AM »
You can change in which layout an object is using entmake like this:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq ent (entget (car (entsel "\n Select object: "))))
  2.     (subst
  3.       (cons 410 "LayoutName") ; Target layout name
  4.       (assoc 410 ent)
  5.       ent
  6.     )
  7.   )
  8. )

You might also want to have a look at this:
http://www.lee-mac.com/ms2ps.html
« Last Edit: September 01, 2022, 07:27:42 AM by dexus »

civil.eng

  • Newt
  • Posts: 66
Re: Copy text from model to layout
« Reply #2 on: September 01, 2022, 09:56:57 AM »
Thank you for your respond,
Is it also possible to modify insertion point of the text with this method ? (within entmake)

dexus

  • Bull Frog
  • Posts: 208
Re: Copy text from model to layout
« Reply #3 on: September 01, 2022, 10:18:59 AM »
Sure, you can modify almost all dxf codes by stacking subst functions:

Code - Auto/Visual Lisp: [Select]
  1.   (and
  2.     (setq ent (entget (car (entsel "\n Select object: "))))
  3.     (member (cdr (assoc 0 ent)) '("TEXT" "MTEXT"))
  4.   )
  5.     (subst
  6.       (cons 410 "LayoutName") ; Target layout name
  7.       (assoc 410 ent)
  8.       (subst
  9.         (cons 10 '(10 10 0)) ; InsertionPoint of text
  10.         (assoc 10 ent)
  11.         ent
  12.       )
  13.     )
  14.    )
  15. )

Edit:
You might find this easier to read. Does the same as above.
Code - Auto/Visual Lisp: [Select]
  1.   (and
  2.     (setq ent (entget (car (entsel "\n Select object: "))))
  3.     (member (cdr (assoc 0 ent)) '("TEXT" "MTEXT"))
  4.   )
  5.   (progn
  6.     (setq newent (subst (cons 10 '(10 10 0)) (assoc 10 ent) ent)) ; InsertionPoint of text
  7.     (setq newent (subst (cons 410 "LayoutName") (assoc 410 newent) newent)) ; Target layout name
  8.     (entmake newent)
  9.   )
  10. )
« Last Edit: September 01, 2022, 10:22:55 AM by dexus »

mhupp

  • Bull Frog
  • Posts: 250
Re: Copy text from model to layout
« Reply #4 on: September 01, 2022, 11:51:27 AM »

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Copy text from model to layout
« Reply #5 on: September 01, 2022, 10:12:55 PM »
Just a guess copy text in model back on its self then use "Chspace" and (entlast). So will work for current layout.

Code: [Select]
(defun c:chsptxt ( / ent)
(command "mspace")
(setq ent (car (entsel "\n Select txt ")))
(command "chspace" (entlast) "")
(princ)
)
A man who never made a mistake never made anything

civil.eng

  • Newt
  • Posts: 66
Re: Copy text from model to layout
« Reply #6 on: September 03, 2022, 04:35:08 AM »
Just a guess copy text in model back on its self then use "Chspace" and (entlast). So will work for current layout.

Code: [Select]
(defun c:chsptxt ( / ent)
(command "mspace")
(setq ent (car (entsel "\n Select txt ")))
(command "chspace" (entlast) "")
(princ)
)

Thank you all guys, my problem has been resolved with your helps and rsponds.