| |
 | Gut zu wissen: Hilfreiche Tipps und Tricks aus der Praxis prägnant, und auf den Punkt gebracht für CATIA & Co. |
| |
 | KISTERS 3DViewStation: Germar Nikol - Der Visionär hinter der Erfolgsgeschichte, eine Pressemitteilung
|
Autor
|
Thema: FTA useless cameras (667 mal gelesen)
|
Sylas Mitglied
 
 Beiträge: 349 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 21. Aug. 2023 12:05 <-- editieren / zitieren --> Unities abgeben:         
Hello Community! I'm sorry if the question was already answered, but I didn't find the answer anywhere, so I ask here: Many times, I find FTA for my models made by suppliers with many, many cameras, from which only few are actually used. Is it possible to check which one of them are parentless and to select them and delete? I know I can check if the capture has camera bond, but can't figure the other way around.... Any idea? Thanks in advance Lucas Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
       
 Beiträge: 12054 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 21. Aug. 2023 17:18 <-- editieren / zitieren --> Unities abgeben:          Nur für Sylas
|
Sylas Mitglied
 
 Beiträge: 349 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 21. Aug. 2023 22:36 <-- editieren / zitieren --> Unities abgeben:         
Zitat: Original erstellt von bgrittmann: Hi LucasI'm not familiar with FTA. You wanna delete all cameras, which are not used in a capture? regards, Bernd
Exactly. I've come to point when I can temporarily rename all cameras used by captures, so after that I know which ones are used or not 😉 But after this point I manually delete not renamed (not used). I want to somehow delete them automatically 😉 Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
       
 Beiträge: 12054 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 22. Aug. 2023 09:03 <-- editieren / zitieren --> Unities abgeben:          Nur für Sylas
Hi, Do these cameras belong to the cameras of the document? (CATIA.ActiveDocument.Cameras) If so, there is also a remove method regards, Bernd PS: Instead of renaming you can also create a list/dictionary/array with the cameras used in the captures ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sylas Mitglied
 
 Beiträge: 349 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 22. Aug. 2023 11:23 <-- editieren / zitieren --> Unities abgeben:         
Zitat: Original erstellt von bgrittmann: Hi,Do these cameras belong to the cameras of the document? ([i]CATIA.ActiveDocument.Cameras) If so, there is also a remove method regards, Bernd PS: Instead of renaming you can also create a list/dictionary/array with the cameras used in the captures [/i]
Hello Bernd Thank you for your comment Yes - the cameras are part of the active document (If I manually open Named views window, I can see all of them in). The trick is how to define the unused ones? By changing the name I know which one are used, so the only way I'm thinking of is to rename them by adding some pre-/suffix to the name, like "temp_xxxx" and then make a loop checking camera name for that prefix, and when does not exist remove from Cameras Collection.... is it good approach? What do you think? Best regards Lucas EDIT: I tried to go through cameras collection of the document, like this:
Code:
For j = 1 To oDoc.Cameras.Count If InStr(1, oDoc.Cameras.Item(j).Name, "temp_") = 0 Then oSel.Add oDoc.Cameras.Item(j) End If Next oSel.Delete oSel.Clear
but it seems CATIA isn;t adding unused cameras to the selection  how can I remove them from the document? [Diese Nachricht wurde von Sylas am 22. Aug. 2023 editiert.] Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
       
 Beiträge: 12054 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 22. Aug. 2023 11:29 <-- editieren / zitieren --> Unities abgeben:          Nur für Sylas
Hi Lucas this should be possibile. I already mention a other approach. create a list of used cameras, loop trough the cameras, if not in this list remove the camera regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sylas Mitglied
 
 Beiträge: 349 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 22. Aug. 2023 11:47 <-- editieren / zitieren --> Unities abgeben:         
Zitat: Original erstellt von bgrittmann: Hi Lucasthis should be possibile. I already mention a other approach. create a list of used cameras, loop trough the cameras, if not in this list remove the camera regards, Bernd
please take a look at post above, which I've edited 
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
       
 Beiträge: 12054 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 22. Aug. 2023 12:10 <-- editieren / zitieren --> Unities abgeben:          Nur für Sylas
|
Sylas Mitglied
 
 Beiträge: 349 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 22. Aug. 2023 12:56 <-- editieren / zitieren --> Unities abgeben:         
