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
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
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: VBA - Selection query - Published elements only
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 SubIf SearchInPublication = true, then oArrayOfFoundedEl contains Reference objects, otherwise it contains AnyObject (in this code: Plane, Line, AxisSystem)
Public variables Declarations
CODE -->
LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013