Sub CATMain() 'Abfrage Dokumente If CATIA.Windows.Count = 0 Then Box = MsgBox("Es ist kein Dokument geladen!" + Chr(10) + "Das Makro kann nicht ausgeführt werden und wird beendet!", vbCritical, "Keine Dokument geladen") Exit Sub End If Set Dokument = CATIA.ActiveDocument If TypeName(Dokument) <> "ProductDocument" Then Box = MsgBox("Das aktiv geladen Dokument ist KEIN CATProduct!" + Chr(10) + "Bitte aktivieren sie ein CATProduct und starten sie das Makro erneut!", vbExclamation, "Abbruch falscher Dateityp") Exit Sub End If set Product_Collection = new Collection Set Produkte = Dokument.Product.Products for each Product in Produkte Product_Collection.add Product.Name next Product_Collection.sort Set oSel = Dokument.Selection oSel.clear for i = 1 to Product_Collection.Count oSel.add Produkte.Item(Product_Collection.Item(i)) oSel.cut oSel.clear oSel.add Dokument.Product oSel.Paste oSel.clear next end sub class Collection private Array() sub class_initialize() 'Array mit 1 (leeren) Datenfeld anlegen' Redim Array(0) end Sub 'Elemat am Ende des Arrays hinzufügen (automatische erweitern)) public Sub add(Datenfeld) Index = Ubound(Array) ReDim preserve Array((Index+1)) Array(Index+1) = Datenfeld end Sub 'Datenfeld ausgeben public function Item(Index) 'Überprüfen: Index zu hoch? Index 0 ist leer' if (Index <= 0 and Index > Ubound(Array)) then Item = "ungültiger Index" Else Item = Array(Index) End If end function 'den Array aufsteigend sortieren' Sub sort 'Bubblesort for i = 1 to Ubound(Array)-1 for u = i to Ubound(Array) if Array(i) > Array(u) then 'temp-Variable schreiben, danach austauschen temp = Array(i) Array(i) = Array(u) Array(u) = temp end if next next end Sub public function Count Count = Ubound(Array) end function end class