TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on September 01, 2022, 04:45:04 AM

Title: Copy text from model to layout
Post by: civil.eng 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.
Title: Re: Copy text from model to layout
Post by: dexus 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
Title: Re: Copy text from model to layout
Post by: civil.eng 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)
Title: Re: Copy text from model to layout
Post by: dexus 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. )
Title: Re: Copy text from model to layout
Post by: mhupp on September 01, 2022, 11:51:27 AM
Can't beat the goat

http://www.lee-mac.com/ms2ps.html
Title: Re: Copy text from model to layout
Post by: BIGAL 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)
)
Title: Re: Copy text from model to layout
Post by: civil.eng 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.