Redefine the site level User-defined propety classification in Site Parcel Properties

Redefine the site level User-defined propety classification in Site Parcel Properties

msullivan
Participant Participant
443 Views
3 Replies
Message 1 of 4

Redefine the site level User-defined propety classification in Site Parcel Properties

msullivan
Participant
Participant

I wrote this command method to update all of the parcels in a drawing to use a user-defined property classification, and it works great, but I can't seem to find a method to change the User-defined property classification in the Site Parcel Properties directly? The new UDP does not show up in the Prospector graph view unless it is selected in that dialog. Does anyone know if changing that is possible through the COM/API?

 

[CommandMethod("SETUDPCLASS")]
public void SetUDPClass()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    CivilDocument civilDoc = CivilApplication.ActiveDocument;
    
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        ObjectIdCollection siteIds = civilDoc.GetSiteIds();
        
        if (siteIds.Count == 0)
        {
            ed.WriteMessage("\nNo parcel sites found in drawing.");
            tr.Commit();
            return;
        }
        
        int sitesProcessed = 0;
        
        foreach (ObjectId siteId in siteIds)
        {
            Site site = tr.GetObject(siteId, OpenMode.ForWrite) as Site;
            if (site == null) continue;
            
            dynamic comSite = null;
            dynamic parcels = null;
            dynamic parcelsProperties = null;
            
            try
            {
                comSite = site.AcadObject;
                parcels = comSite.Parcels;
                parcelsProperties = parcels.Properties;
                
                parcelsProperties.SetUserDefinedPropertyClassification(0, "LandUse");
                
                ed.WriteMessage($"\nSet UDP classification to 'LandUse' for site: {site.Name}");
                sitesProcessed++;
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\nError for site {site.Name}: {ex.Message}");
            }
            finally
            {
                if (parcelsProperties != null && Marshal.IsComObject(parcelsProperties))
                    Marshal.ReleaseComObject(parcelsProperties);
                if (parcels != null && Marshal.IsComObject(parcels))
                    Marshal.ReleaseComObject(parcels);
                if (comSite != null && Marshal.IsComObject(comSite))
                    Marshal.ReleaseComObject(comSite);
            }
        }
        
        ed.WriteMessage($"\n{sitesProcessed} site(s) updated.");
        tr.Commit();
    }
}

 

0 Likes
Accepted solutions (1)
444 Views
3 Replies
Replies (3)
Message 2 of 4

msullivan
Participant
Participant

I tried adding in a Site.UseCustomClassification(LandUse) and Site.UseAllClassifications() to the loop based on a recommendation, but that didn't work. I have also tried a COM approach. My suspicion is the dialog drop down in the Site Parcel Properties to set the UDP is not exposed to the API.

0 Likes
Message 3 of 4

Jeff_M
Consultant
Consultant
Accepted solution

@msullivan This works for me:

                foreach (ObjectId siteId in siteIds)
                {
                    Site site = tr.GetObject(siteId, OpenMode.ForWrite) as Site;
                    if (site == null) continue;

                    try
                    {
                        site.UseCustomClassification("LandUse");
                        sitesProcessed++;
                    }
                    catch (System.Exception ex)
                    {
                        ed.WriteMessage($"\nError for site {site.Name}: {ex.Message}");
                    }
                }

After looking at the COM API, your initial code likely would have worked if you used this: 


                parcelsProperties.SetUserDefinedPropertyClassification(2, "LandUse");

 Note the 2...you had 0 which specified to use the None type, whereas 2 is the Custom type.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 4 of 4

msullivan
Participant
Participant

Yeah man, that did it. I just changed that type to 2 and it worked. I might give the other method a try, but I'm happy with the results for now.

0 Likes