×
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

CATScript - Looping Hide/Show in CATProduct

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.

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

RE: CATScript - Looping Hide/Show in CATProduct

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

https://picasaweb.google.com/102257836106335725208

RE: CATScript - Looping Hide/Show in CATProduct

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

RE: CATScript - Looping Hide/Show in CATProduct

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

https://picasaweb.google.com/102257836106335725208

RE: CATScript - Looping Hide/Show in CATProduct

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

RE: CATScript - Looping Hide/Show in CATProduct

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

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