TBC Macros and Extensions

 View Only
Expand all | Collapse all

Adding User Attributes to a Tree point using TML

  • 1.  Adding User Attributes to a Tree point using TML

    Posted 23 days ago
    I need to add or update the attributes of trees in my project

    The trees are not captured with an instrument but manually using Station and Offset

    The tree attributes - Point Number, Species, Spread, Girth are in a csv file

    The code should be simple but not being very experienced with TML I getting no where.

    Cheers
    Alan





  • 2.  RE: Adding User Attributes to a Tree point using TML

    Posted 22 days ago

    Hi Alan,

    In this post reply, Ronny has links to a ton of PY macro files.  I would look in there to see if the old sample TMLs or Ronny himself have done something like this already.

    Otherwise, hopefully @Bryce Haire on the dev team can help - since he has access to the source code and can look up how things are done in TBC itself.

    My dev experience was on the HCE (Heavy Civil) side, so I'm not as familiar with how Features, Attributes, and the Feature Library work in TBC - though my curiosity is piqued each time someone brings up feature attributes...



    ------------------------------
    Quan Mueller
    Revenant Solutions | TBC Extension Developer
    Superuser Program | superuser@revenantsolutions.com
    ------------------------------



  • 3.  RE: Adding User Attributes to a Tree point using TML

    Posted 21 days ago
    Edited by Ronny Schneider 21 days ago

    Hello Alan,

    I don't have a macro that does this. This is a rather unusual use case, use point numbers from a project to lookup data in a CSV file and apply the data you find there as attribute values in the project.

    My first thought was to export your points as XYZ-CSV, compile a new file with Excels "VLOOKUP", save as CSV and import into TBC.

    But, TBC doesn't have an import of CSV data with feature code and attributes. It can't even import the CSV with FC and Attributes it exported itself. Another one of those inexplicably missing features where you wonder why you pay maintenance fees year after year.

    Can you send me the CSV and TBC files. Preferably the table with point numbers, station, elevation as well. I need to see how everything is structured, if and how your feature library is set up and how many trees we're talking about. r.schneider.eu@gmail.com

    Potentially I can tweak my existing SCR_ImportStaOffEl to create points with FC and Attributes.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 4.  RE: Adding User Attributes to a Tree point using TML

    Posted 19 days ago

    Hi Ronny,

    When I mentioned your macros, I meant for Alan to look through them for sample code on how to assign values to the attributes of point features attached to point objects in TBC.

    From Alan's post, it sounded like he wanted to write the macro himself, and was looking for instructions or sample code on how to assign feature attribute values.

    More power to you if you want to investigate how to do that yourself - or enhance your own macros - but that's why I tagged @Bryce Haire - he can just look at how TBC sets attribute values (for example via the Properties command) and hopefully provide a few lines of code.

    Side note: it sounds like Alan wants a CSV import that adds or updates attribute values in the project - is that an unusual workflow?  To update existing point/feature data?



    ------------------------------
    Quan Mueller
    Revenant Solutions | TBC Extension Developer
    Superuser Program | superuser@revenantsolutions.com
    ------------------------------



  • 5.  RE: Adding User Attributes to a Tree point using TML

    Posted 19 days ago
    Edited by Ronny Schneider 19 days ago

    Hello Quan,

    having just points in TBC and bulk adding FC's from a CSV is relative unusual. Standard workflow is field work in Access with feature coding in the field and double checking and minor error fixing in the office.

    And since TBC is unable to import FC's plus attributes from a CSV file in general, it never was an option anyway. I might actually write one, the biggest issue is the multitude of possible formats of the FC and attribute values.

    With a lot of trial and fail, due to Trimble's unwillingness to provide decent documentation, I figured out the following a while ago. Is partly shown in some of my macros.

    the FC's with attributes need to be setup/created in TBC beforehand, i.e. via Feature Definition Editor

    It all depends on how the FC's are structured in the CSV file.

    the following code assumes a CSV-FC string as you'd get when exporting points from TBC (at least exporting is possible)

    multiple FC's and attributes; concatenated with "|" into one column and format "FC:Attribute:Value"

    not shown as code below is reading the CSV, looping through and processing it line by line, extract FC string from line (basically a csvline.split(",") and sending the correct element/column to the below code)

    I'd suggest creating a dictionary from the FC string. Potentially you can create one large dictionary for the whole CSV file that includes the point number as well.

        def fcstringtodic(self, fcstring):
    
            fcdic = {}
    
            for fc in fcstring.split("|"):
    
                att = fc.split(":")
                if att.Count == 3: # only try to add to dict if we have a "FC:Attribute:Value" combination
    
                    if not att[0] in fcdic.keys(): # if the FC doesn't exist in the dict yet add it
                        fcdic.update({att[0] : {}})
                    fcdic[att[0]].update({att[1] : att[2]}) # add attribute and value to FC key
    
            return fcdic

    you'll have to find the corresponding point, to this specific CSV line, in the TBC database

    afterwards you can apply the FC to the point in question and apply the attribute values; the dictionary fcdic in this example always just contains the data for one specific point/line from the CSV

                fcdic = self.fcstringtodic(fcstring)
    
                # PointManager doesn't seem to have a fixed serial number; need to find it manually
                # seems to be 1040 - but in the SDK it's not explicitly shown as always being this number
                for o2 in self.currentProject:
                #find PointManager as object
                    if isinstance(o2, PointManager):
                        pm = o2
    
                                            # assuming we have found the "namedPoint" in the TBC data base that we want to apply the current FC from the CSV
    
                                            for setfc in fcdic: # go through all the keys/FC's of the dictionary; setfc is the feature code abbreviation
                                                pm.SetFeatureCodeAtPoint(namedPoint.SerialNumber, setfc) # set the FC
                                                features = pm.AssociatedRDFeatures(namedPoint.SerialNumber) # retrieve the list of attributes we can try to fill
                                                # try to fill the feature attributes from the dictionary
                                                for f in features:
                                                    for attr in f.Definition.AttributeDefinitions:
                                                        # lookup values from dictionary - try to find it, that is - no result returns an empty string ""
                                                        attrval = fcdic.get(f.Code, {}).get(attr.Name, "")
                                                        # set attribute value - weirdly we have to use Add to overwrite it - is not properly documented in the SDK
                                                        f.Add(attr.Type, attr.Name, attrval)
    
    



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 6.  RE: Adding User Attributes to a Tree point using TML

    Posted 19 days ago
    Hi Ronny, Quan

    The import macro was not too complicated so importing points from a station & offset survey via a csv file with the point feature code,  point feature attributes was achieved.  The points can then be processed as a Keyed In block using the "Process Feature Codes" command.

    I wanted to
    1. Plot new points with their feature attributes or
    2. Update existing points with updated feature attributes.

    The idea for the feature update macro was based on the idea that the fieldwork would be done without advanced survey equipment
    i.e. No Trimble Access, where for example the tree attributes were recorded in order to create new or update existing records

    A tree is a good example as the position for existing would not change. So why drag equipment around if a tape will suffice.

    While it does have an actual practical use it is also a lesson for me to understand the link between the point and the feature library

    Thanks for the help, much appreciated

    Cheers
    Alan