GBH 发表于 2023-6-6 16:16:00

如何直接用VScode运行生成一个模型文件?

请问Python代码如何操作UG建模呀?直接用VScode运行会报错,比如下面这段代码我这里已经有NXOpen了,但是还是在第一行报错,问了ChatGPT,说得用UG里面的“菜单”>“执行”,但是我也没找到能运行Python脚本的选项,能不能直接用VScode运行生成一个三维模型啊?有没有大神能解答一下
import NXOpen

# 创建一个新的UG会话
theSession = NXOpen.Session.GetSession()

# 获取当前工作部件
workPart = theSession.Parts.Work

# 创建一个新的坐标系
coordinateSystemBuilder = workPart.CoordinateSystems.CreateCoordinateSystemBuilder(NXOpen.CoordinateSystem.Null)
coordinateSystemBuilder.Origin.SetValue(0.0, 0.0, 0.0)
coordinateSystem = coordinateSystemBuilder.Commit()

# 创建一个新的点
pointBuilder = workPart.Points.CreatePointBuilder(NXOpen.Point.Null)
pointBuilder.CoordinateSystem.SetValue(coordinateSystem)
pointBuilder.PointType = NXOpen.Point.PointTypes.Point
pointBuilder.Point.SetValue(1.0, 2.0, 3.0)
point = pointBuilder.Commit()

# 创建一个新的直线
lineBuilder = workPart.Curves.CreateLineBuilder(NXOpen.Line.Null)
lineBuilder.CoordinateSystem.SetValue(coordinateSystem)
lineBuilder.StartPoint.SetValue(point)
lineBuilder.EndPoint.SetValue(4.0, 5.0, 6.0)
line = lineBuilder.Commit()

# 创建一个新的圆柱体
cylinderBuilder = workPart.Features.CreateCylinderBuilder(NXOpen.Features.Cylinder.Null)
cylinderBuilder.CoordinateSystem.SetValue(coordinateSystem)
cylinderBuilder.StartFace.SetValue(line)
cylinderBuilder.Height.ExplicitValue = 10.0
cylinderBuilder.Radius.ExplicitValue = 2.0
cylinder = cylinderBuilder.Commit()

# 更新显示
workPart.ModelingViews.WorkView.Fit()

# 保存模型
outputFile = "D:\\BaiduSyncdisk\\AAAAAAA_yanyi_xia\\程序\\UGAPI.prt"
workPart.SaveAs(outputFile)

页: [1]
查看完整版本: 如何直接用VScode运行生成一个模型文件?