Code:
Private Function fctPunktErzeugen(ByVal p_dblX As Double, ByVal p_dblY As Double, ByVal p_dblZ As Double, ByVal p_strPunktname As String, ByRef p_strGeoSetInfos As String, p_dblFIPunktDurchmesser As Double) As String
'Diese Funktion erstellt einen Punkt sowie eine Hüllgeometrie.
'Übergabewerte sind die Punktkoordinaten sowie Name und GeoSetInfos
'Rückgabewert ist der Pfad der erstellten CATIA-Datei, welche den Punkt enthält'Errorhandling
Dim strErrObj As String, strErrFct As String, strErrMsg As String, strErrArr(10) As Variant
strErrObj = ""
strErrFct = "fctPunktErzeugen"
strErrMsg = ""
On Error GoTo ErrorFct:
Dim objPart As Part
Dim objPartDoc As PartDocument
Dim partDoc As PartDocument
Dim PartProduct As Product
Dim newPoint 'As HybridShapePointCoord
Dim hsfShape 'As HybridShapeFactory
Dim hbBody As HybridBody
Dim hbBodies As HybridBodies
Dim newSphere 'As HybridShapeSphere
Dim refReference_1 'As Reference
Dim refReference_2 'As Reference
Dim asAxisSystems As AxisSystems
Dim asAxSystem
Dim strSpeicherPfad As String
Set objPartDoc = docDocuments.add("Part")
Set partDoc = CATIA.ActiveDocument
Set PartProduct = partDoc.GetItem(1)
Set objPart = partDoc.Part
Set hbBodies = objPart.HybridBodies
Set hsfShape = objPart.HybridShapeFactory
Set hbBody = hbBodies.add
'Punkt erstellen
Set newPoint = hsfShape.AddNewPointCoord(p_dblX, p_dblY, p_dblZ)
newPoint.Name = p_strPunktname
hbBody.AppendHybridShape newPoint
'Hüllfläche erstellen
Set asAxisSystems = objPart.AxisSystems
Set asAxSystem = asAxisSystems.Item("Absolute Axis System")
Set refReference_1 = objPart.CreateReferenceFromObject(newPoint)
Set refReference_2 = objPart.CreateReferenceFromObject(asAxSystem)
Set newSphere = hsfShape.AddNewSphere(refReference_1, refReference_2, p_dblFIPunktDurchmesser / 2, -360, 360, 0, 360)
newSphere.Name = "Sphere of " & p_strPunktname
hbBody.AppendHybridShape newSphere
hbBody.Name = newPoint.Name
hbBody.Name = p_strGeoSetInfos
objPart.Update
strSpeicherPfad = "C:\Users\d2aantd\Desktop\CATIA_Zwischenspeicher\" & p_strPunktname
CATIA.DisplayFileAlerts = False
objPartDoc.ExportData strSpeicherPfad & ".cgr", "cgr"
objPartDoc.Close
CATIA.DisplayFileAlerts = True
fctPunktErzeugen = strSpeicherPfad & ".cgr"
strSpeicherPfad = ""
ExitFct:
Set objPartDoc = Nothing
Set partDoc = Nothing
Set PartProduct = Nothing
Set objPart = Nothing
Set hbBodies = Nothing
Set hsfShape = Nothing
Set hbBody = Nothing
Set asAxisSystems = Nothing
Set asAxSystem = Nothing
Set refReference_2 = Nothing
Set newPoint = Nothing
Set refReference_1 = Nothing
Set newSphere = Nothing
Exit Function
' Fehlerbehandlung
ErrorFct:
If mbldebug Or gbldebug Then
Call subFehlerbehandlung(mbldebug, gbldebug, strErrObj, strErrFct, strErrMsg, strErrArr): Call fctErrorHandler(Err.Number, strErrObj, strErrFct, strErrMsg, strErrArr(), , , , , 1): Stop
Resume
End If
Select Case fctErrorHandler(Err.Number, strErrObj, strErrFct, strErrMsg, strErrArr(), , , , , 2)
Case vbRetry
Resume
Case vbIgnore
Resume Next
Case Else
Resume ExitFct:
End Select
End Function