changing symbol styles and line styles for all objects in a table

142 views
Skip to first unread message

new user1234

unread,
Jun 28, 2021, 6:38:00 AM6/28/21
to MapInfo-L
Hi everyone,

Stuck with a small problem.

I'm trying to use some code I can copy and paste and drop into the MapBasic window in the MapInfo application.

I have a number of tables, some with symbols (points) some with lines (pens)

I'm trying to select all the objects and have the MapBasic window select all objects in the table and change the styles.

This is the code I'm using for tables with symbols

Select * from SYMBOLSTABLE
dim oSymbol as object
oSymbol  = selection.obj
Alter Object oSymbol Info 2, MakeSymbol(40, 16711680, 12)
Update selection set obj = oSymbol
undim oSymbol

This is the code I'm using for tables with lines

Select * from LINESTABLE
dim oLine as object
oLine  = selection.obj
Alter Object oLine  Info 2, MakePen(30, 2, 65535)
Update selection set obj = oLine
undim oLine

The problem seems to be that the code is making the objects in the table change style details however, it then moves the actual location of all the other objects so they are sitting on top of each other. I thought, at first, it had deleted them, but on looking at the table all the objects are still there, they have just moved location.

Is there anyway I can modify the codes above so that it's just the style that changes (color/line thickness etc) and the location of each line or symbol stays where I have originally placed it?

Many thanks for any help or advice

Gav

Uffe Kousgaard

unread,
Jun 28, 2021, 11:46:27 AM6/28/21
to mapi...@googlegroups.com
Hi,

In th 3rd line of your code, oSymbol contains the geometry and style of the first object in your table.

In the 5th line, you apply the new style and geometry to all objects.

In order to get it working, use a loop:

dim oSymbol as object
dim n as integer
Fetch first from SYMBOLSTABLE
n = 1
while not eot(SYMBOLSTABLE) do
  oSymbol  = SYMBOLSTABLE.obj

  Alter Object oSymbol Info 2, MakeSymbol(40, 16711680, 12)
  Update SYMBOLSTABLE set obj = oSymbol where rowid=n
  fetch next from SYMBOLSTABLE
  n = n+1
wend
undim oSymbol

It is crucial that your table is packed or n may go unsynchronized with the fetch next command.

And the usual disclaimer: Untested and keep a backup copy of your data.

Regards
Uffe Kousgaard
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapinfo-l/089f29b5-c88b-459d-bf6b-b709ddcd073dn%40googlegroups.com.

accumanddis trading

unread,
Jun 28, 2021, 11:53:23 AM6/28/21
to mapi...@googlegroups.com
appreciate your help Uffe, will give this a try.

Thanks

Gav

Peter Horsbøll Møller

unread,
Jun 29, 2021, 1:58:10 AM6/29/21
to mapi...@googlegroups.com
But Uffe’s solution will not work through the MapBasic window. This needs to run inside an application, a compiled mbx.

What version of MapInfo are you using?

Peter Horsbøll Møller
Peter Horsbøll Møller
Principal Sales Engineer - Distinguished Engineer

 


Den 28. jun. 2021 kl. 17.53 skrev accumanddis trading <justanaverageg...@gmail.com>:



This message originated Externally. Use proper judgement and caution with attachments, links, or responses.


new user1234

unread,
Jun 29, 2021, 3:52:24 AM6/29/21
to MapInfo-L
Hi peter, ok understood.  I'm using v17.0.3 64bit

Yes, I just tried to compile in MapBasic and it came up with errors, looks like it didn't recognise the wend part

Unrecognized command:wend
Command unavailable: undim
Missing '=' in assignment to oSynbol
Found [] while searching for [loop]

If it was done in an mbx application rather than the mapbasic window of mapinfo itself, would it be easy to wrap it in an a IF statement so it cycles through a list of tables and ignores the empty ones?

Thanks

Gav

Peter Horsbøll Møller

unread,
Jun 29, 2021, 4:23:10 AM6/29/21
to mapi...@googlegroups.com

Try this instead:

 

dim oSymbol as object
dim nRow, nTab as integer

dim arrTables() As String

 

'Creating a list of tables

nTab = nTab + 1

Redim arrTables(nTab)

arrTables(nTab) = "SYMBOLSTABLE"

nTab = nTab + 1

Redim arrTables(nTab)

arrTables(nTab) = "SYMBOLSTABLE2"

 

'Looping through the list of tables