Zitat: Original erstellt von bgrittmann: HiSo try the intended method [i]remove (see documentation cameras-object) regards, Bernd [/i]
OK, so I'm few steps forward :) this is my code now:
Code: Sub CATMain() On Error Resume Next Dim oAnnSet As AnnotationSet Dim odSel As Selection Dim oSel Dim InputObjectType(0) As Variant Dim oTable() As Variant Dim oPart As Part Dim oDoc As DocumentSet odSel = CATIA.ActiveDocument.Selection Set oSel = odSel InputObjectType(0) = "Product" Result = oSel.SelectElement2(InputObjectType, "Choose FTA", True) Set oPart = oSel.Item(1).Value.ReferenceProduct.Parent.Part Set oDoc = oSel.Item(1).Value.ReferenceProduct.Parent Dim oAnnotationSets As AnnotationSets Set oAnnotationSets = oPart.AnnotationSets Set oAnnSet = oAnnotationSets.Item(1) Dim oCapture As Capture Dim oCamera As Camera3D Dim oActiveView As TPSView Dim oNameTable() As Variant ReDim oNameTable(oAnnSet.Captures.Count - 1) oNameTable = Empty For i = oAnnSet.Captures.Count To 1 Step -1 Set oCapture = oAnnSet.Captures.Item(i) Set oCamera = oCapture.Camera Set oActiveView = oCapture.ActiveView 'captures naming If Left(oCapture.Name, 2) <> "C." Then oCapture.Name = "C." & oCapture.Name End If 'cameras naming If InStr(1, oCapture.Name, " / ") <> 0 Then oCamera.Name = Mid(oCapture.Name, 3, InStr(1, oCapture.Name, " / ") - 2) Else oCamera.Name = Mid(oCapture.Name, 3) End If oNameTable(i - 1) = oCamera.Name Next oSel.Clear For j = 1 To oDoc.Cameras.Count If IsInArray(oDoc.Cameras.Item(j), oNameTable) = False Then question = MsgBox(oDoc.Cameras.Item(j).Name & " is not used! " & vbCrLf & "Should I delete it?", vbYesNoCancel, "Remove camera?") If question = vbYes Then oDoc.Cameras.Remove (oDoc.Cameras.Item(j).Name) ElseIf question = vbNo Then Else MsgBox ("Cancelled by user!") End End If End If Next MsgBox ("Done!") End Sub Private Function IsInArray(valToBeFound As Variant, arr As Variant) As Boolean 'DEVELOPER: Ryan Wells (wellsr.com) 'DESCRIPTION: Function to check if a value is in an array of values 'INPUT: Pass the function a value to search for and an array of values of any data type. 'OUTPUT: True if is in array, false otherwise Dim element As Variant On Error GoTo IsInArrayError: 'array is empty For Each element In arr If element = valToBeFound Then IsInArray = True Exit Function End If Next element Exit Function IsInArrayError: On Error GoTo 0 IsInArray = False End Function
Now, when I get to this line:
Code: oDoc.Cameras.Remove (oDoc.Cameras.Item(j).Name)
nothing happens :P and when I change this to this: Code: oDoc.Cameras.Remove j
it removes wrong camera - always last one from the list - I don't understand why. Could you help me to solve this? Of course, when I get it working properly, I'll remove them all at once  [Diese Nachricht wurde von Sylas am 22. Aug. 2023 editiert.] By the way, is it possible to refresh the tree, so I can see changed names f the captures, after this:
Code: 'captures naming If Left(oCapture.Name, 2) <> "C." Then oCapture.Name = "C." & oCapture.Name End If
So far, I need to collapse and expand the captures tree manually... [Diese Nachricht wurde von Sylas am 22. Aug. 2023 editiert.] Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
       
 Beiträge: 12054 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 22. Aug. 2023 13:30 <-- editieren / zitieren --> Unities abgeben:          Nur für Sylas
Do you get an error? (please remove on error resume next) have you used the watch/local window and run your code step wise? Have you tested the removing on a smaller part and easier code. I suggest, if you remove elements from a collection, work from last to first element. ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sylas Mitglied
 
 Beiträge: 349 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 22. Aug. 2023 13:48 <-- editieren / zitieren --> Unities abgeben:         
Zitat: Original erstellt von bgrittmann: Do you get an error? (please remove [i]on error resume next) have you used the watch/local window and run your code step wise? Have you tested the removing on a smaller part and easier code. I suggest, if you remove elements from a collection, work from last to first element.[/i]
Everything works like a charm! Thank you. I've found a problem in the line: Code:
If IsInArray(oDoc.Cameras.Item(j), oNameTable) = False Then
it was deleting all cameras :) It should be: Code: If IsInArray(oDoc.Cameras.Item(j).Name, oNameTable) = False Then
Thanks again for your help! Lucas Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |