Hi Tanner
The style is stored on the object itself, or at least that's the way you get to the style and change the style; changing the object.
This means that you will have to loop over the records that you want to change, read the object into an Object variable, update the style using Alter Object, and finally write the changed object back to the record you just read it from.
The MapBasic equivalent of this looks like this:
Dim nRowID As Integer
Dim oSel As Object
Fetch First From Selection
Do Until EOT("Selection")
nRowID = Selection.ROWID
oSel = Selection.OBJ
Alter Object oSel Info 2, MakePen(1, 2, value) '2 = OBJ_INFO_PEN
Update Selection Set OBJ = oSel Where ROWID = nRowID
Fetch Next From Selection
Loop
Let me know if you have issues converting this into a MapBasic/Python mix.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------
Original Message:
Sent: 05-22-2025 12:42
From: Tanner Mork
Subject: Changing Color of a Selection
I am writing a script using python that takes unique values from a table and goes through selecting lines and assigning your chosen color to each value. I do realize that this is essentially what themes are for but I am trying to avoid those for this. I was wondering if someone could help me with the part I am struggling with, assigning a color or pen style to a selection at the end of my pasted code where I have "make it this color"?
Thanks!
import osfrom osgeo import ogrfrom mi_common_util import CommonUtilfrom System.Collections.Generic import Listfrom System import *from MapInfo.Types.Data import *from MapInfo.Types import MapInfoDictionaryfrom MapInfo.Types import *colorList = [16711680, 16776960, 65280, 65535, 255, 16711935, 8388608, 8388736, 8421504]tableCount = (pro.Catalog.Tables.Count)print ("Pick a number from the opions below")for x in range(tableCount): print ("Table " + str(x) + ": " + pro.Catalog.Tables[x].Alias)i = input("type the number for the desired table")uniqueRows = []rowTotal = (pro.Catalog.Tables[int(i)].RowCount())for y in range(rowTotal): CommonUtil.do("Fetch Rec " + str(y) + " From UNIQUE_values") sValue=eval("UNIQUE_values.Level") uniqueRows.append(sValue)print (uniqueRows)variables = List[MapInfoDictionary[String, Object]]()newVariables = []c=0for g in range(rowTotal): c += 1 if g < 9: vColor = MapInfoDictionary[String, Object]() vColor['Name'] = ("Color" + str(c)) vColor['Type'] = ("Color" + str(c)) vColor['Prompt'] = ("_Color" + str(c) + ":") vColor['Value'] = colorList[g] variables.Add(vColor) else: vColor = MapInfoDictionary[String, Object]() vColor['Name'] = ("Color" + str(c)) vColor['Type'] = ("Color" + str(c)) vColor['Prompt'] = ("_Color" + str(c) + ":") vColor['Value'] = 255 # blue variables.Add(vColor)if pro.Input('Input Style', variables, None): for v in variables: new_List = ('{}'.format(v['Value'])) newVariables.append (new_List)print (newVariables)my_dict = dict(zip(uniqueRows, newVariables))print(my_dict)for key, value in my_dict.items(): CommonUtil.do(f"select Alberta.Level from Alberta where ALberta.Level = {key}") #print (f"make it this color {value}") #CommonUtil.do(f" Update Selection Set Style Pen (1,2,{value})")
------------------------------
Tanner Mork
Knowledge Community Shared Account
Burlington MA
------------------------------