Imports System.IO
Imports System.Runtime.InteropServices
Public Class frmAssemblyQuery
Sub OpenSolidEdgeDocument(ByVal objApplication As SolidEdgeFramework.Application, ByVal path As String)
Dim objDocuments As SolidEdgeFramework.Documents
Dim objDocument As SolidEdgeFramework.SolidEdgeDocument
Dim objAssemblyDocument As SolidEdgeAssembly.AssemblyDocument
Dim objDraftDocument As SolidEdgeDraft.DraftDocument
Dim objPartDocument As SolidEdgePart.PartDocument
Dim objSheetMetalDocument As SolidEdgePart.SheetMetalDocument
Dim objWeldmentDocument As SolidEdgePart.WeldmentDocument
objDocuments = objApplication.Documents
objDocument = objDocuments.Open(path)
Select Case objDocument.Type
Case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument
objAssemblyDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument
objDraftDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igPartDocument
objPartDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument
objSheetMetalDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igUnknownDocument
' Handle case
Case SolidEdgeFramework.DocumentTypeConstants.igWeldmentAssemblyDocument
' Weldment Assembly Document
Case SolidEdgeFramework.DocumentTypeConstants.igWeldmentDocument
objWeldmentDocument = objDocument
End Select
End Sub
Function GetTrainingFolder() As DirectoryInfo
Dim objInstallData As SEInstallDataLib.SEInstallData = Nothing
Dim objInstallFolder As DirectoryInfo = Nothing
Dim objTrainingFolder As DirectoryInfo = Nothing
Try
objInstallData = New SEInstallDataLib.SEInstallData
objInstallFolder = New DirectoryInfo(objInstallData.GetInstalledPath())
objTrainingFolder = New DirectoryInfo(Path.Combine(objInstallFolder.Parent.FullName, "Training"))
Catch
Finally
If Not (objInstallData Is Nothing) Then
Marshal.FinalReleaseComObject(objInstallData)
objInstallData = Nothing
End If
End Try
Return objTrainingFolder
End Function
Private Sub AssemblyQuery_Click(sender As Object, e As EventArgs) Handles AssemblyQuery.Click
Dim objTrainingFolder As DirectoryInfo
Dim objApplication As SolidEdgeFramework.Application
Dim objQueries As SolidEdgeAssembly.Queries
Dim objQuery As SolidEdgeAssembly.Query
Dim objDoc As SolidEdgeAssembly.AssemblyDocument
Dim objSelectSet As SolidEdgeFramework.SelectSet
Dim str1 As String
Try
'Get Solid Edge Application
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
'Get Training Folder
objTrainingFolder = GetTrainingFolder()
'Open Coffee Pot.asm
OpenSolidEdgeDocument(objApplication, Path.Combine(objTrainingFolder.FullName, "Coffee Pot.asm"))
objDoc = objApplication.ActiveDocument
'Get existing queries (if any)
objQueries = objDoc.Queries
If objQueries.Count = 0 Then
'Add new query
objQuery = objQueries.Add("Query1")
Else
'Update existing query
objQuery = objQueries.Item(1)
'Clear all criteria's of above query
objQuery.RemoveAllCriteria()
End If
'Specify scope for query
objQuery.Scope = SolidEdgeAssembly.QueryScopeConstants.seQueryScopeAllParts
objQuery.SearchSubassemblies = True
'String to be set as "Value"
str1 = "strainer"
'Add Criteria to above query
objQuery.AddCriteria(SolidEdgeAssembly.QueryPropertyConstants.seQueryPropertyName, "Name", SolidEdgeAssembly.QueryConditionConstants.seQueryConditionContains, str1)
'Below Statement will execute Query 1 from assembly document
objQuery = objQueries.Item(1)
'To check the count from above statement use "MatchesCount"
MsgBox(objQuery.MatchesCount.ToString)
'Use below statement to put these selected objects on the select set.
objSelectSet = objDoc.SelectSet
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class