For nTab = 1 To Ubound(arrTables)

 

   Select * From arrTables(nTab)

      Where OBJ

      Into __HAS__OBJECTS NoSelect

   Select * From __HAS__OBJECTS

      Where Str$(ObjectInfo(OBJ, 1)) = "5" 'OBJ_TYPE_POINT

      Into __HAS__POINTS NoSelect


   Fetch first from __HAS__POINTS
   Do Until EOT(__HAS__POINTS)
      oSymbol  = __HAS__POINTS.obj

      nRow = __HAS__POINTS.ROWID


      Alter Object oSymbol Info 2, MakeSymbol(40, 16711680, 12)

      Update __HAS__POINTS set obj = oSymbol where rowid = nRow
      fetch next from __HAS__POINTS
   Loop

 

   Close Table __HAS__POINTS

   Close Table __HAS__ OBJECTS

 

Next 'Table

 

This should create a list of tables using an array and then loop over these tables.

I have added a few checks (via Select statements) at first to make sure the records has objects and that the objects are points.

 

If you want the symbol to very across the tables, you can add another array to holds the symbols for each table and use these in the Alter Object statement:

 

dim arrTables() As String

dim arrSymbols() As Symbol

 

'Creating a list of tables

nTab = nTab + 1

Redim arrTables(nTab)

arrTables(nTab) = "SYMBOLSTABLE"

Redim arrSymbols(nTab)

arrSymbols(nTab) = MakeSymbol(40, 16711680, 12)

nTab = nTab + 1

Redim arrTables(nTab)

arrTables(nTab) = "SYMBOLSTABLE2"

Redim arrSymbols(nTab)

arrSymbols(nTab) = MakeSymbol(40, 16711680, 16)

      Alter Object oSymbol Info 2, arrSymbols(nTab)

 

Peter Horsbøll Møller

www.precisely.com

 

Peter Horsbøll Møller
Principal Sales Engineer - Distinguished Engineer

 

new user1234

unread,
Jun 29, 2021, 5:20:46 AM6/29/21
to MapInfo-L
ok thanks peter, cheers, really appreciate your help :)

thanks

new user1234

unread,
Jul 3, 2021, 7:48:54 AM7/3/21
to MapInfo-L
thanks for helping me out Peter, I have gotten round to experimenting with this this weekend.
I'm sorry but can I check I'm doing this right? When compiling the first batch of code it is creating two errors which seem to be directed towards the end section of the code

These are the errors:
(symbolstyle.mb:64) Found [next] while searching for [combine]
(symbolstyle.mb:64) Found [] while searching for [next]

looks like line 64 is the next statement at the end. I tried deleting it, but no joy.

I think I understand what you're saying about adding a symbol array to then have variable styles across tables. I can probably get that working if I can crack this first bit.

... and, just, one more question, to change all this to be tables containing lines (pens) rather than it being focused on symbols I'm thinking I just need to change things like MAKESYMBOL to MAKEPEN?
would line 38 need to change?

Where Str$(ObjectInfo(OBJ, 1)) = "5" 'OBJ_TYPE_POINT

I'm wondering if the 5 is telling it which default symbol to be looking for.

Many thanks for your help

Gav

Peter Horsbøll Møller

unread,
Jul 5, 2021, 5:01:08 AM7/5/21
to mapi...@googlegroups.com

Ah, sorry, it seems I had an extra space in the last table name:

   Close Table __HAS__ OBJECTS

Remove the space before OBJECTS and recompile and you are good.

 

Yeah, the Where command needs to be changed to work with linear objects in stead.

Here are a list of object types from MapBasic.def.

Define OBJ_TYPE_ARC                             1

Define OBJ_TYPE_ELLIPSE                         2

Define OBJ_TYPE_LINE                            3

Define OBJ_TYPE_PLINE                           4

Define OBJ_TYPE_POINT                           5

Define OBJ_TYPE_FRAME                           6

Define OBJ_TYPE_REGION                          7

Define OBJ_TYPE_RECT                            8

Define OBJ_TYPE_ROUNDRECT                       9

Define OBJ_TYPE_TEXT                            10

Define OBJ_TYPE_MPOINT                          11

Define OBJ_TYPE_COLLECTION                      12

 

So for linear objects, change the Where command to:

Where Str$(ObjectInfo(OBJ, 1)) In ("1", "3", "4") 'OBJ_TYPE_ARC, OBJ_TYPE_LINE, OBJ_TYPE_PLINE

 

HTH

accumanddis trading

unread,
Jul 5, 2021, 5:42:29 AM7/5/21
to mapi...@googlegroups.com
great thanks so much Peter. appreciate your help and time in explaining. I will have a play around with this today.

gav

Reply all
Reply to author
Forward
0 new messages