CATScript - Looping Hide/Show in CATProduct
CATScript - Looping Hide/Show in CATProduct
(OP)
Hi,
I'm trying to step through a CATProduct (and all sub-products) and display each level at a time with the following routine. It works the first time through, and the second time it shows me the selection contains the right items, but it doesn't apply the HIDE to them.
For example.
In the first step it turns off CATProduct A & B, but then it reports the selection CATParts a,b, & c but doesn't turn them off.
What am I missing?
Thanks (as always),
Jeff
I'm trying to step through a CATProduct (and all sub-products) and display each level at a time with the following routine. It works the first time through, and the second time it shows me the selection contains the right items, but it doesn't apply the HIDE to them.
For example.
CODE
CATProduct 1
containing CATProduct A
containing CATPart a
containing CATPart b
containing CATPart c
containing CATProduct B
containing CATPart i
containing CATPart ii
containing CATPart iii
containing CATProduct A
containing CATPart a
containing CATPart b
containing CATPart c
containing CATProduct B
containing CATPart i
containing CATPart ii
containing CATPart iii
CODE
Sub CATMAIN()
Dim documentlist
Dim MainDocument As ProductDocument
Set documentlist = CATIA.Documents
Set MainDocument = CATIA.ActiveDocument
Set oTopProduct = MainDocument.Product
Call TurnOff(oTopProduct)
End Sub
Sub TurnOff(oTopProduct)
Dim selection1 As Selection
Set selection1 = oTopProduct.Parent.Selection
Dim visPropertySet1 As VisPropertySet
Set visPropertySet1 = selection1.VisProperties
Dim ItemToHide As Product
Dim lNumberOfItems As Long
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
Set ItemToHide = oTopProduct.Products.Item(i)
selection1.Add ItemToHide
SelectionList = SelectionList & chr(10) & selection1.Item(i).LeafProduct.Name
next
MsgBox "Selection is " & SelectionList
Set visPropertySet1 = selection1.VisProperties
VisPropertySet1.SetShow 1 'HIDE
MsgBox "Selected components should be off"
Dim k,m
k = ItemToHide.Products.Count
For m = 0 to k
VisPropertySet1.SetShow 0 'SHOW
Call TurnOff(ItemToHide.ReferenceProduct)
VisPropertySet1.SetShow 1 'HIDE
Next
End Sub
Dim documentlist
Dim MainDocument As ProductDocument
Set documentlist = CATIA.Documents
Set MainDocument = CATIA.ActiveDocument
Set oTopProduct = MainDocument.Product
Call TurnOff(oTopProduct)
End Sub
Sub TurnOff(oTopProduct)
Dim selection1 As Selection
Set selection1 = oTopProduct.Parent.Selection
Dim visPropertySet1 As VisPropertySet
Set visPropertySet1 = selection1.VisProperties
Dim ItemToHide As Product
Dim lNumberOfItems As Long
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
Set ItemToHide = oTopProduct.Products.Item(i)
selection1.Add ItemToHide
SelectionList = SelectionList & chr(10) & selection1.Item(i).LeafProduct.Name
next
MsgBox "Selection is " & SelectionList
Set visPropertySet1 = selection1.VisProperties
VisPropertySet1.SetShow 1 'HIDE
MsgBox "Selected components should be off"
Dim k,m
k = ItemToHide.Products.Count
For m = 0 to k
VisPropertySet1.SetShow 0 'SHOW
Call TurnOff(ItemToHide.ReferenceProduct)
VisPropertySet1.SetShow 1 'HIDE
Next
End Sub
What am I missing?
Thanks (as always),
Jeff





