Author Topic: Existing field to now link to active layout  (Read 2914 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Existing field to now link to active layout
« on: December 06, 2007, 11:58:35 AM »
Someone on the Adesk Ng was asking about this, and I thought it might be fun to see what I could find out.  I don't use fields, and do not pretend to know what I did, but it works.

I created a field linked to a text object.  I then ran this code, and selected the field object just created, and it worked in changing the association of the existing field from the text object to the layout it is in.  If you change the name of the layout it will change the field.

It is a starting point, so use it as you like.

Code: [Select]
(progn
(setq Sel (entsel "\n Select object to change field value: "))
(setq Obj (vlax-ename->vla-object (car Sel)))
(if
(and
(equal (vla-get-HasExtensionDictionary Obj) :vlax-true)
(setq Dict (vla-GetExtensionDictionary Obj))
(not
(vl-catch-all-error-p
(setq FDict
(vl-catch-all-apply
'vla-Item
(list
Dict
"ACAD_FIELD"
)
)
)
)
)
)
(vlax-for tempObj FDict
(setq tempData (entget (vlax-vla-object->ename tempObj)))
[color=red]; here I thought you needed to change this to layout, but you do not.[/color]
;(setq tempData (subst (cons 1 "_layout") (assoc 1 tempData) tempData))
;(setq tempData (subst (cons 1 "_text") (assoc 1 tempData) tempData))
;(entmod tempData)
(setq tempData (entget (cdr (assoc 360 tempData))))
(setq tempData
(subst
'(2 .  "\\AcObjProp Object(%<\\_ObjIdx 0>%).Name")
(assoc 2 tempData)
tempData
)
)
(setq tempData
(subst
(cons
330
(vlax-vla-object->ename
(setq ActLo
(vla-get-ActiveLayout
(vla-get-ActiveDocument
(vlax-get-Acad-Object)
)
)
)
)
)
(assoc 330 (reverse tempData))
tempData
)
)
(setq tempList
(vl-remove-if-not
'(lambda (x) (equal (car x) 1))
tempData
)
)
(setq tempData
(subst
'(1 . "Name")
(nth 1 tempList)
tempData
)
)
(setq tempData
(subst
(cons 1 (vla-get-Name ActLo))
(nth 2 tempList)
tempData
)
)
(setq tempData
(subst
(cons 301 (vla-get-Name ActLo))
(assoc 301 tempData)
tempData
)
)
(entmod tempData)
)
)
)
Tim

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

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Existing field to now link to active layout
« Reply #1 on: December 07, 2007, 12:11:53 AM »
I really need to read up on vlax, this looks promising for a few issues I see on a regular basis.
Thanks T!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Existing field to now link to active layout
« Reply #2 on: December 07, 2007, 11:58:23 AM »
I really need to read up on vlax, this looks promising for a few issues I see on a regular basis.
Thanks T!
You're welcome Kewl.  That is why I posted it here, so people can use it if they want.  Glad someone is.  :-)
Tim

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

Please think about donating if this post helped you.

daron

  • Guest
Re: Existing field to now link to active layout
« Reply #3 on: December 07, 2007, 12:19:25 PM »
Nice to have that programmed. I haven't tried yours, but I regularly have a field set to change when the layout name changes. I might try that.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Existing field to now link to active layout
« Reply #4 on: December 07, 2007, 12:22:29 PM »
Nice to have that programmed. I haven't tried yours, but I regularly have a field set to change when the layout name changes. I might try that.
Maybe later (if/when I get around to understand fields more) one could code up how to create one from code, instead of having to change one.  Let me know when you get a chance to try it Daron.  I would love to know how it works for someone that uses fields.
Tim

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

Please think about donating if this post helped you.

daron

  • Guest
Re: Existing field to now link to active layout
« Reply #5 on: December 07, 2007, 12:54:35 PM »
It's interesting, but as far as I can tell, the field has to be set up to accomplish this in the first place. However, the idea has merit and it would be really nice to expand the idea into something that would automatically place a text object with said field type in place.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Existing field to now link to active layout
« Reply #6 on: December 07, 2007, 01:14:33 PM »
It's interesting, but as far as I can tell, the field has to be set up to accomplish this in the first place.
The field has to be set up to link to something (an objects property).  In my test it was linked to a piece of text (the content), then I just changed what it was linked to, so it would now be linked to the specific layout (the name property).
Tim

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

Please think about donating if this post helped you.

daron

  • Guest
Re: Existing field to now link to active layout
« Reply #7 on: December 07, 2007, 01:21:26 PM »
Oh. So you could take any field object and make it behave with layout names. That's good.

Guest

  • Guest
Re: Existing field to now link to active layout
« Reply #8 on: December 07, 2007, 01:34:14 PM »
>>This<< is from a while back...  Might be of some help.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Existing field to now link to active layout
« Reply #9 on: December 07, 2007, 01:45:26 PM »
>>This<< is from a while back...  Might be of some help.
You don't really want to link to the 'ctab' system variable, as it will change when you change layouts, where might won't.  Mine will only change when one changes the name of the layout.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Existing field to now link to active layout
« Reply #10 on: December 07, 2007, 01:47:30 PM »
Oh. So you could take any field object and make it behave with layout names. That's good.
That is the intent.  That is why I wanted people who use fields to try it, as I don't use them, but on my tests it seem to do what is expected of it to do.

Right now it will only update to the current layout (that it is ran in), but if you want to choose the layout that wouldn't be hard to implement.
Tim

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

Please think about donating if this post helped you.