Author Topic: attribute 'linking'  (Read 8141 times)

0 Members and 1 Guest are viewing this topic.

rooster jk

  • Guest
attribute 'linking'
« on: April 27, 2011, 03:15:29 PM »
ok, so i started another topic that has lead me to believe i need to start this one...

has anyone found a way to link an object to an attribute?  lets say you have a block that you need to put an area of an object into.  so you have a rectangle as the object and you have a block that has an attribute in it that you want the value of to be linked to the rectangle's area.  so if and when you change the size of the rectangle that the attribute would update.  i have found a vlisp routine that will let me place a field that would be linked to the object so perhaps this is starting point?

really what i'm after isn't just related to the area, it's just an example.  what i'm really after is being able to link objects that have values to blocks that have attributes.

any ideas or suggestions would be greatly appreciated...

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #1 on: April 27, 2011, 03:31:27 PM »
after reading this i have realized that to achomplish what i'm asking isn't that dif by using a field in the block att.  but what i'm tryhing to do is create a lisp routine that will run something like this...

USER: run lisp routine

CAD: select block that has attribute to be changed:

USER: select block that has the attribute that you want to update

CAD: which attribute do you wish to change?

USER: select from list the attribute that you want to update

CAD: select object to link to block

USER: select object with desired value of attribute

CAD: select object's value that you want to use to update attribute

USER: select object's value

CAD: updates the block attribute and returns to command line

hope this is more clear as to what i'm looking to achomplish

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: attribute 'linking'
« Reply #2 on: April 27, 2011, 03:40:30 PM »
Hi,

