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!

CATScript - Looping Hide/Show in CATProduct

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
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.
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
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.
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


What am I missing?

Thanks (as always),
Jeff
 
Replies continue below

Recommended for you

Hi,

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

 
Thanks Fernando, but I need the operation to be automated so that I can run some other functions in between.

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
 
Hi,

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

 
No solution yet.

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 Sub

Jeff
 
I solved it by changing from a "For i=1 to numberOfItems" and relying on Item(i) index, to doing it as For Each Prod in 'AllProducts'. It seems that my index wasn't "liked" by the CATScript.

Sometimes I just have to change the approach, and then I can stop banging my head against the wall.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor