Public Class Form1





    Private Sub Button1_Click(ByVal sender As System.Object, ByVal ee As System.EventArgs) Handles Button1.Click

        Dim CATIA As INFITF.Application
        Dim MyDoc As Document
        Dim d1(8) As Object
        Dim point2df(100) As Point2D
        Dim line2df(100) As Line2D
        Dim e As Integer
        Dim laengea As Integer
        Dim laengeh1 As Integer
        Dim laenkek As Integer
        Dim documents1 As Documents
        Dim partDocument1 As Document
        Dim part1 As Part
        Dim st1Name As Integer
        Dim st2name As Integer
        Dim version As String
        Dim Makroname As String
        Dim arrayOfVariantOfDouble1(8)
        Dim laenge As Integer
        Dim Kantenlaenge As Integer
        Dim st3name As Integer
        Dim parameters1 As Parameters
        Dim length1 As Dimension
        Dim parameters2 As Parameters
        Dim length2 As Dimension
        Dim Radius As Integer
        Dim parameters3 As Parameters
        Dim length3 As Dimension
        Dim bodies1 As Bodies
        Dim body1 As Body
        Dim sketches1 As Sketches
        Dim reference1 As Reference
        Dim sketch1 As Sketch
        Dim factory2D1 As Factory2D
        Dim geometricElements1 As GeometricElements
        Dim axis2D1 As GeometricElement
        Dim line2D1 As CATBaseDispatch
        Dim line2D2 As CATBaseDispatch
        Dim point2D1 As Point2D
        Dim point2D2 As Point2D
        Dim point2D3 As Point2D
        Dim point2D4 As Point2D
        Dim point2D5 As Point2D
        Dim point2D6 As Point2D
        Dim point2D7 As Point2D
        Dim line2D3 As Line2D
        Dim line2D4 As Line2D
        Dim line2D5 As Line2D
        Dim line2D6 As Line2D
        Dim line2D7 As Line2D
        Dim line2D8 As Line2D
        Dim line2D9 As Line2D
        Dim point2D8 As CATBaseDispatch
        Dim constraints1 As Constraints
        Dim reference2 As Reference
        Dim constraint1 As Constraint
        Dim reference3 As Reference
        Dim constraint2 As Constraint
        Dim reference4 As Reference
        Dim constraint3 As Constraint
        Dim reference5 As Reference
        Dim constraint4 As Constraint
        Dim reference6 As Reference
        Dim constraint5 As Constraint
        Dim reference7 As Reference
        Dim constraint6 As Constraint
        Dim reference8 As Reference
        Dim sketch2 As Sketch
        Dim arrayOfVariantOfDouble2(8)
        Dim factory2D2 As Factory2D
        Dim geometricElements2 As GeometricElements
        Dim axis2D2 As GeometricElement
        Dim line2D10 As CATBaseDispatch
        Dim line2D11 As CATBaseDispatch
        Dim circle2D1 As Circle2D
        Dim constraints2 As Constraints
        Dim reference9 As Reference
        Dim constraint7 As Constraint
        Dim shapeFactory1 As Factory
        Dim reference10 As Reference
        Dim pad1 As Pad
        Dim reference11 As Reference
        Dim reference12 As Reference
        Dim pad2 As Pad
        Dim reference13 As Reference
        Dim relations1 As Relations
        Dim limit1 As Limit
        Dim length4 As Length
        Dim formula1 As Formula
        Dim catCStTypeLength As CatConstraintType
        Dim catCstModeDrivingDimension As CatConstraintMode
        Dim catCstTypeRadius As CatConstraintType



        Try
            CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
        Catch ex As System.Runtime.InteropServices.COMException
            MessageBox.Show("Catia nicht gefunden!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End
        End Try

        Try
            MyDoc = CATIA.Documents.Add("Part")
        Catch ex As Exception
            MessageBox.Show("Datei-Öffnen Fehler!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End
        End Try




        partDocument1 = CATIA.ActiveDocument


        part1 = partDocument1.Part


        parameters1 = part1.Parameters


        length1 = parameters1.CreateDimension("", "LENGTH", 0.0)

        length1.Rename("Kantenlaenge")

        Do
            st1Name = InputBox("Geben sie eine Mass für die Kantenlaenge zwischen 25 und 35 ein!", "Name der Werkzeugkomponente", 35)
            If st1Name = "" Then
                MsgBox("Es wurde kein Mass eingegeben!", 16, Makroname + " " + version)
                'Exit Sub
            End If

        Loop While st1Name = ""

        length1.RangeMin = 0.0

        length1.RangeMin = 25.0

        length1.RangeMin = 25.0

        length1.RangeMax = 35.0

        length1.Value = st1Name
        Kantenlaenge = length1.Value
        MsgBox(Kantenlaenge)




        part1.Update()


        parameters2 = part1.Parameters


        length2 = parameters2.CreateDimension("", "LENGTH", 0.0)

        length2.Rename("laenge")



        Do
            st2Name = InputBox("Geben sie eine Mass für die laenge zwischen 65 und 100 ein!", "Name der Werkzeugkomponente", 100)
            If st2Name = "" Then
                MsgBox("Es wurde kein Mass eingegeben!", 16, Makroname + " " + version)
                'Exit Sub
            End If

        Loop While st2Name = ""

        length2.RangeMin = 0.0

        length2.RangeMin = 65.0

        length2.RangeMin = 65.0

        length2.RangeMax = 100.0

        length2.Value = st2Name
        laenge = length2.Value
        MsgBox(laenge)






        parameters3 = part1.Parameters


        length3 = parameters3.CreateDimension("", "LENGTH", 0.0)

        length3.Rename("Radius")



        Do
            st3Name = InputBox("Geben sie eine Mass für den Radius zwischen 10 und 20 ein!", "Name der Werkzeugkomponente", 20)
            If st3Name = "" Then
                MsgBox("Es wurde kein Mass eingegeben!", 16, Makroname + " " + version)
                'Exit Sub
            End If

        Loop While st3Name = ""

        length3.RangeMin = 0.0

        length3.RangeMin = 10.0

        length3.RangeMin = 10.0

        length3.RangeMax = 20.0

        length3.Value = st3Name
        laenge = length3.Value
        MsgBox(Radius)






        bodies1 = part1.Bodies


        body1 = bodies1.Item("Hauptkörper")


        sketches1 = body1.Sketches


        reference1 = part1.CreateReferenceFromName("Selection_RSur:(Face:(Brp:(AxisSystem.1;1);None:();Cf11:());AxisSystem.1;Z0;G2388)")


        sketch1 = sketches1.Add(reference1)


        arrayOfVariantOfDouble1(0) = 0.0
        arrayOfVariantOfDouble1(1) = 0.0
        arrayOfVariantOfDouble1(2) = 0.0
        arrayOfVariantOfDouble1(3) = 1.0
        arrayOfVariantOfDouble1(4) = 0.0
        arrayOfVariantOfDouble1(5) = 0.0
        arrayOfVariantOfDouble1(6) = 0.0
        arrayOfVariantOfDouble1(7) = 1.0
        arrayOfVariantOfDouble1(8) = 0.0
        sketch1.SetAbsoluteAxisData(arrayOfVariantOfDouble1)

        part1.InWorkObject = sketch1


        factory2D1 = sketch1.OpenEdition()


        geometricElements1 = sketch1.GeometricElements


        axis2D1 = geometricElements1.Item("Absolute Achse")


        line2D1 = axis2D1.GetItem("H-Richtung")

        line2D1.ReportName = 1


        line2D2 = axis2D1.GetItem("V-Richtung")

        line2D2.ReportName = 2


        point2D1 = factory2D1.CreatePoint(32.253101, -16.378663)

        point2D1.ReportName = 3


        point2D2 = factory2D1.CreatePoint(32.253101, 18.621337)

        point2D2.ReportName = 4


        point2D3 = factory2D1.CreatePoint(1.942212, 36.121337)

        point2D3.ReportName = 5


        point2D4 = factory2D1.CreatePoint(-28.368677, 18.621337)

        point2D4.ReportName = 6


        point2D5 = factory2D1.CreatePoint(-28.368677, -16.378663)

        point2D5.ReportName = 7


        point2D6 = factory2D1.CreatePoint(1.942212, -33.878663)

        point2D6.ReportName = 8


        point2D7 = factory2D1.CreatePoint(28.368677, 0.0)

        point2D7.ReportName = 9


        line2D3 = factory2D1.CreateLine(32.253101, -16.378663, 32.253101, 18.621337)

        line2D3.ReportName = 10

        line2D3.StartPoint = point2D1

        line2D3.EndPoint = point2D2


        line2D4 = factory2D1.CreateLine(32.253101, 18.621337, 1.942212, 36.121337)

        line2D4.ReportName = 11

        line2D4.StartPoint = point2D2

        line2D4.EndPoint = point2D3


        line2D5 = factory2D1.CreateLine(1.942212, 36.121337, -28.368677, 18.621337)

        line2D5.ReportName = 12

        line2D5.StartPoint = point2D3

        line2D5.EndPoint = point2D4


        line2D6 = factory2D1.CreateLine(-28.368677, 18.621337, -28.368677, -16.378663)

        line2D6.ReportName = 13

        line2D6.StartPoint = point2D4

        line2D6.EndPoint = point2D5


        line2D7 = factory2D1.CreateLine(-28.368677, -16.378663, 1.942212, -33.878663)

        line2D7.ReportName = 14

        line2D7.StartPoint = point2D5

        line2D7.EndPoint = point2D6


        line2D8 = factory2D1.CreateLine(1.942212, -33.878663, 32.253101, -16.378663)

        line2D8.ReportName = 15

        line2D8.StartPoint = point2D6

        line2D8.EndPoint = point2D1


        line2D9 = factory2D1.CreateLine(0.0, 0.0, 28.368677, 0.0)

        line2D9.ReportName = 16

        line2D9.Construction = True


        point2D8 = axis2D1.GetItem("Ursprung")

        line2D9.StartPoint = point2D8

        line2D9.EndPoint = point2D7


        constraints1 = sketch1.Constraints


        reference2 = part1.CreateReferenceFromObject(line2D4)


        constraint1 = constraints1.AddMonoEltCst(catCstTypeLength, reference2)

        constraint1.Mode = catCstModeDrivingDimension


        reference3 = part1.CreateReferenceFromObject(line2D3)


        constraint2 = constraints1.AddMonoEltCst(catCstTypeLength, reference3)

        constraint2.Mode = catCstModeDrivingDimension


        reference4 = part1.CreateReferenceFromObject(line2D8)


        constraint3 = constraints1.AddMonoEltCst(catCstTypeLength, reference4)

        constraint3.Mode = catCstModeDrivingDimension


        reference5 = part1.CreateReferenceFromObject(line2D7)


        constraint4 = constraints1.AddMonoEltCst(catCstTypeLength, reference5)

        constraint4.Mode = catCstModeDrivingDimension


        reference6 = part1.CreateReferenceFromObject(line2D6)


        constraint5 = constraints1.AddMonoEltCst(catCstTypeLength, reference6)

        constraint5.Mode = catCstModeDrivingDimension


        reference7 = part1.CreateReferenceFromObject(line2D5)


        constraint6 = constraints1.AddMonoEltCst(catCstTypeLength, reference7)

        constraint6.Mode = catCstModeDrivingDimension

        sketch1.CloseEdition()

        part1.InWorkObject = body1

        part1.Update()


        reference8 = part1.CreateReferenceFromName("Selection_RSur:(Face:(Brp:(AxisSystem.1;1);None:();Cf11:());AxisSystem.1;Z0;G2388)")


        sketch2 = sketches1.Add(reference8)


        arrayOfVariantOfDouble2(0) = 0.0
        arrayOfVariantOfDouble2(1) = 0.0
        arrayOfVariantOfDouble2(2) = 0.0
        arrayOfVariantOfDouble2(3) = 1.0
        arrayOfVariantOfDouble2(4) = 0.0
        arrayOfVariantOfDouble2(5) = 0.0
        arrayOfVariantOfDouble2(6) = 0.0
        arrayOfVariantOfDouble2(7) = 1.0
        arrayOfVariantOfDouble2(8) = 0.0
        sketch2.SetAbsoluteAxisData(arrayOfVariantOfDouble2)

        part1.InWorkObject = sketch2


        factory2D2 = sketch2.OpenEdition()


        geometricElements2 = sketch2.GeometricElements


        axis2D2 = geometricElements2.Item("Absolute Achse")


        line2D10 = axis2D2.GetItem("H-Richtung")

        line2D10.ReportName = 1


        line2D11 = axis2D2.GetItem("V-Richtung")

        line2D11.ReportName = 2


        circle2D1 = factory2D2.CreateClosedCircle(0.0, 0.0, 20.0)

        circle2D1.ReportName = 3


        constraints2 = sketch2.Constraints


        reference9 = part1.CreateReferenceFromObject(circle2D1)


        constraint7 = constraints2.AddMonoEltCst(catCstTypeRadius, reference9)

        constraint7.Mode = catCstModeDrivingDimension

        sketch2.CloseEdition()

        part1.InWorkObject = body1

        part1.Update()

        part1.InWorkObject = body1


        shapeFactory1 = part1.ShapeFactory


        reference10 = part1.CreateReferenceFromName("")


        pad1 = shapeFactory1.AddNewPadFromRef(reference10, 20.0)


        reference11 = part1.CreateReferenceFromObject(sketch1)

        pad1.SetProfileElement(reference11)

        part1.Update()


        reference12 = part1.CreateReferenceFromName("")


        pad2 = shapeFactory1.AddNewPadFromRef(reference12, 20.0)


        reference13 = part1.CreateReferenceFromObject(sketch2)

        pad2.SetProfileElement(reference13)


        relations1 = part1.Relations


        limit1 = pad2.FirstLimit


        length4 = limit1.Dimension


        formula1 = relations1.CreateFormula("Formel.8", "", length4, "laenge ")

        formula1.Rename("Formel.8")

        part1.Update()

    End Sub



  
End Class