You can have a look at this thread, last release here.
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: attribute 'linking'
« Reply #3 on: April 27, 2011, 03:47:47 PM »
If you want to go the field route, then this code will help you out.
[ http://www.theswamp.org/index.php?topic=20446.0 ]
Tim

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

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: attribute 'linking'
« Reply #4 on: April 27, 2011, 05:55:32 PM »
What are you referring to when you say 'Object's Value' ? Another attribute? An area? A Text Value?

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #5 on: April 28, 2011, 12:49:53 AM »
yes object's value could be another att or an area or a vol...really anything that the object will produce as a value that is of use.  there is more than one thing i'm working on now.  first i was trying to be able to link a 3d solid or masselement's volume to an attribute in a title block, with the idea being that once they were linked the att would be updatable as the object changes.  i know how to use a field to acchomplish this but its time consuming and cumbersome to do so i'm trying to make it a more streamlined process.

i also am trying to be able to link a block with lots of attributes in it to a another block.  the idea here is that i have a block that has attributes in it that a user fills in.  i then would like to be able to take this block and 'link' it to another block where the values would be transfered if you will to the other block.  make any sense?  i know that with a field you can do this but again it's time consuming to do an edit and manually 'link' each att to the block.

thanks for any help.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: attribute 'linking'
« Reply #6 on: April 28, 2011, 05:09:16 AM »
A LISP program could certainly be written to create the fields for you following selection of the source object and object to house the field. Here is one such example.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: attribute 'linking'
« Reply #7 on: April 28, 2011, 10:54:31 AM »
Post a sample drawing. I'm a visual learner  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #8 on: April 28, 2011, 02:30:11 PM »
A LISP program could certainly be written to create the fields for you following selection of the source object and object to house the field. Here is one such example.

what you have sent me to is exactly what i'm looking for, with the only real dif being that i would like it to get the volume from a 3d-solid or masselement.  one problem i have run across in trying to do this is that 3d solids volumes and masselements volume behave differently.  3d solids volume when retrieved from cad if you will only come in cubic inches, while masselements values come in whatever the volume units of the drawing are set to.  so i'm not sure if in the lisp routine that there would need to be something that changes the volume units setting to cubic inches so that if a 3d solid or masselement is selected that the output is consistent.  the reality is that the final product i'm looking for is cubic yards, but it's just math to change it from cubic inches.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: attribute 'linking'
« Reply #9 on: April 28, 2011, 02:57:59 PM »
Hi,

AFAIK, you won't get the volume (neither other 3d solid mechanic property) in a field.
You can only get it using the COM/ActiveX properties (vla-get-volume ...) and fill an attribute with the result, but if you want your attribute to be dynamically linked to the 3d solid, you'll have to use reactors as in the exammple in the link I provided.
Speaking English as a French Frog

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #10 on: April 28, 2011, 03:13:26 PM »
i'm not trying to get the volume from a field. i'm trying to get the volume of an object to be dynamically linked to an attribute in a block.  i have a lisp routine that will allow me to select either a 3d object or masselement and then places a field in the drawing.  this is not that useful really when i can get that info by running massprop on the 3d solid or selecting the masselement and looking in the properties.  what i'm really after here is the ability to place the volume of an object into an attribute and have the attribute update if the objects volume changes.  now i can do this with a field in the attribute but again it's time consuming to edit and 'link' the object everytime.  so i'm trying to automate that process by being able to select the attribute and then select the object and be done.  i'm pretty sure that Lee Mac has this figured out with the area link that he posted in his response with some minor tweaking.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: attribute 'linking'
« Reply #11 on: April 28, 2011, 03:37:01 PM »
The code I linked to will allow you to link the volume property of a 3d solid, to a text entity ( attribute, text or mtext ).  You can use that, or wait for Lee to respond.
Tim

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

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: attribute 'linking'
« Reply #12 on: April 28, 2011, 05:00:22 PM »
In my program change [Line 33]

Code: [Select]
(ssget '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE")))
to:

Code: [Select]
(ssget '((0 . "3DSOLID")))
And [Line 46]:

Code: [Select]
">%).Area>% + "
to:

Code: [Select]
">%).Volume>% + "

Oh, and change the command name and prompts accordingly.

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #13 on: April 28, 2011, 05:24:36 PM »
that works for the 3dsolids...any ideas on how to make it work for both 3d solids and masselements?  also, back to the issue of it giving the data in cubic inches as opposed to cubic yards?  i'm really not sure what the answer will be here if we make it so that this will work on both 3d solids and masselements as they don't behave the same.  i have attached a lisp that i created from another lisp that i can't rememeber who wrote - so i appologize for not being able to tell who's this was to begin with...i'm posting it so you can see what i mean by it being able to do both 3dsolids as well as masselements and the difference in the data output.  to use this you have to first pick an object, then pick where you want the field to be placed, and then pick the object with the volume you want.  please let me know your thougths.

Code: [Select]
(defun c:VOL ()
(vl-load-com)
;;get a reference to model space
(setvar "textsize" 0.09375)
(setvar "luprec" 8)
(setq *model-space*
       (vla-get-ModelSpace
(vla-get-ActiveDocument (vlax-get-acad-object))
       )
)
;;pass this function an entity and a point
(defun Linkedvol (ent pt / obj objID ip width str)
  ;;convert the entity to an object
;;;  (setq obj   (vlax-ename->vla-object ent)
;;; ;;get the object ID
;;; objID (vla-get-objectid obj)

  (setq vl1 (car (entsel "\nSelect Volume Entity: ")))
  (setq objID (vlax-invoke-method (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))) "GetObjectIdString" (vlax-ename->vla-object vl1) :vlax-False))

  (setq ;;convert the point
ip    (vlax-3D-Point pt)
;;set the width for the MTEXT
width 0.0
  )
;;set the string - this creates the field
;;; str   (strcat
;;; "%<\\AcObjProp Object(%<\\_ObjId "(rtos objID 2 0)">%).Volume \\f \"%lu2%ct6%qcu yd\">%"
;;;      )

  (setq str (strcat "%<\\AcObjProp Object(%<\\_ObjId " objID ">%).Volume \\f \"%lu2%ct6%qf1%pr2 CU YD\">%"))

  ;;Create the MTEXT entity containing the field.
  (vla-addMText *model-space* ip width str)
)

;; Set A = the entity and set B = Point for text
(setq a (car (entsel)) b (getpoint "\n Select Point To Locate Field: "))
;;Call the function
(linkedvol a b)
(princ)
  )
« Last Edit: April 28, 2011, 08:03:49 PM by CAB »

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #14 on: April 28, 2011, 05:29:05 PM »
it appears as though i need to get a lesson on how to post code!!!

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: attribute 'linking'
« Reply #15 on: April 28, 2011, 05:31:08 PM »
it appears as though i need to get a lesson on how to post code!!!

Maybe take a visit to the 'First things First' board.

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #16 on: April 28, 2011, 05:33:21 PM »
it appears as though i need to get a lesson on how to post code!!!

Maybe take a visit to the 'First things First' board.


good idea for sure...

Code: [Select]
(defun c:VOL ()
(vl-load-com)
;;get a reference to model space
(setvar "textsize" 0.09375)
(setvar "luprec" 8)
(setq *model-space*
       (vla-get-ModelSpace
(vla-get-ActiveDocument (vlax-get-acad-object))
       )
)
;;pass this function an entity and a point
(defun Linkedvol (ent pt / obj objID ip width str)
  ;;convert the entity to an object
;;;  (setq obj   (vlax-ename->vla-object ent)
;;; ;;get the object ID
;;; objID (vla-get-objectid obj)

  (setq vl1 (car (entsel "\nSelect Volume Entity: ")))
  (setq objID (vlax-invoke-method (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))) "GetObjectIdString" (vlax-ename->vla-object vl1) :vlax-False))

  (setq ;;convert the point
ip    (vlax-3D-Point pt)
;;set the width for the MTEXT
width 0.0
  )
;;set the string - this creates the field
;;; str   (strcat
;;; "%<\\AcObjProp Object(%<\\_ObjId "(rtos objID 2 0)">%).Volume \\f \"%lu2%ct6%qcu yd\">%"
;;;       )

  (setq str (strcat "%<\\AcObjProp Object(%<\\_ObjId " objID ">%).Volume \\f \"%lu2%ct6%qf1%pr2 CU YD\">%"))

  ;;Create the MTEXT entity containing the field.
  (vla-addMText *model-space* ip width str)
)

;; Set A = the entity and set B = Point for text
(setq a (car (entsel)) b (getpoint "\n Select Point To Locate Field: "))
;;Call the function
(linkedvol a b)
(princ)
  )

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: attribute 'linking'
« Reply #17 on: April 28, 2011, 06:16:53 PM »
I appologise, I thaught it wasn't possible to get the volume of a 3d solid in a field. :oops:
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: attribute 'linking'
« Reply #18 on: April 28, 2011, 06:26:27 PM »
I appologise, I thaught it wasn't possible to get the volume of a 3d solid in a field. :oops:

It doesn't look like you can with the field command, at least in '09 it doesn't show a volume option when picking a 3d solid as an object.  But with code, you can create a field to any property that can be returned with ActiveX.
Tim

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

Please think about donating if this post helped you.

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #19 on: April 28, 2011, 06:37:34 PM »
I appologise, I thaught it wasn't possible to get the volume of a 3d solid in a field. :oops:

It doesn't look like you can with the field command, at least in '09 it doesn't show a volume option when picking a 3d solid as an object.  But with code, you can create a field to any property that can be returned with ActiveX.

so i have taken the code that Lee linked me to and modified to be able to get a 3dsolid and a mass element volume linked to the attribute. but i'm still having the issue of the 3d solid only giving me the value in cubic inches and the mass elements giving me the value in whatever the volume units of the drawing are set to.  this causes me greif since i need to be able to link both of these objects and have the same output.  so i'm thinking that it's going to involve using a setvar and setting the volume units to cubic inches and then doing math in the lisp to be able to get the output to cubic yards...any thoughts???

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #20 on: April 28, 2011, 06:39:24 PM »
i should probably say at this point that i'm using Architecture 2011...which is where the mass element stuff comes from.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: attribute 'linking'
« Reply #21 on: April 28, 2011, 06:40:49 PM »
You can add a conversion factor to the field formatting to convert from cubic inches to cubic yards.

As for the Mass Element - I've never worked with one so I don't know the ObjectName, but I should imagine it would be a case of using an IF statement whilst iterating through the SelectionSet, and if the object is a Solid, use one field code, if a Mass Element, use another.

rooster jk

  • Guest
Re: attribute 'linking'
« Reply #22 on: April 28, 2011, 07:08:13 PM »
this lets me pick either the 3dsolid or the mass element

Code: [Select]
(and (ssget '((0 . "3dsolid,AEC_MASS_ELEM")))

and i'm sure that from here the conversion isn't that difficult.  but i'm wondering if we can set the volume units of the drawing so that if either are picked the same output happens???

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: attribute 'linking'
« Reply #23 on: April 29, 2011, 03:33:35 AM »
Quote
It doesn't look like you can with the field command, at least in '09 it doesn't show a volume option when picking a 3d solid as an object.  But with code, you can create a field to any property that can be returned with ActiveX.

Thanks Tim, I didn't know that.
Glad to learn a knew thing.
Speaking English as a French Frog

ronjonp

  • Needs a day job
  • Posts: 7529
Re: attribute 'linking'
« Reply #24 on: April 29, 2011, 11:21:27 AM »
Quote
It doesn't look like you can with the field command, at least in '09 it doesn't show a volume option when picking a 3d solid as an object.  But with code, you can create a field to any property that can be returned with ActiveX.

Thanks Tim, I didn't know that.
Glad to learn a knew thing.

X2 :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: attribute 'linking'
« Reply #25 on: August 15, 2012, 09:41:57 AM »
A LISP program could certainly be written to create the fields for you following selection of the source object and object to house the field. Here is one such example.

Lee, I was trying a similar exercise myself, but I kept getting #### for the field - so I found this thread and looked at your example code. I'm doing (what I think) is the same thing. How about another set of eyes to look at this code snip?

Code: [Select]
(setq att2obj (vlax-ename->vla-object att2))
(if (> (vl-string-search "x64" (getvar "platform")) 0)
  (progn
    (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
    (setq objid (vlax-invoke-method util "GetObjectIdString" att2obj :vlax-False))
   )
  (setq objid (rtos oba 2 0))
)
(setq new (strcat "%<\\AcObjProp Object(%<\\_ObjId " objid ">%).Length \\f \"%lu2%pr2\">%"))
(vla-put-TextString att2obj new)

The code runs fine, it inserts the field, but the display of the field is ####
The field string is: %<\AcObjProp Object(%<\_ObjId 8796083683168>%).Length>% , which matches exactly what I get if I manually create the field. What am I overlooking?
TIA

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: attribute 'linking'
« Reply #26 on: August 15, 2012, 10:07:15 AM »
Hi rk,

Assuming the variable 'oba' is defined, your code looks to be correct, though, I personally would write it in the following way:

Code: [Select]
(setq obj (vlax-ename->vla-object att2))
(if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
    (setq id (vla-getobjectidstring (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))) obj :vlax-false))
    (setq id (itoa (vla-get-objectid obj)))
)
(vla-put-textstring obj (strcat "%<\\AcObjProp Object(%<\\_ObjId " id ">%).Length \\f \"%lu2%pr2\">%"))

Note that you may require a Regen to display Fields in some objects (such as attributes).

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: attribute 'linking'
« Reply #27 on: August 16, 2012, 03:30:24 AM »
Note that you may require a Regen to display Fields in some objects (such as attributes).
That's probably the major reason. You could also send a selection of objects to the UpdateField command.

I wonder if it's doing much use if you use the ActiveX Object's Update method on the attribute and/or block - just to not need a full regen and/or command call.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.