Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - Selection query - Published elements only

Status
Not open for further replies.

lukaszsz

Aerospace
Oct 16, 2012
71
PL
Hello all

Is there any possibility to create query for search that returns Published elemetns only (as it is possible in 'Search window' - CTRL+F)

Or is there any other possibility to check, if element is published? via VBScript?

Thanks in advance

LukaszSz



LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Replies continue below

Recommended for you

Hi,

Again, late response...

Code:
Sub CATMain()

Dim iAnswer 
iAnswer = MsgBox ("You need to select first all what is under Publication" & Chr(10) & "Click OK if you already done the selection or Cancel to EXIT", vbOKCancel)
         
if iAnswer = vbCancel Then 
        Exit Sub
Else

Dim oWindow
Set oWindow = CATIA.ActiveWindow
'create text file
sPath = "C:\Temp"
sName = "\Published_elements_for_" & oWindow.Caption & ".TXT"
sFile = sPath & sName
Dim oFileOut 'As File
Set oFileOut = CATIA.FileSystem.CreateFile(sFile, True)
Dim oStream 'As TextStream
Set oStream = oFileOut.OpenAsTextStream("ForWriting")
 oStream.Write "Published element"  & "      %     Name of publication    %    "  & "        Parent name of publication"   & vbcrlf
 
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim ActiveDocument As Document
Set ActiveDocument = CATIA.ActiveDocument

Dim ActiveDocumentPublications As Publications
Set ActiveDocumentPublications = ActiveDocument.Product.Publications   
      
    ' Current children selection
    Set UserSelection = ActiveDocument.Selection
    NumberOfSelectedElement = UserSelection.Count   
    Redim ChildrenList(NumberOfSelectedElement)
    
For i=1 To NumberOfSelectedElement

Set ChildrenList(i) = UserSelection.Item(i).Value        
        oStream.Write ChildrenList(i).Name & "   %   " & ActiveDocument.Product.Publications.Item(i).Name  & "   %   " &  ActiveDocument.Product.Publications.Item(i).Parent.Name  & vbcrlf
Next

oStream.Close
MsgBox "Done, check file " & sName & " in " & sPath

End If

End Sub

Regards
Fernando

 
Thanks for your reply, i thought there is simply way to create query for search tool or add whole collection (doucment.product.publications) to search tool.

Here is my solution (not standalone code, just subroutine - it's part of larger project - )

Code:
Sub SearchForEl(ByRef oArrayOfFoundedEl_size As Integer, ByRef oArrayOfFoundedEl() As Variant, ByRef oArrayOfFoundedElNames() As String, ByRef oArrayOfFoundedEl_Product() As Variant)
    
    Dim Selection1 As Selection
    Set Selection1 = CATIA.ActiveDocument.Selection
    Dim Lindex As Integer
    oArrayOfFoundedEl_size = -1
    
    For i = 0 To ArrayOfParts_size
        Selection1.Clear
        
        If SearchInPublication Then
        
            If ArrayOfParts(i).Publications.Count > 0 Then
                For k = 1 To ArrayOfParts(i).Publications.Count
                    Selection1.Clear
                    Selection1.Add ArrayOfParts(i).Publications.Item(k).Valuation
                    Selection1.Search Filter
                    'MsgBox ArrayOfParts(i).Publications.Item(k).Valuation.DisplayName
                    If Selection1.Count = 1 Then
                        oArrayOfFoundedEl_size = oArrayOfFoundedEl_size + Selection1.Count
                        ReDim Preserve oArrayOfFoundedEl(oArrayOfFoundedEl_size)
                        ReDim Preserve oArrayOfFoundedElNames(oArrayOfFoundedEl_size)
                        ReDim Preserve oArrayOfFoundedEl_Product(oArrayOfFoundedEl_size)
                        Set oArrayOfFoundedEl(oArrayOfFoundedEl_size) = ArrayOfParts(i).Publications.Item(k).Valuation
                        oArrayOfFoundedElNames(oArrayOfFoundedEl_size) = ArrayOfParts(i).Publications.Item(k).Valuation.DisplayName
                        Set oArrayOfFoundedEl_Product(oArrayOfFoundedEl_size) = ArrayOfParts(i)
                        
                    End If
                Next
            End If
            
            
        Else
            
        
            Selection1.Add ArrayOfParts(i)
            Selection1.Search Filter
            If Selection1.Count > 0 Then
                LIndex = oArrayOfFoundedEl_size
                oArrayOfFoundedEl_size = oArrayOfFoundedEl_size + Selection1.Count
                ReDim Preserve oArrayOfFoundedEl(oArrayOfFoundedEl_size)
                ReDim Preserve oArrayOfFoundedElNames(oArrayOfFoundedEl_size)
                ReDim Preserve oArrayOfFoundedEl_Product(oArrayOfFoundedEl_size)
                For j = 1 To Selection1.Count
                    Set oArrayOfFoundedEl(LIndex + j) = Selection1.Item(j).Value
                    oArrayOfFoundedElNames(LIndex + j) = ArrayOfPartsNames(i) & "/!" & Selection1.Item(j).Value.Name
                    Set oArrayOfFoundedEl_Product(LIndex + j) = ArrayOfParts(i)
                    'MsgBox ArrayOfFoundedEl1Names(j - 1)
                Next
            End If
        
        
        End If
    Next

End Sub

If SearchInPublication = true, then oArrayOfFoundedEl contains Reference objects, otherwise it contains AnyObject (in this code: Plane, Line, AxisSystem)


Public variables Declarations
Code:
Public ArrayOfParts() As Variant
Public ArrayOfPartsNames() As String
Public ArrayOfParts_size As Integer
Public Filter As String
Public SearchInPublication As Boolean

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top