MapInfo Pro Developers User Group

 View Only
  • 1.  MakePen() equivalent in Python

    Posted 07-15-2021 21:40

    trawling through all the python samples and knowledge communities I cannot seem to find an example of updating object styles.

    I have a SQL selection that I want to then update the object style.

    Suggestions or examples appreciated

    Stephen Perger
    Buloke Shire Council
    Wycheproof VIC

  • 2.  RE: MakePen() equivalent in Python

    Posted 07-16-2021 14:50
    Hi Stephen,

    As not all pro functionality is covered in python yet, somethings you need to resort to mapbasic to get things done.
    You can use do() or eval() to execute mapbasic statements.

    If you need more details let me know.


    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team

  • 3.  RE: MakePen() equivalent in Python

    Posted 07-18-2021 20:58
    Hi Bob,

    Can you suggest how to achieve the below mapbasic example using a DO in python.  How are you able to reference the Selection.

    '// Select all records with a map object

    Select * from mybigtable where obj into ToUpdate


    '// Update your selection table

    Update ToUpdate Set obj = UpdatePenStyle(obj, newPen)



    '// Update the pen style of an object


    Function UpdatePenStyle(ByVal updObject as Object, ByVal newPen as Pen) as Object


           Alter Object updObject Info OBJ_INFO_PEN, newPen

           UpdatePenStyle = updObject


    End Function

    I currently use the below to select data, how do I reference the resulting selection to update the pen style.

    do("select * from Grader_Jobs_To_Current where gang_code = \"" + gangCode + "\" AND disp_year = \"" + str(dispYear) + "\" into " + selectName + " noselect".format(table.Alias))


    Stephen Perger
    Buloke Shire Council
    Wycheproof VIC

  • 4.  RE: MakePen() equivalent in Python

    Posted 07-22-2021 02:59
    Hi Stephen,

    You cannot assign a python expression to a MB command, achieving the same thing can be used using MB command only in python.
    See code below.

    do("select * from states where obj into ToUpdate NoSelect")
    do("dim newPen as Pen")
    do("newPen = MakePen(3,9,RED)")
    ToUpdateTable = pro.Catalog.Tables['ToUpdate']
    numSelectionRows = ToUpdateTable.RowCount() + 1
    for row in range(1, numSelectionRows):
        do("fetch rec {} From {}".format(row, ToUpdateTable.Alias))
        do("dim updObj as Object")
        do("updObj = {}.obj".format(ToUpdateTable.Alias))
        do("Alter Object updObj Info 2, newPen".format(ToUpdateTable.Alias))
        do("Update {} Set obj = updObj where rowid = {}".format(ToUpdateTable.Alias, row))


    Anshul Goel
    Knowledge Community Shared Account
    Shelton CT