Change region style.

60 views
Skip to first unread message

Matthew Hirsch

unread,
Apr 30, 2024, 2:29:19 PMApr 30
to MapInfo-L
I am looking for code to add into a map basic script to change a region table's style to no fill, no border.   

The table is called MAPE.    (It is a territory boundary file we use in code to select a particular territory, add the selection boundary to the map, then view entire layer of the selection.)

Right now, we are running one script to create the mape table, then manually changing the style and saving then finishing off the script that uses the mape boundaries.

Within a larger script, if possible I'd like to: 

Open Table "M:\mape.TAB" Interactive
Map From mape

----Script for changing region to no line, no fill.

Commit Table Mape Interactive
Close all

I've looked around and there have been some other discussions about this, but none seemed to focus on just this one thing.

Thank you.

Peter Horsbøll Møller

unread,
May 1, 2024, 2:51:52 AMMay 1
to mapi...@googlegroups.com
Hi Matthew
Check out the function STLAlterClosedObject in the STYLELib module from the Common MapBasic Libraries.

You pass the object, a brush style and a pen style to the function and the function will return the object with these styles applied.

Typical use case:

penNew = MakePen(…)
brsNew = MakeBrush(…)
Update MAPE
 Set OBJ = STLAlterClosedObject(OBJ, penNew, brsNew)

Make sure to dim the two style variable and insert the right style values in the Make… functions

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

 


Den 30. apr. 2024 kl. 20.29 skrev Matthew Hirsch <mrhr...@gmail.com>:



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


--
--
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/2f16bc7b-59a4-4779-b686-8a56238c92cfn%40googlegroups.com.

Matthew Hirsch

unread,
May 1, 2024, 11:41:15 AMMay 1
to MapInfo-L
So, would this be the whole code?   I am trying to keep it as simple as possible.     

Include "MAPBASIC.DEF"

Declare Sub Main

Dim penNew As Brush,
Dim brsNew As Pen

Sub main

Open Table "C:\temp\mape.TAB" Interactive
Map From mape
penNew = MakePen(1, 0, 16777215)
brsNew = MakeBrush(1, 2, 16776960)

Update MAPE
Set OBJ = STLAlterClosedObject(OBJ, penNew, brsNew)
Commit Table mape

End Sub


Peter Horsbøll Møller

unread,
May 2, 2024, 4:45:54 AMMay 2
to mapi...@googlegroups.com

Not quite.

If you aren’t using a MapBasic project, it will be easist to copy and paste these additional functions into your code:

I have modified these a bit compared to how they look in the MapBasic module I was referring to.

I have changed the error handling to be more simple to avoid including more modules/functions.

 

'**********************************************************************************************''

Function STLAlterClosedObject(     ByVal oObj As Object          'Closed object whoes style to change

                                , ByVal penNew As Pen      'New Pen style to assign

                                , ByVal brsNew As Brush          'New Brush style to assign

                                ) As Object

 

OnError GoTo ErrorOccured

 

STLAlterClosedObject = oObj

 

     oObj = STLAlterPen(oObj, penNew)

     oObj = STLAlterBrush(oObj, brsNew)

 

STLAlterClosedObject = oObj

 

     Exit Function

'-------------------------

ErrorOccured:

     Print Err() & “ “ & Error$() & " STLAlterClosedObject"

 

End Function

 

'**********************************************************************************************''

Function STLAlterPen(  ByVal oObj As Object     'Object whoes style to change

                     , ByVal penNew As Pen      'New Pen style to assign

                     ) As Object

 

OnError GoTo ErrorOccured

 

STLAlterPen = oObj

 

     If STLObjectHasPen(oObj) Then

           Alter Object oObj

                Info OBJ_INFO_PEN, penNew

           STLAlterPen = oObj

     End If

     Exit Function

'-------------------------

ErrorOccured:

     Print Err() & " " & Error$() & " STLAlterPen"

 

End Function

 

'**********************************************************************************************''

Function STLAlterBrush(      ByVal oObj As Object          'Object whoes style to change

                           , ByVal brsNew As Brush          'New Brush style to assign

                           ) As Object

 

OnError GoTo ErrorOccured

 

STLAlterBrush = oObj

 

     If STLObjectHasBrush(oObj) Then

           Alter Object oObj

                Info OBJ_INFO_BRUSH, brsNew

           STLAlterBrush = oObj

     End If

 

     Exit Function

'-------------------------

ErrorOccured:

     Print Err() & “ “ & Error$() & " STLAlterBrush"

 

End Function

 

'**********************************************************************************************''

Function STLObjectHasPen(ByVal oObj As Object) As Logical

 

