Public Sub ProjectPoints() ' Have the sketch that contains the points selected. Dim sk As PlanarSketch Set sk = ThisApplication.CommandManager.Pick(kSketchObjectFilter, _ "Select the sketch") ' Have the body to project onto selected. Dim body As SurfaceBody Set body = ThisApplication.CommandManager.Pick(kPartBodyFilter, _ "Select the body") ' Get the part component definition. Dim compDef As PartComponentDefinition Set compDef = body.Parent ' *** Determine the side of the solid the sketch is on and if the ' *** sketch is outside the solid. ' Get the normal vector of the selected sketch. Dim skNormal As UnitVector Set skNormal = sk.PlanarEntityGeometry.Normal Dim skRootPoint As Point Set skRootPoint = sk.PlanarEntityGeometry.RootPoint ' Get the corners of the range box. Dim tg As TransientGeometry Set tg = ThisApplication.TransientGeometry Dim cornerPoints(7) As Point Dim range As Box Set range = body.RangeBox Set cornerPoints(0) = range.MinPoint Set cornerPoints(1) = tg.CreatePoint(range.MinPoint.X, range.MinPoint.Y, _ range.MaxPoint.Z) Set cornerPoints(2) = tg.CreatePoint(range.MinPoint.X, range.MaxPoint.Y, _ range.MinPoint.Z) Set cornerPoints(3) = tg.CreatePoint(range.MinPoint.X, range.MaxPoint.Y, _ range.MaxPoint.Z) Set cornerPoints(4) = range.MaxPoint Set cornerPoints(5) = tg.CreatePoint(range.MaxPoint.X, range.MinPoint.Y, _ range.MaxPoint.Z) Set cornerPoints(6) = tg.CreatePoint(range.MaxPoint.X, range.MinPoint.Y, _ range.MinPoint.Z) Set cornerPoints(7) = tg.CreatePoint(range.MaxPoint.X, range.MaxPoint.Y, _ range.MinPoint.Z) ' Construct a matrix where the X axis is along the sketch plane normal. Dim xAxis As Vector Set xAxis = skNormal.AsVector Dim yAxis As Vector Set yAxis = tg.CreateVector(xAxis.X + 1, xAxis.Y + 1, xAxis.Z + 1) Dim zAxis As Vector Set zAxis = xAxis.CrossProduct(yAxis) Set yAxis = zAxis.CrossProduct(xAxis) xAxis.Normalize yAxis.Normalize zAxis.Normalize Dim transform As Matrix Set transform = tg.CreateMatrix Call transform.SetCoordinateSystem(skRootPoint, xAxis, yAxis, zAxis) transform.Invert ' Transform the range box points and compare them to sketch plane. Dim i As Integer Dim smallX As Double For i = 0 To 7 Call cornerPoints(i).TransformBy(transform) If i = 0 Then smallX = cornerPoints(i).X Else If cornerPoints(i).X < smallX Then smallX = cornerPoints(i).X End If End If Next ' Determine the offset needed to position the points outside the solid. Dim offset As Double If smallX < 0 Then offset = -(smallX + 10) Dim tempNormal As Vector Set tempNormal = skNormal.AsVector Call tempNormal.ScaleBy(-1) Set skNormal = tempNormal.AsUnitVector Else offset = 0 End If Dim offsetVector As Vector Set offsetVector = skNormal.AsVector Call offsetVector.ScaleBy(offset) ' *** Perform the intersection calculation of every center point in the sketch. Dim resultPoints As ObjectCollection Set resultPoints = ThisApplication.TransientObjects.CreateObjectCollection Dim skPoint As SketchPoint For Each skPoint In sk.SketchPoints ' Check to see if the point is a center point. If skPoint.HoleCenter Then ' Get the sketch point as a transient 3D point. Dim pnt As Point Set pnt = skPoint.Geometry3d ' Move the point outside the solid. Call pnt.TranslateBy(offsetVector) ' Intersect the point with the solid. Dim foundEnts As ObjectsEnumerator Dim locPoints As ObjectsEnumerator Call body.FindUsingRay(pnt, skNormal, 0.00001, foundEnts, locPoints, True) ' If an intersection was found, add it to the list. If locPoints.Count > 0 Then Call resultPoints.Add(locPoints.Item(1)) End If End If Next ' Prompt the user for which type of output they want. Dim result As String result = InputBox("Enter choice for output:" & vbCrLf & "1 - Work points" & _ vbCrLf & "2 - 3D sketch" & vbCrLf & "3 - csv File", _ "Enter output type", 3) If result = "1" Or result = "2" Then ' Start a transaction so that the creation is grouped in a single undo. Dim trans As Transaction Set trans = ThisApplication.TransactionManager.StartTransaction( _ ThisApplication.ActiveDocument, "Projected Points") If result = "1" Then ' Create work points. For i = 1 To resultPoints.Count Call compDef.WorkPoints.AddFixed(resultPoints.Item(i)) Next End If If result = "2" Then ' Create a 3D sketch and points in the sketch. Dim sk3D As Sketch3D Set sk3D = compDef.Sketches3D.Add() For i = 1 To resultPoints.Count Call sk3D.SketchPoints3D.Add(resultPoints.Item(i)) Next End If trans.End ElseIf result = "3" Then ' Write the points out to a file. x 3.000; MF;y 215.000; MF;z 0.000; ML; z -10; MF; Dim x_offset As Double Dim y_offset As Double Dim z_offset As Double x_offset = 26.5 'update nach verkleben der Matten y_offset = -325.8 z_offset = -76 '84.4 ist niedrigste Z-Koordinate 'z_offset = 0 'debug Dim Sa As Double Sa = 8 'sicherheitsabstand 'erste File ?ffnen und Points zum einstellen erstellen Open "C:\CAD\Points.txt" For Output As #1 Print #1, "/* Programm zur Bedienung der 3-Achs Maschine */ " Print #1, "ML_L = 20; MVPAR; /* ml = langsame Geschwindigkeit setzen*/" Print #1, "MF_F = 40; MVPAR; /* mf = schnelle Geschwindigkeit setzen*/" Dim z_max As Double 'h?chsten z Punkt auslesen z_max = 0 For i = 1 To resultPoints.Count If Abs(resultPoints.Item(i).Z) > Abs(z_max) Then z_max = resultPoints.Item(i).Z 'h?chsten z Punkt auslesen End If Print #1, "x "; Replace(Format(resultPoints.Item(i).X * 10 + x_offset - 3, "0.000"), ",", "."); _ "; MF;y "; Replace(Format(resultPoints.Item(i).Y * 10 + y_offset - 3, "0.000"), ",", "."); _ "; MF;z "; Replace(Format(resultPoints.Item(i).Z * 10 + z_offset, "0.000"), ",", "."); "; ML; z "; Replace(Format(z_offset - Sa, "0.000"), ",", "."); "; MF;" Next Close #1 Dim x_offset2 As Double Dim y_offset2 As Double Dim z_offset2 As Double x_offset2 = 8 y_offset2 = -321.7 z_offset2 = 4 'bei 5 steht die maschine fest: maximal 4 """ start ist bei -16 'zweite File ?ffnen und reset Points erstellen 'zum reset den Zylinder auf h?chste Kerbe stellen (Zylinder weit unten) Open "C:\CAD\Points_reset.txt" For Output As #2 Print #2, "/* Programm zur Bedienung der 3-Achs Maschine */ " Print #2, "ML_L = 20; MVPAR; /* ml = langsame Geschwindigkeit setzen*/" Print #2, "MF_F = 40; MVPAR; /* mf = schnelle Geschwindigkeit setzen*/" For i = 1 To resultPoints.Count If i = 1 Then Print #2, "x "; Replace(Format(resultPoints.Item(i).X * 10 + x_offset2 - 3, "0.000"), ",", "."); _ "; MF;y "; Replace(Format(resultPoints.Item(i).Y * 10 + y_offset2 - 3, "0.000"), ",", "."); _ "; MF;z "; z_offset2; "; ML; z "; Replace(Format(z_offset2 - Sa - z_max * 10, "0.000"), ",", "."); "; MF;" 'offset ist auf 22 unterm Fleximould ElseIf i + 1 = 1981 Then Print #2, "x "; Replace(Format(resultPoints.Item(i).X * 10 + x_offset2 - 3, "0.000"), ",", "."); _ "; MF;y "; Replace(Format(resultPoints.Item(i).Y * 10 + y_offset2 - 3, "0.000"), ",", "."); _ "; MF;z "; z_offset2; "; ML; z "; Replace(Format(z_offset2 - 4 - z_max * 10, "0.000"), ",", "."); "; MF;" 'offset ist auf 22 unterm Fleximould Else i_mirror = resultPoints.Count - 36 + (i + 1) + Round((((i + 1) - 1) / 36 - 0.499999999), 0) * -72 Print #2, "x "; Replace(Format(resultPoints.Item(i).X * 10 + x_offset2 - 3, "0.000"), ",", "."); _ "; MF;y "; Replace(Format(resultPoints.Item(i).Y * 10 + y_offset2 - 3, "0.000"), ",", "."); _ "; MF;z "; z_offset2; "; ML; z "; Replace(Format(z_offset2 - 4 - resultPoints.Item(i_mirror).Z * 10, "0.000"), ",", "."); "; MF;" End If Next Close #2 'Open "C:\CAD\Points_testtiiiii.txt" For Output As #3 'For i = 1 To resultPoints.Count '(i+1) = resultPoints.Count - 36 + (i+1) + Round((((i+1) - 1) / 36 - 0.499999999), 0) * -72 ' Print #3, i, resultPoints.Count - 36 + i + Round(((i - 1) / 36 - 0.499999999), 0) * -72, i / 37, Round(((i - 1) / 36 - 0.499999999), 0) * -72, resultPoints.Count - 36 + (i - 1) + Round((((i - 1) - 1) / 36 - 0.499999999), 0) * -72 ' Next 'Close #3 'test1 = resultPoints.Count - 36 + i + RoundDown(i / 37, 0) * -72 MsgBox "File written to ""C:\CAD\Points.csv""" Else MsgBox "Invalid Input" End If End Sub