Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Create a custom SelectionSet, which selects only Objects originating from Advance Steel

eduardo_salvador02
Enthusiast

Create a custom SelectionSet, which selects only Objects originating from Advance Steel

eduardo_salvador02
Enthusiast
Enthusiast

Hello! Through the SOftware, we have the option of importing an XML file into the SelectionSet. I was trying to do the same through the API, but I did not find any method that allowed me to import this XML file through the .NET API.

I was developing the code below, I managed to create the SelectionSet, but it still does not return the selected items according to the category and property.

I'll leave my XML code below for review, and my .NET code that I was developing.

I'm waiting!

XML:

<?xml version="1.0" encoding="UTF-8" ?>

<exchange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://download.autodesk.com/us/navisworks/schemas/nw-exchange-12.0.xsd" units="mm" filename="Lista de Material Advance Steel.nwd" filepath="A:\01-Clientes\Inpasa\2023.115 - Usina Etanol - Sidrolândia\Áreas\_Auxiliar\Lista de Material Advance Steel">
<selectionsets>
<selectionset name="Advance Steel" guid="48671e2e-028f-4fea-9d0e-2d3c9ec659da">
<findspec mode="all" disjoint="0">
<conditions>
<condition test="contains" flags="10">
<property>
<name internal="LcOaSceneBaseClassUserName">Type</name>
</property>
<value>
<data type="wstring">AST</data>
</value>
</condition>
</conditions>
<locator>/</locator>
</findspec>
</selectionset>
</selectionsets>
</exchange>

.NET CODE:

public static void AdicionarConjuntoSelecaoAdvanceSteel()
{
try
{
Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;

// Esta linha agora retorna corretamente uma ModelItemCollection
ModelItemCollection conjuntoSelecaoAdvanceSteel = create_search("LcOaSceneBaseClassUserName", "Type", "AST", "Advance Steel");

// Usa a ModelItemCollection diretamente sem casting
doc.CurrentSelection.Clear();
doc.CurrentSelection.AddRange(conjuntoSelecaoAdvanceSteel);
}
catch (Exception ex)
{
MessageBox.Show($"Erro ao criar o conjunto de seleção 'Advance Steel'.\nErro: {ex.Message}", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public static ModelItemCollection create_search(string categoryDisplayName, string propertyDisplayName, string variantData, string searchSetName)
{
// Cria uma nova busca
Search search = new Search();

// Define a condição de busca para a propriedade com o nome de exibição fornecido
// e verifica se o valor de exibição é igual ao valor de 'variantData'
// Nota: A API padrão verifica igualdade; uma abordagem "contém" pode exigir uma implementação customizada
SearchCondition condition = SearchCondition
.HasPropertyByName(categoryDisplayName, propertyDisplayName)
.EqualValue(VariantData.FromDisplayString(variantData));

// Adiciona a condição de busca ao objeto de busca
search.SearchConditions.Add(condition);

// Configura a busca para selecionar todos os descendentes e o próprio item
search.Selection.SelectAll();
search.Locations = SearchLocations.DescendantsAndSelf;

// Executa a busca e cria um conjunto de seleção com os resultados
ModelItemCollection results = search.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);

// Adiciona um novo conjunto de seleção ao documento com base nos resultados
// Isso é um pouco diferente do XML, onde o conjunto de seleção é definido dentro do arquivo
SelectionSet newSelectionSet = new SelectionSet(results);
newSelectionSet.DisplayName = searchSetName;
Autodesk.Navisworks.Api.Application.ActiveDocument.SelectionSets.AddCopy(newSelectionSet);

return results;
}

0 Likes
Reply
431 Views
2 Replies
Replies (2)

jabowabo
Mentor
Mentor

Edit: Try this for your search condition:

SearchCondition searchCond = SearchCondition.
	HasPropertyByDisplayName("Item", "Type").
	DisplayStringWildcard("AST*")
	.IgnoreStringValueCase();

 

0 Likes

eduardo_salvador02
Enthusiast
Enthusiast

 

Perfect! Works exactly how I need it! Thank you very much!

See if you can help me with this other question.

I need to edit the "Quick Property Definitions" properties, but I'm not having success. I found the following information regarding this global option on a forum:

[7]interface.smart_tags: Quick Properties|smart_tags(|eFLAG_ORDERED)
[0]interface.smart_tags.enabled: Show Quick Properties => Boolean:True
[1]interface.smart_tags.hide_category: Hide Category => Boolean:False
[2]interface.smart_tags.definitions: Definitions|definitions(|eFLAG_ARRAY)
[0]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaNode(Item)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:LcOaSceneBaseUserName(Name)
[1]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaPropOverrideCat(Idigo)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:Fluid Code(Fluid Code)
[2]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcRevitData_Element(Element)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:lcldrevit_parameter_4911058(Pressure Drop)
[3]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcRevitData_Element(Element)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:lcldrevit_parameter_5085687(Pressure Drop)
[4]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaPropOverrideCat(Idigo)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:Zone(Zone)
[5]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:PDMS(PDMS)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:lcldrvm_prop_:clap(:CLAP)
[6]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaPropOverrideCat(Idigo)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:Pipe NPS(Pipe NPS)
[7]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaPropOverrideCat(Idigo)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:Pipe Total OD(Pipe Total OD)
[8]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaPropOverrideCat(Idigo)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:Pipeline(Pipeline)
[9]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LcOaPropOverrideCat(Idigo)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:Pipe Length(Pipe Length)
[10]interface.smart_tags.definitions.:
[0]interface.smart_tags.definitions..category: Category => NamedConstant:LineStyle(LineStyle)
[1]interface.smart_tags.definitions..property: Property => NamedConstant:GraphicsStyleType(GraphicsStyleType)

However, I don't know how to change these values ​​to the ones I need, through Navisworks, I also use an XML file that I just import, and it already changes the settings.

XML is linked in the post.

0 Likes