I need to get the type of layer for the hidden FTA annotations. I am able to set the Layer type but unbale to get the layer type which is already defined.
My question is when the layer type is "None" then export those value to excel.
Below is the code to set the layer type.
Sub test_Layer256()
Dim wb As Workbook
Dim WS As Worksheet
Dim MyProduct
Set wb = ThisWorkbook
Set WS = wb.Worksheets("Annotaions")
WS.Range("A2:D100000").ClearContents
WS.Range("A2:D100000").Interior.Color = xlNone
lr = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
j = 2
Dim CATIA As Object
On Error Resume Next
Set CATIA = GetObject(, "CATIA.Application")
If Err.Number <> 0 Then
Set CATIA = CreateObject("CATIA.Application")
CATIA.Visible = True
End If
On Error GoTo 0
'--------------------Define CATIA------------------------------------------
Set CATIA = GetObject("", "CATIA.Application")
Set MyDocument = CATIA.ActiveDocument
Set MyProduct = MyDocument.Product
MyRootPN = MyProduct.PartNumber
MyRootInstanceName = MyProduct.Name
MyDSType = Left(MyRootPN, 4)
'--------------------Select BNS------------------------------------------
Dim objSel As Selection, oSel As Selection
Set objSel = CATIA.ActiveDocument.Selection
If Right(MyRootPN, 2) = "FD" Then
j = 2
objSel.Search "CATTPSSearch.CATFTAElement.Visibility=Hidden,all"
For i = 1 To objSel.Count
If Not objSel.Item2(i).Value.Name Like "*view*" And objSel.Item2(i).LeafProduct.PartNumber Like "*AHD*" Then
Set visProperties1 = objSel.VisProperties
visProperties1.GetLayer layertype, layer
Debug.Print objSel.Item2(i).Value.Name
WS.Cells(j, 1).Value = "Hidden AHD FTA Annotation - Layer 256"
WS.Cells(j, 2).Value = objSel.Item2(i).Value.Name
WS.Cells(j, 3).Value = layer
If WS.Cells(j, 3).Value = 256 Then
WS.Cells(j, 4).Value = "OK"
WS.Cells(j, 4).Interior.Color = RGB(204, 255, 204)
Else
WS.Cells(j, 4).Value = "NOK"
WS.Cells(j, 4).Interior.Color = RGB(255, 153, 204)
End If
j = j + 1
End If
Next i
Else
MsgBox "Please Load the Full3D set and Run again", vbCritical + vbOKOnly, "WARNING!!"
Exit Sub
End If
objSel.Clear
End Sub
To get VisProperties
from one specific element, you have to only select this element.
Possible procedure:
VisProperties
Example code:
'enter code for searching here
Dim SeletedElements() as Object
if objSel.Count <> 0 then
' store elements in an array
ReDim SeletedElements(objSel.Count)
For i = 1 To objSel.Count
Set SeletedElements(i) = objSel.Item2(i).Value
next
' select elements from array one by one
for i = 1 to UBound(SeletedElements)
' clear seelection to start
objSel.Clear
' select element
objSel.Add SeletedElements(i)
Set visProperties1 = objSel.VisProperties
visProperties1.GetLayer layertype, layer
' check if element has a layer
if layertype = catVisLayerBasic then
Msgbox SeletedElements(i).Name & ": Layer=" & layer
end if
next
end if