Author Topic: Change Field Object in Mtext  (Read 4262 times)

0 Members and 1 Guest are viewing this topic.

Shade

  • Guest
Change Field Object in Mtext
« on: March 17, 2008, 01:23:35 PM »
Does any one have a lisp that will change the object in a field with out changing the other field settings.
I want to be able to quickly make a text with a field in it that tells me an objects property and they copy the text and hook up the field to another object without re-editiing the field.

For example;
Text field A is set to object; linetype of object A and I want to copy the text and set the field to linetype, object B by I picking object B.

I may have to write my own lisp, and I am currently brainstorming and writing pseudo code for it as we speak.

Any help would be appreciated.... :mrgreen:

PS I will post some code when I have something to post.  ;-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change Field Object in Mtext
« Reply #1 on: March 17, 2008, 01:34:21 PM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

kozmos

  • Newt
  • Posts: 114
Re: Change Field Object in Mtext
« Reply #2 on: March 17, 2008, 11:40:41 PM »
Try the codes
Code: [Select]
;;; Input obj=ENAME
(Defun x-get-fieldcode (obj / abc)
  (if (and vla-fieldcode
   (setq obj (vlax-ename->vla-object obj))
   (vlax-method-applicable-p obj "FieldCode")
   (setq abc (vla-fieldcode obj))
      )
    (while (vl-string-search "_ObjIdx" abc)
      (setq abc (vl-string-subst "_ObjId" "_ObjIdx" abc))
    )
  )
  abc
)
;;; Input obj=ENAME
(Defun x-get-fieldobj (obj / abc pos idx obx)
  (setq abc (x-get-fieldcode obj))
  (while (wcmatch abc "*(%<\\_ObjId ##########>%)*")
    (setq pos (+ 12 (vl-string-search "(%<\\_ObjId " abc))
  idx (cons (substr abc pos 10) idx)
  abc (substr abc (+ pos 11))
    )
  )
  (foreach pos idx
    (setq obx (cons (vlax-vla-object->ename (vla-objectidtoobject
      (vla-Get-ActiveDocument (vlax-Get-Acad-Object))
      (read pos)
    ))
    obx
      )
    )
  )
  obx
)
;;; Input obj=ENAME
;;; Input new=ENAME or ENAME LIST
(Defun x-put-fieldobj(obj new / abc xyz ob nn)
  (setq abc (x-get-fieldcode obj)
xyz (x-get-fieldobj obj)
xyz (mapcar 'vlax-ename->vla-object xyz)
xyz (mapcar 'vla-get-objectid xyz)
xyz (mapcar 'vl-prin1-to-string xyz)
  )
  (if (= (type new) 'ename) (setq new (list new)))
  (setq new (mapcar 'vlax-ename->vla-object new)
new (mapcar 'vla-get-objectid new)
new (mapcar 'vl-prin1-to-string new)
  )
  (foreach ob xyz
    (setq nn (car new) new (cdr new))
    (if nn
      (setq abc (vl-string-subst (strcat "(%<\\_ObjId " nn) (strcat "(%<\\_ObjId " ob) abc))
    )
  )
  (setq obj (vlax-ename->vla-object obj))
  (vla-put-textstring obj "CLEAR")
  (vla-put-textstring obj abc)
)
« Last Edit: March 17, 2008, 11:46:27 PM by kozmos »
KozMos Inc.

Shade

  • Guest
Re: Change Field Object in Mtext
« Reply #3 on: March 18, 2008, 10:02:10 AM »
Thanks for the help!  :-D
Its what I needed for now....

Shade

  • Guest
Re: Change Field Object in Mtext
« Reply #4 on: March 18, 2008, 11:43:35 AM »
How does one check to see if new object has all the same field options as the existing.

ie. old object is a circle and has radius but new object is a line so no radius is present?

I have thought about isolating the type of field through the text string and I have got it to work.
Now how do I check to see if my new entity has the same field properties as the existing one?

kozmos

  • Newt
  • Posts: 114
Re: Change Field Object in Mtext
« Reply #5 on: March 18, 2008, 09:17:33 PM »
see vlax-property-available-p function
KozMos Inc.

Shade

  • Guest
Re: Change Field Object in Mtext
« Reply #6 on: March 19, 2008, 09:28:17 AM »
Thanks for the help Kozmos!
I appreciated it a lot!  :-D