Select to view content in your preferred language

Getting TextSymbols from Layerfile

616
1
Jump to solution
09-21-2021 01:01 AM
TOPOGRAPHICS
Occasional Contributor

Hello,

I want to read a Layer-File (.stylx) fom disk and get the TextSymbols (with all properties) by Name.

I need this information to generate a AnnotationClass with the right TextSymbols.

Is it possible to do this from a Core.Host C# Application, not as an add-in, and how can I do it?

Thanks a lot

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You cannot do this in a corehost application only in an add-in because styles can only be managed within the context of an ArcGIS Pro project.   You can create the style from a .stylx input file by using the StyleHelper class: .

//Full path for the new style file (.stylx) to be created
string styleToCreate = @"C:\Temp\NewStyle.stylx";
await QueuedTask.Run(() => StyleHelper.CreateStyle(Project.Current, styleToCreate));
var stylxProjectItem = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(i => i.Path == styleToCreate);

And then you can use LookupItem to find specific content:

 public Task<SymbolStyleItem> GetSymbolFromStyleAsync(StyleProjectItem style, string key)
{
    return QueuedTask.Run(() =>
    {
    if (style == null)
        throw new System.ArgumentNullException();

    //Search for a specific point symbol in style
    SymbolStyleItem item = (SymbolStyleItem)style.LookupItem(StyleItemType.PointSymbol, key);
    return item;
    });
}

 

View solution in original post

1 Reply
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You cannot do this in a corehost application only in an add-in because styles can only be managed within the context of an ArcGIS Pro project.   You can create the style from a .stylx input file by using the StyleHelper class: .

//Full path for the new style file (.stylx) to be created
string styleToCreate = @"C:\Temp\NewStyle.stylx";
await QueuedTask.Run(() => StyleHelper.CreateStyle(Project.Current, styleToCreate));
var stylxProjectItem = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(i => i.Path == styleToCreate);

And then you can use LookupItem to find specific content:

 public Task<SymbolStyleItem> GetSymbolFromStyleAsync(StyleProjectItem style, string key)
{
    return QueuedTask.Run(() =>
    {
    if (style == null)
        throw new System.ArgumentNullException();

    //Search for a specific point symbol in style
    SymbolStyleItem item = (SymbolStyleItem)style.LookupItem(StyleItemType.PointSymbol, key);
    return item;
    });
}