LucasC
Automotive
- Feb 18, 2019
- 157
I've been struggling to find a -reliable- solution to this problem for over a year now.
I only want my userform/macro to open in V5 if an active document is present. Otherwise, if no files are open, the macro gives a runtime error for the user.
Currently, I control this with doing a simple If CATIA.Documents.Count = 0 then msg to user and exit sub. works completely fine right after you start CATIA and no files have been opened. Here is where it gets tricky. after working/opening/closing files there are .CATfct files present in the background that apparently don't count as active documents. They do, however, increase the value of CATIA.documents.count so my simple if..then = 0 logic fails since the count is now a value 1-4 with no active documents open.
There seems to be different types that occur in our system ABQMaterialscatalog.CATfct, CAAPstProductIconExt.CATfct, and another 1 or 2 I can't duplicate atm (QWERTY....something or CATSessionSetup...something rings a bell). these seem to occur randomly depending on what files/products have been worked on by the user. so it can be 0-3or4 of them present in any combination.
Any ideas how I can make this function properly? catia.activedocument doesn't get the .count property unfortunately.
I've been able to capture the .CATfct files in an array and identify them when present. I tried the below code for Product/part/drawing with no luck. But like I mentioned before, there may be 0, 1, 2, 3, 4 or more present so the array goes out of range when they are not present. I also think my use of the "<> right(string,8)" is wrong...
I've also thought about getting rid of the array and just going with
any thoughts/ideas??
I only want my userform/macro to open in V5 if an active document is present. Otherwise, if no files are open, the macro gives a runtime error for the user.
Currently, I control this with doing a simple If CATIA.Documents.Count = 0 then msg to user and exit sub. works completely fine right after you start CATIA and no files have been opened. Here is where it gets tricky. after working/opening/closing files there are .CATfct files present in the background that apparently don't count as active documents. They do, however, increase the value of CATIA.documents.count so my simple if..then = 0 logic fails since the count is now a value 1-4 with no active documents open.
There seems to be different types that occur in our system ABQMaterialscatalog.CATfct, CAAPstProductIconExt.CATfct, and another 1 or 2 I can't duplicate atm (QWERTY....something or CATSessionSetup...something rings a bell). these seem to occur randomly depending on what files/products have been worked on by the user. so it can be 0-3or4 of them present in any combination.
Any ideas how I can make this function properly? catia.activedocument doesn't get the .count property unfortunately.
I've been able to capture the .CATfct files in an array and identify them when present. I tried the below code for Product/part/drawing with no luck. But like I mentioned before, there may be 0, 1, 2, 3, 4 or more present so the array goes out of range when they are not present. I also think my use of the "<> right(string,8)" is wrong...
Code:
Dim DocCount As Integer
DocCount = CATIA.Documents.Count
Dim NameArray(3) As String
NameArray(0) = CATIA.Documents.Item(1).Name
NameArray(1) = CATIA.Documents.Item(2).Name
NameArray(2) = CATIA.Documents.Item(3).Name
If NameArray(0) <> Right(".CATPart", 8) Then
MsgBox "There are no CATIA Files open.", vbInformation
Exit Sub
End If
I've also thought about getting rid of the array and just going with
Code:
Dim DocCount As Integer
DocCount = CATIA.Documents.Count
Dim n as integer
For n = 1 to DocCount step 1
If CATIA.Documents.Item(n).Name <> Right(".CATPart", 8) Then
MsgBox "There are no CATIA Files open.", vbInformation
Exit Sub
End If
Next n
'... duplicate the above for .catprduct and .catdrawing
any thoughts/ideas??