Author Topic: Table Question  (Read 3147 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Table Question
« on: June 08, 2009, 09:14:56 PM »
I have been testing a lisp to update the text found in a table.
Using nentsel to get the text entity which I update with entmod.
Using entupd on the table entity shows the change.

My question is, has anyone had problems with this method?
I am testing in ACAD2006 and seems to work fine.
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.

Joe Burke

  • Guest
Re: Table Question
« Reply #1 on: June 09, 2009, 08:17:40 AM »
Alan,

Have you tried it with mtext in a cell which uses a TrueType text style?

In that case nentsel will usually return nil in all versions which support tables. It may work in some cases, but it's totally unreliable.

It is a bug which I recently mentioned here and in the Autodesk customization NG.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Table Question
« Reply #2 on: June 09, 2009, 09:18:16 AM »
Thanks Joe,
Your way ahead of me on these tables. I just changed to TT Fonts and nothing is selected! :-(

Doing some reading this morning I see I am way behind on TABLES. :)

It appears as though you must use entsel to get the pick point and then loop through the table cells
using vla-hittest to see if that is the cell you want to change.

Otherwise you must have the user enter a Row & Column number to get to the cell.
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.

Joe Burke

  • Guest
Re: Table Question
« Reply #3 on: June 09, 2009, 09:29:49 AM »
Example file attached.

Nentsel will fail in most cases when an mtext object is picked in the left table. It will work within the table at right, apparently because the mtext objects in that table use an SHX text style.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Table Question
« Reply #4 on: June 09, 2009, 09:42:24 AM »
Using 2006 I can't get ENTSEL to pick the table by picking the SHX text!  :-o

Do you have to use GETPOINT and hunt for the TABLE?
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.

Joe Burke

  • Guest
Re: Table Question
« Reply #5 on: June 09, 2009, 09:52:09 AM »
Alan,

Food for thought:

  ;; Arguments: table vla-object and a WCS point
  ;; calling function should trans 1 0 nentselp pick point.
  ;; the table vla-object is the last last item in the list
  ;; returned by nentselp after conversion from ename to vla-object.
  (defun ST:GetRowCol (table pt / vector row col)
    (setq vector (vlax-make-safearray vlax-vbDouble '(0 . 2)))
    (vlax-safearray-fill vector (getvar "viewdir"))
    (setq vector (vlax-make-variant vector))
    (setq pt (vlax-3d-point pt))
    (if (= :vlax-true (vla-hittest table pt vector 'row 'col))
      (list row col)
    )
  ) ;end

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Table Question
« Reply #6 on: June 09, 2009, 10:46:08 AM »
Thanks for the subroutine.
My problem is the actual user pick of the SHX text cell. Seems that no method will work on SHX fonts.
The only recourse is to use GETPOINT and hunt for the table at that point?
Code: [Select]
(setq entity (nentselp "\n* Select Text in Table to Change *"))

(cond
 ((= 52 (getvar "errno"))
  (prompt "\n*** User Quit  ***\n")
 )
 ((and (null entity)
(eq 5 (car (setq pt (grread t 8 0)))) ; got a point
(setq entity (GoHuntForTable pt)))
« Last Edit: June 09, 2009, 12:40:48 PM by CAB »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Table Question
« Reply #7 on: June 09, 2009, 01:54:00 PM »
This seems to work for TT fonts.
Any better ideas?

Code: [Select]
;;  CAB 06.09.09
;;  This is a test routine for Changing the text within a Table

;;  Note that fields are not dealt with is this version
;;


(defun c:tu () (c:TableUpdate))
(defun c:TableUpdate (/          entity  txt_str tblent  e-type  n
                        ti      val     ent     elst    column  hitpt
                        hitres  row     vlaobj  tblRC
                        gettext HuntForTable    UpdateCell
                       )

  ;;  User selection of source text string
  (defun gettext (/ ent elst txt)
    (setvar "errno" 0)
    (while
      (cond
         ((null (setq ent (nentsel "\n* Select Source Text *")))
          (princ "\nMissed, try again.")
         )
         ((= 52 (getvar "errno"))
          (prompt "\n*** User Quit  ***\n")
          (setq txt nil)                     ; exit loop
         )
         ((and
            (setq elst (entget (car ent)))
            (= (type (setq txt (cdr (assoc 1 elst)))) 'STR)
          )
          (princ (strcat "\**  Got new source text: \"" txt "\""))
          nil                                ; exit loop
         )
         ((princ "\n*** No Text Found  ***\n")
          (setq txt nil)
          t
         )                                   ; stay in loop
      )
    )
    txt
  )


  ;;  See if point is within a table, if so
  ;;  return a list of Hits '((TableObject Row Column ) .....)
 
  (defun HuntForTable (pt / vCtr vSize vHs ll ur ss i ename TblList tblHit vDir vpt)
 
    ;;  get coordenates of screen   CAB 12/7/06
    (setq  vCtr  (getvar "VIEWCTR")     ; UCS
           vSize (/ (getvar "VIEWSIZE") 2.0) ; UCS
           vHs   (* vSize (apply '/ (getvar "screensize")))
    )
    (setq ll (list (- (car vCtr) vHs) (- (cadr vCtr) vSize)))
    (setq ur (list (+ (car vCtr) vHs) (+ (cadr vCtr) vSize)))
    ;;  get a selection set of TABLES in screen
    ;;  make a list of objects selected
    ;;  test the tables to see if the point is within them
    (if (setq ss (ssget "_C" ur ll '((0 . "ACAD_TABLE"))))
      (progn
        (setq i -1)
        (while (setq ename (ssname ss (setq i (1+ i))))
           (setq TblList (cons (vlax-ename->vla-object ename) TblList))
        )
        (setq pt   (trans pt 1 0)
              vpt  (vlax-3d-point pt)
              vDir (vlax-3d-point (getvar "viewdir"))
        )
        (mapcar
           (function
             (lambda (tbl / row col)
               (if  (= :vlax-true (vla-hittest tbl vpt vDir 'Row 'Col))
                 (setq TblHit (cons (list tbl Row Col) TblHit))
               )
             )
           )
           TblList
        )
      )
 
    )
    tblHit
  )

  ;; returns t if successful
  (defun UpdateCell (tbl r c txt)
    (if (vl-catch-all-error-p
           (vl-catch-all-apply
             'vla-SetText (list tbl R C txt)))
      (prompt "\n Can't paste. Object may be on locked layer. ")
      t
    )
  )



  ;;**********************************************************


  ;(if (setq txt_str (gettext))
  (if (setq txt_str "My Test") ; debug
    (while
      (progn
         (setvar "errno" 0)

         
         (initget "Change")
         (setq entity (nentsel "\n* Select Text in Table to Change *"))
       
         (cond
           ;;.......................................
           ((= 52 (getvar "errno")) ; Enter Key
            (prompt "\n*** User Quit  ***\n")
           )
           ;;.......................................
           ((and (null entity) ; ? missed pick, test for table
                  (eq 5 (car (setq pt (grread t 8 0)))) ; got a point
                  (setq TblRC (HuntForTable (cadr pt))) ; got a table
                  )
            ;; No suport for more than one table found at this time
            (setq TblRC (car TblRC)) ; debug
            (if (not (UpdateCell (car TblRC)(cadr TblRC)(caddr TblRC) Txt_Str))
              (prompt "\n*** Could Not Update Table  ***")
            )
            t
           )
           ;;.......................................
           ((null entity) (princ "\nMissed Pick, Try again."))
           
           ((= entity "Change")              ; allow user to select new source text
            (setq txt_str (gettext))
           )

           ;;.......................................
           ((and entity (listp entity)(> (length entity) 3))
                  (setq tblent (car (last entity))
                         e-type (cdr (assoc 0 (entget tblent)))
                  )
                (cond
                   ;;  BLOCK not included in test routine
                   ((= e-type "ACAD_TABLE") ; got a table with a pick point
                    (setq  vlaObj (vlax-ename->vla-object
                                     (cdr (assoc -1 (entget (car (last entity)))))
                                  )
                           hitPt  (vlax-3D-Point (trans (cadr entity) 1 0))
                           hitRes (vla-HitTest vlaObj hitPt
                                     (vlax-3d-point (getvar "viewdir")) 'Row 'Column)
                    )                        ; end setq
                    (if
                      (and
                        (= :vlax-true hitRes)
                        (= (vla-GetCellType vlaObj row column) acTextCell)
                      )
                       (UpdateCell vlaObj row column Txt_Str)
                       (princ "\n*** Could Not Update Table  ***")
                    )                        ; end if

                   )
                )
             t
           )
         )
      )
    )                                        ; end while
  )
  (princ)
)
(prompt "\nTable Test ")
(princ)
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.

Joe Burke

  • Guest
Re: Table Question
« Reply #8 on: June 10, 2009, 07:37:56 AM »
Using 2006 I can't get ENTSEL to pick the table by picking the SHX text!  :-o

Do you have to use GETPOINT and hunt for the TABLE?


Alan,

I haven't seen that problem in 2006. I just tested it in 2006. (car (entsel)) > pick SHX text in the right table returns <Entity name: 7ef7c1a8> which is the table ename.

Joe Burke

  • Guest
Re: Table Question
« Reply #9 on: June 10, 2009, 08:12:43 AM »
This seems to work for TT fonts.
Any better ideas?

Alan,

I've been talking to James Allen about the nentsel bug with TrueType mtext in a table. Recently he sent a solution similar to yours. Both work, though I've not yet tried to fold either one into my SwapText routine.

I have some misgivings about do so. The obvious one is it's a workaround for a bug Autodesk should fix. Another reason is the workaround breaks the basic SwapText interface which expects pick text for source and target objects. IOW, the workaround allows picking a table cell anywhere. Not specifically the mtext object contained in the cell.

One might argue that's a feature... but I would disagree.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Table Question
« Reply #10 on: June 10, 2009, 08:48:07 AM »
The attached DWG has a table with some cells using "Stylus BT"  which I tried again this morning
and can not select them using (setq ent (car (entsel)))

<edit>
Oops, I miss spoke about the SHX text, I can select that!
As you see my test rig does use the nentsel to get SHX font in cells and grread to hunt down the missed picks..
« Last Edit: June 10, 2009, 09:00:21 AM by CAB »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Table Question
« Reply #11 on: June 10, 2009, 08:59:21 AM »
The obvious one is it's a workaround for a bug Autodesk should fix. Another reason is the workaround breaks the basic SwapText interface which expects pick text for source and target objects. IOW, the workaround allows picking a table cell anywhere. Not specifically the mtext object contained in the cell.

One might argue that's a feature... but I would disagree.
I'm shocked that they haven't fixed that bug!
I would rather select the text but given the choices.....  8-)
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.

Joe Burke

  • Guest
Re: Table Question
« Reply #12 on: June 10, 2009, 09:43:17 AM »
Glad to hear oops. That one had me wondering...  :-)

I'm also shocked Autodesk is not aware of this bug, which apparently has been around since tables were introduced.