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

0 Members and 1 Guest are viewing this topic.

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.