Article Directory
foreword
The 3D model (.prt) drawn by myself on UG adds a point set on the boundary to get dense points on the boundary, and then saves it as an .IGS file to obtain the 3D coordinate information of the boundary point set on the model, and write a program to read all point coordinates.
Reference: Batch export the points in UG and get their three-dimensional coordinates
1. Add point set to 3D model
First, draw a 3D model in UG (the author UG10.0).
Open the point set function: Menu—Insert—Datum/Point——Point Set, or the point set shortcut button under the curve.
In the point set interface, set the number of points according to the requirement, and then select a line to add the point set to. The example sets the number of points to 5000, and the side pointed by the red arrow is the boundary line that the author chooses to add the point set.
After the boundary line is selected, the points have been added, and they are small green balls when zoomed in.
After clicking Apply, the newly added green points are very dense, and the overall view is a green border line.
After clicking Apply above, if the points do not change, you can directly click the next line, and then continue to click Apply, or after changing the points, select other lines, and each time you select a line, you must click "Apply" and then select the next one, otherwise there will be a warning, use the above steps to add the remaining border lines to the point set.
2. Save as .IGS file
All components except point sets are hidden.
File - Save - Save As, select IGES file (*.igs) as the save type, and two files (.log and .igs) will be obtained after saving. The .log has the total number of points for the file.
.igs files can be opened with Notepad. In this file, the line starting with "116," is the line where the point coordinates are located. The first comma immediately following "116," is the X coordinate, the second comma is the Y coordinate, and the third comma is the Z coordinate.
For example, the number on the blue background in the figure above starts with "116," and this line is the information line of a point whose three-dimensional coordinates are (0.0400080016003201, 0.0, 3.0).
3. The program reads the three-dimensional coordinates of each point
According to the content of the .igs file, the target information to be read is: the line starting with "116," and only the value within the three commas after "116," needs to be left.
import numpy as np
file = "E:/panel-dataset/cap_2/cap_2.igs"
IGS_file = open(file, 'r')
IGS_lines = IGS_file.readlines()
temp2 = []
# print(IGS_lines)
for line in IGS_lines:
if line[:4] == "116,":
temp1 = line.split(',')
temp2.append(temp1[1:4])
L = len(temp2)
point = np.zeros((L, 3), np.float32)
for i in range(len(temp2)):
point[i, 0] = float(temp2[i][0])
point[i, 1] = float(temp2[i][1])
point[i, 2] = float(temp2[i][2])
# print(point)
np.savetxt('cap_2_point.txt', point)
After getting the point set added to the 3D model, the 3D coordinate TXT file of all points, drag the TXT file to CC to view and verify.
appendix
You can also use the welding point command method in UG to obtain the three-dimensional coordinates of the point set on the boundary line:
NX software: export robot welding point coordinate data to CSV format file operation method
Note: use the welding point wizard command in this method requires UG12.0 version or above.