Author Topic: Pick point - Get table cell  (Read 4160 times)

0 Members and 1 Guest are viewing this topic.

Guest

  • Guest
Pick point - Get table cell
« on: January 17, 2007, 08:55:10 AM »
Is there a way to determine what cell (I.E. row/col) has been selected via a pick point (not selecting a cell border).

I want to be able to issue a prompt to pick a point within a table and from that point, determine what cell the pick-point was in.  From there, I'm going to insert a block or format the cell.

Matersammichman

  • Guest
Re: Pick point - Get table cell
« Reply #1 on: January 17, 2007, 09:56:37 AM »
Wow, Deja-Vu.
That's exactly what I was about to post a thread asking for.

Fatty

  • Guest
Re: Pick point - Get table cell
« Reply #2 on: January 17, 2007, 10:43:21 AM »
Hi Matt
Take a look at HitTest function

Hth

~'J'~

Fatty

  • Guest
Re: Pick point - Get table cell
« Reply #3 on: January 17, 2007, 10:48:17 AM »
You can see this nice one written on lisp,
search for 'selTableCell' by Lee Ambrosius dated 3/24/04
source code available at:
http://hyperpics.blogs.com/beyond_the_ui/autolispvisual_lisp/

~'J'~

Fatty

  • Guest
Re: Pick point - Get table cell
« Reply #4 on: January 17, 2007, 11:18:24 AM »
Give this a try, seems to be working for me

Code: [Select]
Option Explicit

Function GetTableCell(ByVal oTable As AcadTable, ByVal varPt As Variant, _
                      ByRef rowIndex As Long, ByRef colIndex As Long) As Variant
     Dim wviewVec As Variant
     Dim resVar(1) As Long
     wviewVec = ThisDrawing.GetVariable("VIEWDIR")
     oTable.HitTest varPt, wviewVec, rowIndex, colIndex

    resVar(0) = rowIndex
    resVar(1) = colIndex
    GetTableCell = resVar
   
End Function
Sub test()

    Dim ar As Variant, _
    e As AcadEntity, _
    t As AcadTable, _
    p As Variant, _
    ip As Variant, _
    r As Long, _
    c As Long
   
    With ThisDrawing.Utility
    .GetEntity e, ip, "Select table"
    p = .GetPoint(, "Pick point in cell")
    End With
    Set t = e
    ar = GetTableCell(t, p, r, c)

      r = ar(0)
      c = ar(1)
     
           MsgBox "Row " & r & ", Column " & c & vbCr & _
            "Value: " & t.GetText(r, c)
End Sub

~'J'~

Guest

  • Guest
