Code:
Sub catmain()Dim MfgDoc1 As Document
Set MfgDoc1 = CATIA.ActiveDocument
'----------Process-Definition---------------------------------------------
Dim ActivityRef As AnyObject
Set ActivityRef = MfgDoc1.GetItem("Process")
'-------------Setup1-Def,hier auch die ganzen erzeuger-methoden rein,"setPart.."-----------
Dim Setup2 'As ManufacturingSetup
Dim childs As Activities
Dim child As Activity
If (ActivityRef.IsSubTypeOf("PhysicalActivity")) Then
Dim quantity
Set childs = ActivityRef.ChildrenActivities
quantity = childs.Count
If quantity <= 0 Then
Exit Sub
End If
Dim NumberOfSetup
NumberOfSetup = 0
Dim I
For I = 1 To quantity
Set child = childs.Item(I)
If (child.IsSubTypeOf("ManufacturingSetup")) Then
Set Setup2 = child
NumberOfSetup = NumberOfSetup + 1
Exit For
End If
Next
End If
If NumberOfSetup <= 0 Then
Exit Sub
End If
Dim prod2 As Product
Set prod2 = Setup2.GetProductInstance
Dim NC As AnyObject
Dim SG As AnyObject
Dim K As Integer
For K = 1 To prod2.Products.Count
If prod2.Products.Item(K).PartNumber = "Workpiece" Then
Set NC = prod2.Products.Item(K)
End If
Next
Dim L As Integer
For L = 1 To prod2.Products.Count
If prod2.Products.Item(L).PartNumber = "Stock_Geometry" Then
Set SG = prod2.Products.Item(L)
End If
Next
'------------------DesignPart und wichtige elemente herholen-----------------------------
Dim pa As PartDocument
Set pa = NC.ReferenceProduct.Parent
Dim part As part
Set part = pa.part
Dim bod As Bodies
Set bod = part.Bodies
Dim des As AnyObject
Set des = bod.GetItem("heiko")
Dim ebene As AnyObject
Set ebene = des.HybridShapes.GetItem("Oben")
Dim ursprung As AnyObject
Set ursprung = des.HybridShapes.GetItem("Point.1")
Dim myLine As Line
Set myLine = des.HybridShapes.GetItem("Line.1")
'######################################jetzt stock
Dim pa2 As PartDocument
Set pa2 = SG.ReferenceProduct.Parent
Dim part2 As part
Set part2 = pa2.part
Dim bod2 As Bodies
Set bod2 = part2.Bodies
Dim sto As AnyObject
Set sto = bod2.GetItem("PartBody")
'---------------------Setup einrichten--------------------------------
Call Setup2.MachiningAxisSystem.SetOriginPoint(ursprung, NC)
Call Setup2.MachiningAxisSystem.SetOriginZDirection(0, 0, 1)
Call Setup2.CreateMachine("Mfg3AxisMachine")
Call Setup2.Machine.set_DefaultValues
Call Setup2.SetDesignPart(des, NC)
Call Setup2.SetStock(sto, SG)
Call Setup2.SetSafetyPlane(ebene, NC)
Dim mfgprog As ManufacturingProgram
Set mfgprog = Setup2.GetItem("Manufacturing Program.1")
Dim mfgop As ManufacturingOperation
Set mfgop = mfgprog.AppendOperation("M3xHardMaterial", 1)
'--------------schruppOperation einfügen--------------------------
Dim XX As AnyObject
Set XX = Setup2.GetProductInstance
Call mfgop.SetGeometry("Parts", des, XX, 0)
Call mfgop.SetGeometry("RoughStock", sto, XX, 0)
Call mfgop.SetTool("End Mill D10 Rc0")
End Sub