RE: CATScript - Looping Hide/Show in CATProduct
I've modified your macro a little bit, is just a workaround (CATScript)....
Sub CATMAIN()
Dim documentlist
Dim MainDocument As ProductDocument
Set documentlist = CATIA.Documents
Set MainDocument = CATIA.ActiveDocument
Set oTopProduct = MainDocument.Product
Call TurnOff(oTopProduct)
End Sub
Sub TurnOff(oTopProduct)
Dim selection1 As Selection
Set selection1 = oTopProduct.Parent.Selection
Dim visPropertySet1 As VisPropertySet
Set visPropertySet1 = selection1.VisProperties
Dim ItemToHide As Product
Dim lNumberOfItems As Long
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
Set ItemToHide = oTopProduct.Products.Item(i)
selection1.Add ItemToHide
SelectionList = SelectionList & chr(10) & selection1.Item(i).LeafProduct.Name
next
MsgBox "Selection is " & SelectionList
Set visPropertySet1 = selection1.VisProperties
VisPropertySet1.SetShow 1 'HIDE
selection1.Clear
MsgBox "Select components should be shown, you have to hit ESCAPE key when you want to finish, maximum number of loops is 100"
Set oPartDocument = CATIA.ActiveDocument
Set oSelection = oPartDocument.Selection
Dim oInputType(0)
Dim oStatus
For i = 1 To 100
oInputType(0) = "AnyObject"
oStatus = oSelection.SelectElement2(oInputType, "Select something in Specification Tree", True)
If (oStatus = "Cancel") Then
Exit Sub
Else
CATIA.StartCommand "Hide/Show"
End If
Next
End Sub
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: CATScript - Looping Hide/Show in CATProduct
Looking through the code it seems the problem isn't with the hide/show, but with the selection. For some reason it isn't properly adding the lower level components to the selection, so when I change the visibility it isn't affecting anything (since nothing is selected). Am I using the wrong container to trap the lower level components?
Thanks,
Jeff
RE: CATScript - Looping Hide/Show in CATProduct
You noticed same behaviour like me, that's why I choose to force user to select something.
I thought is only about hide/show, obviously I was wrong. Did you find a solution for your problem ? If not, can you detail a little bit ?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: CATScript - Looping Hide/Show in CATProduct
I modified my code a little, because I had some unintended mistakes in it as well. It still doesn't work. But I don't understand why CATIA correctly reports an item is added to the selection list, but won't apply the "Hide" to it.
CODE
Sub CATMAIN() Dim oTopProduct As Product Dim MainDocument As ProductDocument Set MainDocument = CATIA.ActiveDocument Set oTopProduct = MainDocument.Product Call TurnOff(oTopProduct) End Sub Sub TurnOff(oTopProduct) Dim i,j Dim selection1 As Selection Dim visPropertySet1 As VisPropertySet Dim ItemToHide As Product Dim NumberOfItems As Long Dim SelectionList as String Set selection1 = oTopProduct.Parent.Selection Set visPropertySet1 = selection1.VisProperties NumberOfItems = oTopProduct.Products.Count SelectionList = "" selection1.Clear For i = 1 to NumberOfItems set ItemToHide = oTopProduct.Products.Item(i) selection1.Add ItemToHide MsgBox "Added " & ItemToHide.PartNumber SelectionList = SelectionList & chr(10) & selection1.Item(i).LeafProduct.PartNumber next MsgBox "Selection is " & SelectionList Set visPropertySet1 = selection1.VisProperties VisPropertySet1.SetShow 1 'HIDE MsgBox "Selected components should be off" For j = 1 to NumberOfItems Set ItemToHide = oTopProduct.Products.Item(j) k = ItemToHide.Products.Count if k > 0 then VisPropertySet1.SetShow 0 'SHOW MsgBox "Entering " & ItemToHide.ReferenceProduct.PartNumber selection1.Clear Call TurnOff(ItemToHide.ReferenceProduct) VisPropertySet1.SetShow 1 'HIDE end if next End SubJeff
RE: CATScript - Looping Hide/Show in CATProduct
Sometimes I just have to change the approach, and then I can stop banging my head against the wall.
Jeff