Re: Pick point - Get table cell
« Reply #5 on: January 17, 2007, 11:21:45 AM »
I was going to post this (which doesn't work - yet).  I'm trying to avoid selecting the table then selecting a cell if it's possible - it must be, because Lee's code doesn't make you select the table.  I'm a little stumped right now - trying to write this AND do actual billable work at the same time....what was I thinking??!?

Code: [Select]
Public Sub SelectCell()
    Dim objTable As AcadTable
    Dim varPnt As Variant
    Dim varCoords As Variant
    Dim lngRow As Long, lngCol As Long
   
    varPnt = ThisDrawing.Utility.GetPoint(, "Select a cell to edit...")
   
    If objTable.HitTest(varPnt, varCoords, lngRow, lngCol) Then
        MsgBox "Found a cell"
    End If
End Sub

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: Pick point - Get table cell
« Reply #6 on: January 17, 2007, 11:37:35 AM »
Wow, Deja-Vu.
That's exactly what I was about to post a thread asking for.

How do you get Deja-Vu when it only happens once?

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Pick point - Get table cell
« Reply #7 on: January 17, 2007, 11:49:41 AM »
Lee uses a selection window of the current display to see if any tables are in the view, then cycles through any found tables looking to see if the HitTest is successful.....

Guest

  • Guest
Re: Pick point - Get table cell
« Reply #8 on: January 17, 2007, 11:55:14 AM »
So is that the road I have to follow, or is it possible to get the table object from the pick point, and then from there, get the cell's position?

Matersammichman

  • Guest
Re: Pick point - Get table cell
« Reply #9 on: January 17, 2007, 12:24:45 PM »
Greg B,
(From Dictionary.com)
Deja Vu- An impression of having seen or experienced something before.

His question looked familiar because it was what I had thought of too.

Other than that, I don't feel like arguing today.  :|

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Pick point - Get table cell
« Reply #10 on: January 17, 2007, 12:59:10 PM »
Well, Matt, I guess you could try getting a crossing selection set within a certain distance of the pick point.....

Or, if you don't have a lot of tables anyway this may be faster, just cycle through your tables collection and see if you get a hit on HitTest.....

I haven't messed with tables much, yet, to be able to give much better responses.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Pick point - Get table cell
« Reply #11 on: January 18, 2007, 12:15:53 AM »
I think this does what you want
I like the way you feed it p1 as both corners of the selection set and it works.

Code: [Select]
Sub WhatCell()

    Dim oTable As AcadTable
    Dim P1
    Dim V(2) As Double
    Dim R As Long, C As Long
    V(2) = 1
    Set oTable = EntSel(, P1) 'Getentity function
    oTable.SelectSubRegion P1, P1, V, V, 1 _
        , True, R, R, C, C
   
    Debug.Print R, C
    Debug.Print oTable.GetText(R, C)

End Sub

Guest

  • Guest
Re: Pick point - Get table cell
« Reply #12 on: January 18, 2007, 09:15:31 AM »
Can you post the EntSel function?  It's M.I.A.

Quote
Set oTable = EntSel(, P1) 'Getentity function

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Pick point - Get table cell
« Reply #13 on: January 18, 2007, 09:37:59 AM »
It's in the vba functions  Matt.(They seem to have disappeared.)
Code: [Select]

Public Const VK_ESCAPE = &H1B
Public Const VK_LBUTTON = &H1
Public Const VK_SPACE = &H20
Public Const VK_RETURN = &HD
Public Const VK_LEFT = &H25
Public Const VK_MBUTTON = &H4


Public Declare Function GetAsyncKeyState Lib "user32" _
        (ByVal vKey As Long) As Integer


'Randall single selection
Public Function EntSel(Optional strPrmt As String = "Select an entity: ", Optional vPoint As Variant) As AcadEntity
    Dim objTemp As AcadEntity
    Dim objUtil As AcadUtility
    Dim varPnt As Variant
    Dim varCancel As Variant
    On Error GoTo Err_Control
    Set objUtil = ThisDrawing.Utility
    objUtil.GetEntity objTemp, varPnt, vbCr & strPrmt
    Set EntSel = objTemp
    If Not IsMissing(vPoint) Then
        vPoint = ToWcs(varPnt) ',,,,,,,,Added
    End If
Exit_Here:
    Exit Function
Err_Control:
    Select Case Err.Number
        Case -2147352567
        'Debug.Print Err.Number, Err.Description
        varCancel = ThisDrawing.GetVariable("LASTPROMPT")
        If InStr(1, varCancel, "*Cancel*") <> 0 Then
            If GetAsyncKeyState(VK_ESCAPE) And 8000 > 0 Then
                Err.Clear
                Resume Exit_Here
            ElseIf GetAsyncKeyState(VK_LBUTTON) > 0 Then
                Err.Clear
                Resume
            End If
        Else
            If GetAsyncKeyState(VK_SPACE) Then
                Resume Exit_Here
            End If
            'Missed the pick, send them back!
            Err.Clear
            Resume
        End If
        Case Else
            MsgBox Err.Description
            Resume Exit_Here
    End Select
End Function


Guest

  • Guest
Re: Pick point - Get table cell
« Reply #14 on: January 18, 2007, 09:45:23 AM »
One more...

Quote
vPoint = ToWcs(varPnt)

Guest

  • Guest
Re: Pick point - Get table cell
« Reply #15 on: January 18, 2007, 09:47:57 AM »
Nevermind... I found it on the ACAD NG.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Pick point - Get table cell
« Reply #16 on: January 18, 2007, 11:03:54 AM »
Sorry I'll make this real simple
Sub WhatCell()

    Dim oTable As AcadTable
    Dim P1
    Dim V(2) As Double
    Dim R As Long, C As Long
    V(2) = 1
    ThisDrawing.Utility.GetEntity oTable, P1, "Pick"
    oTable.SelectSubRegion P1, P1, V, V, 1 _
        , True, R, R, C, C
    Debug.Print R, C
    Debug.Print oTable.GetText(R, C)

End Sub

Guest

  • Guest
Re: Pick point - Get table cell
« Reply #17 on: January 18, 2007, 11:49:05 AM »
I got it figured out.  The code is over here.

Thanks for the help/ideas.