1

I want to get attributes from object what was selected on map. I understand how to get selected object:

Dim nrecords as Ineger
Dim obj as Object
nRecords = SelectionInfo(SEL_INFO_NROWS)
For i = 1 To nRecords
   Fetch rec i From selection
   obj = selection.obj  

Now i want to get any attributes from this object. How can i do this?

3

You can do it by looping over the columns in the table and writing the values to two arrays: One for the column name and one for the value.

Dim sQuery, arrColNames(), arrColValues() As String
Dim nCount, nNumCols, nCol As Integer
Dim aCol As Alias
Dim oSel As Object

'**Getting the name of the query (instead of Selection)
sQuery = SelectionInfo(SEL_INFO_SELNAME)

'**Get the number of columns and making space for these in the arrays
nNumCols = TableInfo(sQuery, TAB_INFO_NCOLS)
ReDim arrColNames(nNumCols)
ReDim arrColValues(nNumCols)

Fetch First From sQuery
Do Until EOT(sQuery)
   aCol = sQuery & ".OBJ"
   oSel = aCol

   '**Looping thru the columns
   For nCol = 1 To nNumCols
      arrColNames(nCol) = ColumnInfo(sQuery, "COL" & nCol, COL_INFO_NAME)
      aCol = sQuery & ".COL" & nCol
      arrColValues(nCol) = aCol
   Next

   '**Here you will do some stuff with the object and the column values
   '...

   Fetch Next From sQuery
Loop

Note that I'm using a Do Until loop as that's better for dealing with deleted records in a table.

  • Sory taht do not accepting answer for a long time. Solution works nice. But i was pretty suprised that for getting objects's attributes i gonna iterate through whole table. – Kliver Max Oct 5 '16 at 9:16
  • You aren't looping thru the entire table, only thru the selected records. If you know there will only be one selected record, you can remove the outer loop: Do Until EOT() ... Loop and only keep the inner loop on the columns – Peter Horsbøll Møller Oct 9 '16 at 11:54
0

If you nedd to special attribute you can access by Selection.NameOfAttribute

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 1
    Could you elaborate, please? – mgri Jul 25 '17 at 12:36
  • For example if you have attribute "Name" in you layer you can get value from selected object by Selection.Name – Андрей Тарасов Jul 26 '17 at 14:58
  • Thanks, please add this comment as an edit in your answer. – mgri Jul 26 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.