×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA - Selection query - Published elements only

VBA - Selection query - Published elements only

VBA - Selection query - Published elements only

(OP)
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

RE: VBA - Selection query - Published elements only

Hi,

Again, late response...

CODE --> CATScript

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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: VBA - Selection query - Published elements only

(OP)
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 - http://www.eng-tips.com/viewthread.cfm?qid=343823 )

CODE --> CATvba

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources