Author Topic: Get field ?  (Read 10980 times)

0 Members and 1 Guest are viewing this topic.

new_mem

  • Newt
  • Posts: 67
Get field ?
« on: October 19, 2011, 03:34:37 AM »
Can someone tell me the way get field of cell in table. ?

Thank u.


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #1 on: October 19, 2011, 05:44:57 AM »
Double click to edit the cell, then right-click --> Insert Field (or Ctrl+F). To get a formula, then as you've got it selected, right-click --> Insert --> Formula --> (Sum / Avg / Count / Cell / Equation)

Or do you mean you want to make a field through lisp? If so you simply need the field-codes and set that cell's value to the relevant field code. The field gets generated "automagically".

Or ... are you referring to making a field which points to a cell? If so I don't think there is a way other than formulas in the table itself.
« Last Edit: October 19, 2011, 05:48:56 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #2 on: October 19, 2011, 06:07:42 AM »
Actually doing some further investigation, you can generate the field-code programmatically. You need the table's ObjectId (see the function below). Then you need to insert a formula field with the following:
Code: [Select]
Table(###).A1Where ### is the object id of the table, and A1 is the address of the cell.

To get the object Id you could either go manually by making an object property field to that table then searching through the field code at the bottom for the number following %<\_ObjId ... e.g.
Quote
%<\_ObjId -1121994336>%
Or you could use this lisp function:
Code: [Select]
(defun c:GetObjId (/ en)
  (vl-load-com)
  (if (setq en (entsel))
    (princ (vla-get-ObjectId (vlax-ename->vla-object (car en))))
  )
  (princ)
)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Get field ?
« Reply #3 on: October 19, 2011, 07:47:25 AM »
Do you mean retrieving the value of that cell?

If so...

Code: [Select]
(vla-gettext <Table> <row> <col>)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #4 on: October 19, 2011, 08:14:30 AM »
Here's what I mean by using the formula with the table object's Id. Note it only work on cells containing numbers (no text and / or blanks).

Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

new_mem

  • Newt
  • Posts: 67
Re: Get field ?
« Reply #5 on: October 19, 2011, 09:32:06 AM »
Here's what I mean by using the formula with the table object's Id. Note it only work on cells containing numbers (no text and / or blanks).

Great.
That is simple.  :ugly:
Thanks
But it not true with table extract data.! how can fix it.!?


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #6 on: October 19, 2011, 09:36:43 AM »
You're welcome!
But it not true with table extract data.! how can fix it.!?
I'm unsure what you mean. The extract data should work fine AFAIK. Are you referring to Data Extract? That one generates a table, it doesn't read from a table (unfortunately).

Could you explain a bit more, what are you actually trying to achieve? Perhaps there's an alternative way of performing this.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

new_mem

  • Newt
  • Posts: 67
Re: Get field ?
« Reply #7 on: October 19, 2011, 09:43:00 AM »
Do you mean retrieving the value of that cell?

If so...

Code: [Select]
(vla-gettext <Table> <row> <col>)
Thanks.

True.  :lmao:

So how to select cell any by (entsel) and get ID and text of this cell.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get field ?
« Reply #8 on: October 19, 2011, 10:06:01 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #9 on: October 19, 2011, 10:07:26 AM »
Quick and dirty ... just copy to command line:
Code: [Select]
(setq tblObj (vlax-ename->vla-object (car (entsel))))Then to get the 1st row & 2nd column
Code: [Select]
(vla-gettext tblObj 0 1)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #10 on: October 19, 2011, 10:23:22 AM »
Also to obtain the cell's address from a point you can use the Table object's HitTest method. E.g.
Code: [Select]
(vlax-invoke-method tblObj 'HitTest (vlax-3D-point (getpoint)) (vlax-3D-point '(0.0 0.0 1.0)) 'r 'c)If the result is :vlax-true, then r will contain the row number and c the column number.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

new_mem

  • Newt
  • Posts: 67
Re: Get field ?
« Reply #11 on: October 19, 2011, 10:32:44 AM »
You're welcome!
But it not true with table extract data.! how can fix it.!?
I'm unsure what you mean. The extract data should work fine AFAIK. Are you referring to Data Extract? That one generates a table, it doesn't read from a table (unfortunately).

Could you explain a bit more, what are you actually trying to achieve? Perhaps there's an alternative way of performing this.

Okey,
I mean:
Step1: I get ID any cell by select table extract data but i want select cell by mouse.
Step2: Asign value text by field (some code lisp here)


new_mem

  • Newt
  • Posts: 67
Re: Get field ?
« Reply #12 on: October 19, 2011, 10:54:27 AM »
My code:
(setq obj_tbl (vlax-ename->vla-object (car (entsel "\nSelect object table")))
;"how can get cell data table by select position cell at 3dpoint ?
(setq value_cell (?)
(setq obj_text (vlax-ename->vla-object (car (entsel "\nSelect object text")))
   field_data (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos value_cell 2 0) ">%).TextString>%")
   )
  (vla-put-textstring obj_text field_data)
  (vla-update obd)
  (vl-cmdf "regen")

Realy thank u for your solution.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Get field ?
« Reply #13 on: October 19, 2011, 11:05:16 AM »
To my knowledge you cannot directly reference a field cell value using a Field in another object.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Get field ?
« Reply #14 on: October 19, 2011, 11:15:55 AM »
To my knowledge you cannot directly reference a field cell value using a Field in another object.
You "can" but it's not recommended ... nested fields require more than one regen (or other type of update) to propagate a change. So you could run into a scenario where the plotted value is inconsistent.

Though this is again pointing me in strange directions. I thought you wanted to place a field inside a text to duplicate a value from the table? If I'm still on the same track then perhaps this could help:
Code: [Select]
(vl-load-com)

;;; Helper function to get the cell reference of a picked point in a table
;;; tbl - the ActiveX object of the table
;;; pt  - the 3d WCS point
;;; Returns nil if none found, else returns a string such as A1 for column A and row 1
(defun TblHitTest (tbl pt / r c s n letters)
  (setq letters (vl-string->list "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
  (if (= :vlax-true (vla-HitTest tbl (vlax-3D-point pt) (vlax-3D-point (getvar 'ViewDir)) 'r 'c))
    (progn
      (setq s "")
      (while (> c -1)
        (if (= c 0)
          (setq s (strcat "A" s) c -1)
          (setq s (strcat (chr (nth (rem c (length letters)) letters)) s)
                c (fix (/ c (length letters)))
          )
        )
        (if (= c 0) (setq c -1))
      )
      (setq s (strcat s (itoa (1+ r))))
    )
  )
  s
)
Then you'd need a further getpoint to pick the "cell". Or you could try using the point returned by the entsel function (though usually that would be on one of the borders and may give strange results).
Code: [Select]
(setq pt (getpoint "\nPick cell: "))
Also your field-code doesn't look correct. Shouldn't it be something like this:
Code: [Select]
(strcat "%<\\AcExpr (Table(%<\\_ObjId " (itoa (vla-get-ObjectId obj_tbl) ">%)." (TblHitTest obj_tbl pt) ")>%
« Last Edit: October 19, 2011, 11:19:40 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.