OnError GoTo ErrorOccured

 

STLObjectHasPen = FALSE

 

     Do Case ObjectInfo(oObj, OBJ_INFO_TYPE)

           Case OBJ_TYPE_ARC, OBJ_TYPE_LINE, OBJ_TYPE_PLINE

                STLObjectHasPen = TRUE

'          Case OBJ_TYPE_TEXT

'          Case OBJ_TYPE_POINT, OBJ_TYPE_MPOINT

           Case OBJ_TYPE_REGION, OBJ_TYPE_RECT, OBJ_TYPE_ROUNDRECT, OBJ_TYPE_ELLIPSE

                STLObjectHasPen = TRUE

           Case OBJ_TYPE_COLLECTION

                STLObjectHasPen = TRUE

           Case OBJ_TYPE_FRAME

                STLObjectHasPen = TRUE

     End Case

 

     Exit Function

'-------------------------

ErrorOccured:

     Print Err() & " " & Error$() & " STLObjectHasPen"

 

End Function

 

'**********************************************************************************************''

Function STLObjectHasBrush(ByVal oObj As Object) As Logical

 

OnError GoTo ErrorOccured

 

STLObjectHasBrush = FALSE

 

     Do Case ObjectInfo(oObj, OBJ_INFO_TYPE)

'          Case OBJ_TYPE_ARC, OBJ_TYPE_LINE, OBJ_TYPE_PLINE

'          Case OBJ_TYPE_TEXT

'          Case OBJ_TYPE_POINT, OBJ_TYPE_MPOINT

           Case OBJ_TYPE_REGION, OBJ_TYPE_RECT, OBJ_TYPE_ROUNDRECT, OBJ_TYPE_ELLIPSE

                STLObjectHasBrush = TRUE

           Case OBJ_TYPE_COLLECTION

                STLObjectHasBrush = TRUE

           Case OBJ_TYPE_FRAME

                STLObjectHasBrush = TRUE

     End Case

 

     Exit Function

'-------------------------

ErrorOccured:

     Print Err() & " " & Error$() & " STLObjectHasBrush"

 

End Function

 

And you need to declare these functions at the top of your code similar to declaring your Sub Main:

Declare Function STLAlterClosedObject(   ByVal oObj As Object     'Closed object whoes style to change

                                     , ByVal penNew As Pen 'New Pen style to assign

                                     , ByVal brsNew As Brush    'New Brush style to assign

                                     ) As Object                'Return the same object with a different style

Declare Function STLAlterPen(      ByVal oObj As Object     'Object whoes style to change

                                , ByVal penNew As Pen 'New Pen style to assign

                                ) As Object                'Return the same object with a different style

Declare Function STLAlterBrush(    ByVal oObj As Object     'Object whoes style to change

                                , ByVal brsNew As Brush    'New Brush style to assign

                                ) As Object                'Return the same object with a different style

Declare Function STLObjectHasPen(  ByVal oObj As Object     'Object to check for style

                                ) As Logical               'Returns true if oObj has a Pen style

Declare Function STLObjectHasBrush(  ByVal oObj As Object   'Object to check for style

                                ) As Logical               'Returns true if oObj has a Brush style

 

You need all 5 functions, as they are used by “each other”.

The first function call the second two, and they each call one of the last two functions.

 

I hope these makes sense

Peter

 

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

 

Matthew Hirsch

unread,
May 2, 2024, 12:02:07 PMMay 2
to MapInfo-L
I am creating this in MapBasic 2019.    I am not sure if that is different than your mention of a MapBasic project.

Without repasting in a ton of code, using what you put, will my code above work if I drop it into yours, or do I need to rewrite it to call all the functions.

Again, I just want the MBX to open a table, change the table to no line and no fill and save then close the table.   
Once I get just that simple MBX working, I may try to drop the code into a larger MBX at a later date, but that is lower priority.

I do appreciate your help on this.    
Looking back it seems many people have looked for code to do just this, so having some kind of clean, but fully written MB that opens a table like States changes and saves it, to reference, would be really helpful. 

Matthew

Peter Horsbøll Møller

unread,
May 3, 2024, 3:51:26 AMMay 3
to mapi...@googlegroups.com

Hi Matthew

 

I put it all into a MapBasic module. I think that makes it easier for all of us 😊

 

I compiled it and ran it with a table of mine.

And it works. My buffers “disappeared” as their style now got invisible.

 

All you need to do is change the path and file name in line 27.

And potentially change the pen and brush style if required.

 

Cheers

UpdateStyle.mb
Reply all
Reply to author
Forward
0 new messages