Change Object Style using MapBasic

446 views
Skip to first unread message

PaulD

unread,
May 8, 2014, 5:04:34 AM5/8/14
to mapi...@googlegroups.com

Hi All,

 

I'm fairly new to MapBasic and I’m trying to develop a tool which will re-style selected objects in a table, but I’m having a bit of trouble - I’ve managed to get the tool doing everything except for change the style! I've got the tool to select the objects from the appropriate table I want, set the table editable, I just can't get over the final hurdle of actually re-styling the selection.

 

Say, for example, I wanted to select all line objects in a table and change their style to line thickness 2, coloured blue – how do I do it?

 

I thought it would just be a simple case of getting the tool to select all objects and use the set penstyle expression, but that doesn’t work – so I’m guessing it must be a little more complicated?
 

Thanks,

Paul

Thomas Bacon

unread,
May 8, 2014, 5:17:03 AM5/8/14
to mapi...@googlegroups.com

Hi Paul,

 

Best option here is to use a function to update your selection. Code below has not been tested but should give you an idea of how to do this.

 

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

Include "MapBasic.def"

 

Declare Sub Main

Declare Function UpdateLineStyle(ByVal oTarget as Object, ByVal newPen as Pen) as Object

 

Sub Main

      

 Dim pNew as Pen

      

       '...

      

       pNew = MakePen(2, 2, BLUE) '// make your new pen style

      

       Select * from YourTable where StyleChange = "true" into ToUpdate     '// select the records you want to update

      

       Update ToUpdate set obj = UpdateLineStyle(obj, pNew)          '// using an update statement call the style update function which returns the updated object

      

       '...

      

End Sub

 

'// Update the passed object with the new style and then return the updated object

Function UpdateLineStyle(ByVal oTarget as Object, ByVal newPen as Pen) as Object

      

       Alter Object oTarget Info OBJ_INFO_PEN, newPen

      

       UpdateLineStyle = oTarget

      

End Function

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

 

Regards,

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

--
--
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.
For more options, visit https://groups.google.com/d/optout.



 

Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX.  The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. 

PaulD

unread,
May 8, 2014, 6:15:04 AM5/8/14
to mapi...@googlegroups.com
That's great - just tested and is exactly what I was looking for, thanks!
 
Reply all
Reply to author
Forward
0 new messages