Sylas Mitglied
Beiträge: 348 Registriert: 19.11.2012 Dell Precision T3500 Intel Xeon W3550 @ 3,07 GHz 12 GB RAM CATIA V5 R28
|
erstellt am: 27. Jun. 2024 11:43 <-- editieren / zitieren --> Unities abgeben:
Hello Community! I'm trying to write a code to automatically rename captures / views / cameras. The problem occures when there's more then one capture based on (supported by) the same view. What I want in this case is to preserve viewm name from the first rename occurance. Instead of that - my code renames it each time I tried to use ActiveViewState property, but it seems not working. Below my code - maybe someone could give me some tips... Code:
Sub CATMain() 'On Error Resume Next Dim oAnnSet As AnnotationSet Dim odSel As Selection Dim oSel Dim InputObjectType(1) As Variant Dim oTable() As Variant Dim oPart As Part Dim oDoc As DocumentSet odSel = CATIA.ActiveDocument.Selection Set oSel = odSel InputObjectType(0) = "Product" InputObjectType(1) = "Part" Result = oSel.SelectElement2(InputObjectType, "Choose FTA", True) If TypeName(oSel.Item(1).Value) = "Product" Then Set oPart = oSel.Item(1).Value.ReferenceProduct.Parent.Part Set oDoc = oSel.Item(1).Value.ReferenceProduct.Parent Else Set oPart = oSel.Item(1).Value Set oDoc = oSel.Item(1).Value.Parent End If 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) 'captures naming pass 1 For i = oAnnSet.Captures.Count To 1 Step -1 Set oCapture = oAnnSet.Captures.Item(i) If Left(oCapture.Name, 2) <> "C." Then oCapture.Name = "C." & oCapture.Name End If Next 'captures naming pass 2 For i = oAnnSet.Captures.Count To 1 Step -1 Set oCapture = oAnnSet.Captures.Item(i) If Left(oCapture.Name, 3) = "C. " Then oCapture.Name = Replace(oCapture.Name, "C. ", "C.", , 1) End If Next 'captures naming pass 3 For i = oAnnSet.Captures.Count To 1 Step -1 Set oCapture = oAnnSet.Captures.Item(i) If InStr(1, oCapture.Name, "/") <> 0 Then If InStr(1, Mid(oCapture.Name, InStr(1, oCapture.Name, "/") - 1, 3), " ") = 0 Then oCapture.Name = Replace(oCapture.Name, "/", " / ", , 1) End If End If Next 'cameras and views renaming 'Set oActiveView = Nothing 'For i = oAnnSet.Captures.Count To 1 Step -1 For i = 1 To oAnnSet.Captures.Count Set oCapture = oAnnSet.Captures.Item(i) Set oCamera = oCapture.Camera 'cameras naming If InStr(1, oCapture.Name, " / ") <> 0 Then oCamera.Name = Mid(oCapture.Name, 3, InStr(1, oCapture.Name, " / ") - 3) ElseIf InStr(1, oCapture.Name, "/") <> 0 Then oCamera.Name = Mid(oCapture.Name, 3, InStr(1, oCapture.Name, "/") - 3) Else oCamera.Name = Mid(oCapture.Name, 3) End If If oCapture.ActiveViewState = True Then '<------ this should work for captures without supporting view, but it's not :( Set oActiveView = oCapture.ActiveView oActiveView.Name = Mid(oCapture.Name, 3, Len(oCapture.Name)) End If oNameTable(i - 1) = oCamera.Name 'Set oActiveView = Nothing Next oSel.Clear 'deleting unused cameras For j = oDoc.Cameras.Count To 1 Step -1 If IsInArray(oDoc.Cameras.Item(j).Name, oNameTable) = False Then oDoc.Cameras.Remove j End If Next MsgBox ("Done!") End Sub
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |