Sub CATMain() '#####__Declarations__#####' Dim stringSelection As String stringSelection = "" Dim stringGroup As String Dim stringSection As String stringSection = "" Dim documentRoot As Document Dim productRoot As Product Dim groupsRoot As Groups Dim groupSelection As Group Dim scenesRoot As Scenes Dim sceneInvert As Scene Dim sectionsRoot As Sections Dim sectionSelection As Section Dim positionSection(11) As Double Dim firstAxis(2) As Double Dim secondAxis(2) As Double Dim normalAxis(2) As Double Dim originPlane(2) As Double Dim sectionCount As Integer Dim pointStart2D(1) As Double Dim pointEnd2D(1) As Double Dim positionSketch(8) As Double Dim pointStart3D(2) As Double Dim pointEnd3D(2) As Double Dim widthSection As Double Dim selectedItems As Selection Dim statusSelection As String Dim countUserSelection As Integer '#####__Instances__#####' Set documentRoot = CATIA.ActiveDocument Set productRoot = documentRoot.Product Set reviewsRoot = productRoot.GetTechnologicalObject("DMUReviews") Set reviewRoot = reviewsRoot.Item(1) Set groupsRoot = productRoot.GetTechnologicalObject("Groups") Set scenesRoot = productRoot.GetTechnologicalObject("ScenesCollection") Set sectionsRoot = productRoot.GetTechnologicalObject("Sections") Set selectedItems = documentRoot.Selection selectedItems.Clear '#####__Create Group__#####' Dim inputObjectType(1) As CATVariant inputObjectType(0) = "Group" inputObjectType(1) = "Product" statusSelection = selectedItems.SelectElement3(inputObjectType, "Product(s) und/oder Group(s), die geschnitten werden sollen, selektieren", false, CATMultiSelTriggWhenUserValidatesSelection, false) If (statusSelection ="Cancel") Then Exit Sub End If countUserSelection = selectedItems.Count Dim i As Integer i = 1 Dim loops As Integer loops = countUserSelection While (i <= loops) If (TypeName(selectedItems.Item(i).Value) = "Group") Then stringGroup = "" If (countUserSelection = 1) Then While ( (stringGroup <> "1") And (stringGroup <> "2") And (stringGroup <> "3") ) stringGroup = InputBox("Sie haben die Bauteilauswahl" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & CHR(9) & selectedItems.Item(i).Value.Name & "." & TypeName(selectedItems.Item(i).Value) & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "ausgewählt" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "1" & Chr(9) & "EXTRAHIEREN" & Chr(13) & Chr(10) & Chr(9) & "Inhalt extrahieren und einer neuen" & Chr(13) & Chr(10) & Chr(9) & "Bauteilauswahl hinzufügen" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "2" & Chr(9) & "INSTANTIIEREN" & Chr(13) & Chr(10) & Chr(9) & "Group direkt in neue Bauteilauswahl" & Chr(13) & Chr(10) & Chr(9) & "hinzufügen, Groups verschachteln" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "3" & Chr(9) & "ÜBERNEHMEN (keine neue Group" & Chr(13) & Chr(10) & Chr(9) & "erstellen) Bauteilauswahl weitere Schnitte" & Chr(13) & Chr(10) & Chr(9) & "hinzufügen" & Chr(13) & Chr(10) & Chr(13) & Chr(10) , "Bauteilauswahl Group", stringGroup) If (stringGroup = "") Then Exit Sub End If WEnd Else While ( (stringGroup <> "1") And (stringGroup <> "2") ) stringGroup = InputBox("Sie haben die Bauteilauswahl" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & CHR(9) & selectedItems.Item(i).Value.Name & "." & TypeName(selectedItems.Item(i).Value) & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "ausgewählt" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "1" & Chr(9) & "EXTRAHIEREN" & Chr(13) & Chr(10) & Chr(9) & "Inhalt extrahieren und einer neuen" & Chr(13) & Chr(10) & Chr(9) & "Bauteilauswahl hinzufügen" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "2" & Chr(9) & "INSTANTIIEREN" & Chr(13) & Chr(10) & Chr(9) & "Group direkt in neue Bauteilauswahl" & Chr(13) & Chr(10) & Chr(9) & "hinzufügen, Groups verschachteln" & Chr(13) & Chr(10) & Chr(13) & Chr(10), "Bauteilauswahl Group", stringGroup) If (stringGroup = "") Then Exit Sub End If WEnd End If If (stringGroup = "1") Then Dim j As Integer For j = 1 To (selectedItems.Item(i).Value.CountExtract) Step 1 selectedItems.Add selectedItems.Item(i).Value.ItemExtract(j) Next selectedItems.Remove(i) End If End If i = i + 1 WEnd If (stringGroup = "3") Then Set groupSelection = selectedItems.Item(1).Value Else stringSelection = InputBox("Geben Sie den Namen für die Bauteilauswahl" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & CHR(9) & "UMGEBUNG" & Chr(9) & "z.B." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "ein.", "Bauteilauswahl" , stringSelection) If (stringSelection = "") Then Exit Sub End If Set groupSelection = groupsRoot.AddFromSel groupSelection.Name = stringSelection groupSelection.ExtractMode = 0 selectedItems.Clear selectedItems.Add groupsRoot.Item(1) '#####__Create Scene__#####' groupSelection.FillSelWithInvert Dim inputObject(0) Set inputObject(0) = productRoot Set sceneInvert = scenesRoot.AddProductScenePartial("Probe", inputObject) Dim u As Integer For u = 1 To selectedItems.Count Step 1 sceneInvert.GetSceneProductData(selectedItems.Item(u).Value).Hidden = True Next selectedItems.Clear End If inputObjectType(0) = "Sketch" inputObjectType(1) = "Plane" selectedItems.Clear statusSelection = selectedItems.SelectElement3(inputObjectType, "Schnittlinie(n) oder Schnittebene(n) selektieren", false, CATMultiSelTriggWhenUserValidatesSelection, false) If (statusSelection ="Cancel") Then Exit Sub End If Dim r As Integer For r = 1 To (selectedItems.Count) Step 1 stringSection = selectedItems.Item(r).Value.Name If (selectedItems.Item(r).Type = "Plane") Then Set sectionSelection = sectionsRoot.Add() sectionSelection.Name = stringSection sectionSelection.CutMode = 0 sectionSelection.Group = groupSelection sectionType = catSectionTypePlane selectedItems.Item(r).Value.GetFirstAxis firstAxis selectedItems.Item(r).Value.GetSecondAxis secondAxis selectedItems.Item(r).Value.GetOrigin originPlane normalAxis(0) = ( firstAxis(1) * secondAxis(2) ) - ( firstAxis(2) * secondAxis(1) ) normalAxis(1) = ( firstAxis(2) * secondAxis(0) ) - ( firstAxis(0) * secondAxis(2) ) normalAxis(2) = ( firstAxis(0) * secondAxis(1) ) - ( firstAxis(1) * secondAxis(0) ) positionSection(0) = firstAxis(0) positionSection(1) = firstAxis(1) positionSection(2) = firstAxis(2) positionSection(3) = secondAxis(0) positionSection(4) = secondAxis(1) positionSection(5) = secondAxis(2) positionSection(6) = normalAxis(0) positionSection(7) = normalAxis(1) positionSection(8) = normalAxis(2) positionSection(9) = originPlane(0) positionSection(10) = originPlane(1) positionSection(11) = originPlane(2) sectionSelection.SetPosition positionSection sectionSelection.Height = 10000 sectionSelection.Width = 10000 sectionSelection.Behavior = catSectionBehaviorFreeze ElseIf (selectedItems.Item(r).Type = "Sketch") Then Dim v As Integer v = 1 sectionCount = 0 Dim t As Integer For t = 1 To (selectedItems.Item(r).Value.GeometricElements.Count) Step 1 If (selectedItems.Item(r).Value.GeometricElements.Item(t).GeometricType = "3") Then If (selectedItems.Item(r).Value.GeometricElements.Item(t).Construction = False) Then sectionCount = sectionCount + 1 End If End If Next For t = 1 To (selectedItems.Item(r).Value.GeometricElements.Count) Step 1 If (selectedItems.Item(r).Value.GeometricElements.Item(t).GeometricType = "3") Then If (selectedItems.Item(r).Value.GeometricElements.Item(t).Construction = False) Then selectedItems.Item(r).Value.GeometricElements.Item(t).StartPoint.GetCoordinates pointStart2D selectedItems.Item(r).Value.GeometricElements.Item(t).EndPoint.GetCoordinates pointEnd2D selectedItems.Item(r).Value.GetAbsoluteAxisData positionSketch pointStart3D(0) = positionSketch(0) + ( positionSketch(3) * pointStart2D(0) ) + ( positionSketch(6) * pointStart2D(1) ) pointStart3D(1) = positionSketch(1) + ( positionSketch(4) * pointStart2D(0) ) + ( positionSketch(7) * pointStart2D(1) ) pointStart3D(2) = positionSketch(2) + ( positionSketch(5) * pointStart2D(0) ) + ( positionSketch(8) * pointStart2D(1) ) pointEnd3D(0) = positionSketch(0) + ( positionSketch(3) * pointEnd2D(0) ) + ( positionSketch(6) * pointEnd2D(1) ) pointEnd3D(1) = positionSketch(1) + ( positionSketch(4) * pointEnd2D(0) ) + ( positionSketch(7) * pointEnd2D(1) ) pointEnd3D(2) = positionSketch(2) + ( positionSketch(5) * pointEnd2D(0) ) + ( positionSketch(8) * pointEnd2D(1) ) widthSection = ( (pointStart3D(0)-pointEnd3D(0))^2 + (pointStart3D(1)-pointEnd3D(1))^2 + (pointStart3D(2)-pointEnd3D(2))^2 ) ^ (1/2) Set sectionSelection = sectionsRoot.Add() If ( (sectionCount > 1) And (v <= sectionCount) ) Then sectionSelection.Name = stringSection & "." & v v = v + 1 Else sectionSelection.Name = stringSection End If sectionSelection.CutMode = 0 sectionSelection.Group = groupSelection sectionType = catSectionTypePlane positionSection(0) = (positionSketch(4)*positionSketch(8)) - (positionSketch(5)*positionSketch(7)) positionSection(1) = (positionSketch(5)*positionSketch(6)) - (positionSketch(3)*positionSketch(8)) positionSection(2) = (positionSketch(3)*positionSketch(7)) - (positionSketch(4)*positionSketch(6)) positionSection(3) = ( pointEnd3D(0) - pointStart3D(0) ) positionSection(4) = ( pointEnd3D(1) - pointStart3D(1) ) positionSection(5) = ( pointEnd3D(2) - pointStart3D(2) ) positionSection(6) = (positionSection(1)*positionSection(5)) - (positionSection(2)*positionSection(4)) positionSection(7) = (positionSection(2)*positionSection(3)) - (positionSection(0)*positionSection(5)) positionSection(8) = (positionSection(0)*positionSection(4)) - (positionSection(1)*positionSection(3)) positionSection(9) = (pointStart3D(0)+pointEnd3D(0)) / 2 positionSection(10) = (pointStart3D(1)+pointEnd3D(1)) / 2 positionSection(11) = (pointStart3D(2)+pointEnd3D(2)) / 2 sectionSelection.SetPosition positionSection sectionSelection.Height = 10000 sectionSelection.Width = widthSection sectionSelection.Behavior = catSectionBehaviorFreeze End If End If Next End If Next End Sub