update know

This commit is contained in:
JackLee 2025-02-22 15:42:21 +08:00
parent 531b6957e6
commit c75953ef62
27 changed files with 4564907 additions and 126386 deletions

View File

@ -0,0 +1,10 @@
# NX Version:NX 2412
# Email:809262979@qq.com
# python .py created by deepseek
import NXOpen
# 获取当前会话
session = NXOpen.Session.GetSession()
# 打开列表窗口用于输出信息
lw = session.ListingWindow
lw.Open()
lw.WriteLine(f"")

View File

@ -1,7 +0,0 @@
数值和坐标点采用双精度数值类型
Create类型的函数第一个参数不能为None
以下函数第一个参数不能为None
创建坐标系的时候CreateGeometryWithUserName:第一参数为group_geometry对象
创建几何体的时候CreateGeometryWithUserName:第一参数为坐标系对象
创建刀具的时候CreateToolWithUserName:第一参数为generic_machine对象
创建工序的时候CreateWithUserName:第一参数为NC_PROGRAM父级对象

View File

@ -0,0 +1,451 @@
# NX Version:NX 2412
# Email:809262979@qq.com
# python .py created by deepseek
import math
import NXOpen
import NXOpen.CAM
import NXOpen.Features
import NXOpen.SIM
# ----------------------------------------------
# 初始化CAM Session
# ----------------------------------------------
def init_cam():
session = NXOpen.Session.GetSession()
session.ApplicationSwitchImmediate("UG_APP_MANUFACTURING")
session.IsCamSessionInitialized()
return session
# ----------------------------------------------
# 初始化CAM WorkPart
# ----------------------------------------------
def init_workpart(arg_session):
workpart = arg_session.Parts.Work
return workpart
# ----------------------------------------------
# 初始化GENERIC_MACHINE父级
# ----------------------------------------------
def init_parent_generic_machine(arg_workpart):
temp_machine = arg_workpart.CAMSetup.CAMGroupCollection.FindObject("GENERIC_MACHINE")
return temp_machine
# ----------------------------------------------
# 初始化GEOMETRY父级
# ----------------------------------------------
def init_parent_geometry(arg_workpart):
temp_geometry = arg_workpart.CAMSetup.CAMGroupCollection.FindObject("GEOMETRY")
return temp_geometry
# ----------------------------------------------
# 初始化方法组父级
# ----------------------------------------------
def init_parent_nc_method(arg_workpart):
temp_method = arg_workpart.CAMSetup.CAMGroupCollection.FindObject("METHOD")
return temp_method
# ----------------------------------------------
# 初始化方法组父级
# ----------------------------------------------
def init_parent_nc_program(arg_workpart):
temp_nc_program = arg_workpart.CAMSetup.CAMGroupCollection.FindObject("NC_PROGRAM")
return temp_nc_program
# ----------------------------------------------
# 初始化加工模板
# ----------------------------------------------
def init_template_name():
temp_template_name="mill_contour"
return temp_template_name
# ----------------------------------------------
# 初始化刀具
# ----------------------------------------------
def create_tool(arg_workpart,arg_machine,arg_template_name,arg_tool_name,arg_tool_diameter):
#先用FindObject函数通过arg_tool_name查找刀具对象是否存在,
#如果FindObject查找的对象不存在则创建
#这里建议使用Try容错处理
temp_tool = None
try:
#查找刀具对象
temp_tool = arg_workpart.CAMSetup.CAMGroupCollection.FindObject(arg_tool_name)
except Exception as e:
#创建刀具对象
tool_group = arg_workpart.CAMSetup.CAMGroupCollection.CreateToolWithUserName(arg_machine, arg_template_name, "MILL", NXOpen.CAM.NCGroupCollection.UseDefaultName.TrueValue, "MILL", "Mill")
millToolBuilder = arg_workpart.CAMSetup.CAMGroupCollection.CreateMillToolBuilder(tool_group)
#设定刀具半径
millToolBuilder.TlDiameterBuilder.Value = arg_tool_diameter
temp_tool = millToolBuilder.Commit()
millToolBuilder.Destroy()
return temp_tool
# ----------------------------------------------
# 初始化加工坐标系
# ----------------------------------------------
def create_mcs(arg_workpart,arg_geometry,arg_template_name,arg_mcs_name):
#先用FindObject函数通过arg_mcs_name查找刀具对象是否存在,
#如果FindObject查找的对象不存在则创建
#这里建议使用Try容错处理
temp_mcs=None
try:
#通过arg_mcs_name查找坐标系对象
temp_mcs = arg_workpart.CAMSetup.CAMGroupCollection.FindObject(arg_mcs_name,NXOpen.CAM.CAMGroup.CAMGroupType.MachineCoordinateSystem)
except Exception as e:#查找对象错误则转到创建mcs坐标系对象
#创建mcs坐标系对象
orient_geometry = arg_workpart.CAMSetup.CAMGroupCollection.CreateGeometryWithUserName(arg_geometry, arg_template_name, "MCS", NXOpen.CAM.NCGroupCollection.UseDefaultName.TrueValue, arg_mcs_name, "MCS")
millOrientBuilder = arg_workpart.CAMSetup.CAMGroupCollection.CreateMillOrientGeomBuilder(orient_geometry)
millOrientBuilder.GetCsysPurposeMode()
millOrientBuilder.GetSpecialOutputMode()
millOrientBuilder.GetToolAxisMode()
unit1 = arg_workpart.UnitCollection.FindObject("MilliMeter")
millOrientBuilder.GetLowerLimitMode()
millOrientBuilder.TransferClearanceBuilder.SafeDistance = 10.0 #安全高度
arg_workpart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
temp_mcs = millOrientBuilder.Commit()
millOrientBuilder.Destroy()
return temp_mcs
# ----------------------------------------------
# 创建几何体
# ----------------------------------------------
def create_cam_feature(arg_workpart,arg_mcs,arg_template_name):
feature_geometry = arg_workpart.CAMSetup.CAMGroupCollection.CreateGeometryWithUserName(arg_mcs, arg_template_name, "WORKPIECE", NXOpen.CAM.NCGroupCollection.UseDefaultName.TrueValue, "WORKPIECE", "Workpiece")
feature_mill_geom_builder = arg_workpart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(feature_geometry)
feature_mill_geom_builder.PartGeometry.InitializeData(False)
geometrySetList = feature_mill_geom_builder.PartGeometry.GeometryList
taggedObject = geometrySetList.FindItem(0)
geometrySet = taggedObject
partLoadStatus = arg_workpart.LoadThisPartFully()
partLoadStatus.Dispose()
selectionIntentRuleOptions = arg_workpart.ScRuleFactory.CreateRuleOptions()
selectionIntentRuleOptions.SetSelectedFromInactive(False)
bodies1 = [NXOpen.Body.Null] * 1
body = arg_workpart.Bodies.FindObject("UNPARAMETERIZED_FEATURE(1)")
bodies1[0] = body
bodyDumbRule1 = arg_workpart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True, selectionIntentRuleOptions)
selectionIntentRuleOptions.Dispose()
scCollector = geometrySet.ScCollector
rules1 = [None] * 1
rules1[0] = bodyDumbRule1
scCollector.ReplaceRules(rules1, False)
feature = feature_mill_geom_builder.Commit()
feature_mill_geom_builder.Destroy()
return feature,body
# ----------------------------------------------
# 创建毛坯
# ----------------------------------------------
def create_block_feature(arg_workpart,arg_cam_feature,arg_body):
block_mill_geom_builder = arg_workpart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(arg_cam_feature)
block_mill_geom_builder.BlankGeometry.InitializeData(False)
block_mill_geom_builder.BlankGeometry.GeometryList
block_mill_geom_builder.BlankGeometry.BlankIpwMultipleSource.SetList
block_mill_geom_builder.BlankGeometry.BlankDefinitionType = NXOpen.CAM.GeometryGroup.BlankDefinitionTypes.AutoBlock
toolingBoxBuilder1 = arg_workpart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(NXOpen.Features.ToolingBox.Null)
selections1 = [NXOpen.NXObject.Null] * 1
selections1[0] = arg_body
deselections1 = []
toolingBoxBuilder1.SetSelectedOccurrences(selections1, deselections1)
toolingBoxBuilder1.OffsetPositiveZ
temp_block_geom = block_mill_geom_builder.Commit()
block_mill_geom_builder.Destroy()
millGeomBuilder3 = arg_workpart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(temp_block_geom)
block_feature = millGeomBuilder3.Commit()
millGeomBuilder3.Destroy()
return block_feature
# ----------------------------------------------
# 创建工序
# ----------------------------------------------
def cam_program(arg_workpart,arg_nc_program,arg_method,arg_tool,arg_feature,arg_template_name):
operation = arg_workpart.CAMSetup.CAMOperationCollection.CreateWithUserName(nc_program, method, tool, block_feature, template_name, "CAVITY_MILL", NXOpen.CAM.OperationCollection.UseDefaultName.TrueValue, "CAVITY_MILL", "Cavity Mill")
cavityMilling = operation
cavityMillingBuilder = arg_workpart.CAMSetup.CAMOperationCollection.CreateCavityMillingBuilder(cavityMilling)
cavityMillingBuilder.CutLevel.InitializeData()
# 切削参数
cavityMillingBuilder.CutLevel.GlobalDepthPerCut.DistanceBuilder.Value = 0.5
cavityMillingBuilder.CutLevel.ApplyGlobalDepthPerCut()
cavityMillingBuilder.CutPattern.CutPattern = NXOpen.CAM.CutPatternBuilder.Types.FollowPeriphery
cavityMillingBuilder.CutParameters.PatternDirection = NXOpen.CAM.CutParametersPatternDirectionTypes.Inward
cavityMillingBuilder.NonCuttingBuilder.TransferAvoidanceFromBuilder.ToolAxis = NXOpen.Direction.Null
cavityMillingBuilder.NonCuttingBuilder.TransferAvoidanceGohomeBuilder.ToolAxis = NXOpen.Direction.Null
cavityMillingBuilder.NonCuttingBuilder.EngageOpenAreaBuilder.Vector = NXOpen.Direction.Null
cavityMillingBuilder.NonCuttingBuilder.ClearanceBuilder.AxisObject = NXOpen.Direction.Null
cavityMillingBuilder.CutParameters.CutOrder = NXOpen.CAM.CutParametersCutOrderTypes.DepthFirst
cavityMillingBuilder.CutParameters.PartStock.Value = 0.14999999999999999
cavityMillingBuilder.FeedsBuilder.SpindleRpmBuilder.Value = 5000.0
cavityMillingBuilder.NonCuttingBuilder.RetractAreaBuilder.Vector = NXOpen.Direction.Null
cavityMillingBuilder.NonCuttingBuilder.RetractFinalBuilder.Vector = NXOpen.Direction.Null
cavityMillingBuilder.FeedsBuilder.RecalculateData(NXOpen.CAM.FeedsBuilder.RecalculateBasedOn.SpindleSpeed)
cavityMillingBuilder.NonCuttingBuilder.EngageOpenAreaBuilder.EngRetType = NXOpen.CAM.NcmPlanarEngRetBuilder.EngRetTypes.Linear
nXObject6 = cavityMillingBuilder.Commit()
objects1 = [NXOpen.CAM.CAMObject.Null] * 1
cavityMilling2 = nXObject6
objects1[0] = cavityMilling2
arg_workpart.CAMSetup.GenerateToolPath(objects1)
cavityMillingBuilder.Destroy()
cavityMillingBuilder2 = arg_workpart.CAMSetup.CAMOperationCollection.CreateCavityMillingBuilder(cavityMilling2)
isupdated2 = cavityMillingBuilder2.CutLevel.InitializeData()
toolpath=cavityMillingBuilder2.Commit()
cavityMillingBuilder2.Destroy()
#显示刀路
session.CAMSession.PathDisplay.ShowToolPath(toolpath)
session.CAMSession.PathDisplay.Jump(False)
if __name__ == '__main__':
# ----------------------------------------------
# tool_diameter变量为刀具直径,数值类型双精度
# tool_name变量为刀具名字,根据tool_diameter生成
# nc_program_name变量默认为字符串"NC_PROGRAM"
# nc_method_name变量默认为"METHOD"
# 四个变量必须生成
# example:
# tool_diameter=8.0
# tool_name="8.0铣刀"
# nc_program_name="NC_PROGRAM"
# nc_method_name="METHOD"
# mcs_name ="MCS"
# ----------------------------------------------
tool_name = None
tool_diameter = None
nc_program_name = None
nc_method_name = None
mcs_name = None
session=init_cam()
workpart=init_workpart(session)
generic_machine=init_parent_generic_machine(workpart)
geometry=init_parent_geometry(workpart)
nc_program=init_parent_nc_program(workpart,nc_program_name)
nc_method=init_parent_nc_method(workpart,nc_method_name)
template_name=init_template_name()
tool=create_tool(workpart,generic_machine,template_name,tool_name,tool_diameter)
mcs=create_mcs(workpart,geometry,template_name,mcs_name)
cam_feature,body=create_cam_feature(workpart,mcs,template_name)
block_feature=create_block_feature(workpart,cam_feature,body)
cam_program(workpart,nc_program,nc_method,tool,cam_feature,template_name)

View File

@ -0,0 +1,205 @@
# NX Version:NX 2412
# Email:809262979@qq.com
# python .py created by deepseek
#
import NXOpen
import NXOpen.Assemblies
import NXOpen.Drafting
import NXOpen.Drawings
import NXOpen.Preferences
def main(args):
theSession = NXOpen.Session.GetSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theSession.ApplicationSwitchImmediate("UG_APP_DRAFTING")
workPart.Drafting.EnterDraftingApplication()
modelingView1 = workPart.ModelingViews.FindObject("Trimetric")
modelingView1.UpdateCustomSymbols()
draftingDrawingSheetBuilder1 = workPart.DraftingDrawingSheets.CreateDraftingDrawingSheetBuilder(NXOpen.Drawings.DraftingDrawingSheet.Null)
draftingDrawingSheetBuilder1.AutoStartViewCreation = True
draftingDrawingSheetBuilder1.Option = NXOpen.Drawings.DrawingSheetBuilder.SheetOption.CustomSize
draftingDrawingSheetBuilder1.StandardMetricScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11
draftingDrawingSheetBuilder1.StandardEnglishScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardEnglishScale.S11
draftingDrawingSheetBuilder1.Height = 841.0
draftingDrawingSheetBuilder1.Length = 1189.0
draftingDrawingSheetBuilder1.StandardMetricScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11
draftingDrawingSheetBuilder1.StandardEnglishScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardEnglishScale.S11
draftingDrawingSheetBuilder1.ScaleNumerator = 1.0
draftingDrawingSheetBuilder1.ScaleDenominator = 1.0
draftingDrawingSheetBuilder1.Units = NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric
draftingDrawingSheetBuilder1.ProjectionAngle = NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third
draftingDrawingSheetBuilder1.Number = "1"
draftingDrawingSheetBuilder1.SecondaryNumber = ""
draftingDrawingSheetBuilder1.Revision = "A"
nXObject1 = draftingDrawingSheetBuilder1.Commit()
draftingDrawingSheetBuilder1.Destroy()
workPart.Drafting.SetTemplateInstantiationIsComplete(True)
workPart.DraftingManager.DrawingsFreezeOutOfDateComputation()
baseViewBuilder1 = workPart.DraftingViews.CreateBaseViewBuilder(NXOpen.Drawings.BaseView.Null)
modelingView2 = workPart.ModelingViews.FindObject("Top")
baseViewBuilder1.SelectModelView.SelectedView = modelingView2
baseViewBuilder1.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry
baseViewBuilder1.Style.ViewStyleBase.Part = workPart
loadStatus1 = workPart.IsFullyLoaded
baseViewBuilder1.SelectModelView.SelectedView = modelingView2
baseViewBuilder1.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
baseViewBuilder1.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = False
baseViewBuilder1.Style.ViewStyleOrientation.Ovt.NormalDirection = NXOpen.Direction.Null
baseViewBuilder1.Style.ViewStyleOrientation.Ovt.XDirection = NXOpen.Direction.Null
baseViewBuilder1.SelectModelView.SelectedView = modelingView2
baseViewBuilder1.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
baseViewBuilder1.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = False
modelingView3 = workPart.ModelingViews.FindObject("Front")
baseViewBuilder1.SelectModelView.SelectedView = modelingView3
baseViewBuilder1.Style.ViewStyleOrientation.Ovt.NormalDirection = NXOpen.Direction.Null
baseViewBuilder1.Style.ViewStyleOrientation.Ovt.XDirection = NXOpen.Direction.Null
baseViewBuilder1.Scale.ScaleType = NXOpen.Drawings.ViewScaleBuilder.Type.Expression
baseViewBuilder1.Scale.ScaleType = NXOpen.Drawings.ViewScaleBuilder.Type.Ratio
baseViewBuilder1.Scale.Numerator = 3.0
point1 = NXOpen.Point3d(333.40588942307699, 638.37445054945056, 0.0)
baseViewBuilder1.Placement.Placement.SetValue(NXOpen.TaggedObject.Null, workPart.Views.WorkView, point1)
nXObject2 = baseViewBuilder1.Commit()
workPart.DraftingManager.DrawingsUnfreezeOutOfDateComputation()
baseViewBuilder1.Destroy()
workPart.DraftingManager.DrawingsFreezeOutOfDateComputation()
draftingDrawingSheet1 = nXObject1
draftingDrawingSheet1.Open()
projectedViewBuilder1 = workPart.DraftingViews.CreateProjectedViewBuilder(NXOpen.Drawings.ProjectedView.Null)
projectedViewBuilder1.Style.ViewStyleOrientation.HingeLine.Associative = True
projectedViewBuilder1.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry
unit1 = workPart.UnitCollection.FindObject("MilliMeter")
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
baseView1 = nXObject2
projectedViewBuilder1.Parent.View.Value = baseView1
projectedViewBuilder1.Style.ViewStyleGeneral.ToleranceValue = 0.0080000080000000012
projectedViewBuilder1.Style.ViewStyleGeneral.Scale.Numerator = 3.0
projectedViewBuilder1.Style.ViewStyleGeneral.ExtractedEdges = NXOpen.Preferences.GeneralExtractedEdgesOption.Associative
vieworigin1 = NXOpen.Point3d(-50.0, -10.0, 50.0)
projectedViewBuilder1.Style.ViewStylePerspective.ViewOrigin = vieworigin1
projectedViewBuilder1.Placement.AlignmentView.Value = baseView1
projectedViewBuilder1.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
projectedViewBuilder1.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = True
projectedViewBuilder1.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder1.Placement.AlignmentView.Value = baseView1
point2 = NXOpen.Point3d(0.0, 0.0, 0.0)
projectedViewBuilder1.Placement.Placement.SetValue(baseView1, workPart.Views.WorkView, point2)
projectedViewBuilder1.Style.ViewStyleOrientation.HingeLine.ReverseDirection = True
point3 = NXOpen.Point3d(333.40588942307699, 321.03557692307697, 0.0)
projectedViewBuilder1.Placement.Placement.SetValue(NXOpen.TaggedObject.Null, workPart.Views.WorkView, point3)
projectedViewBuilder1.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder1.Placement.AlignmentView.Value = baseView1
nXObject3 = projectedViewBuilder1.Commit()
workPart.DraftingManager.DrawingsUnfreezeOutOfDateComputation()
projectedViewBuilder1.Destroy()
workPart.MeasureManager.SetPartTransientModification()
workPart.Expressions.Delete(expression1)
workPart.MeasureManager.ClearPartTransientModification()
workPart.DraftingManager.DrawingsFreezeOutOfDateComputation()
projectedViewBuilder2 = workPart.DraftingViews.CreateProjectedViewBuilder(NXOpen.Drawings.ProjectedView.Null)
projectedViewBuilder2.Style.ViewStyleOrientation.HingeLine.Associative = True
projectedViewBuilder2.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
projectedViewBuilder2.Parent.View.Value = baseView1
projectedViewBuilder2.Style.ViewStyleGeneral.ToleranceValue = 0.0080000080000000012
projectedViewBuilder2.Style.ViewStyleGeneral.Scale.Numerator = 3.0
projectedViewBuilder2.Style.ViewStyleGeneral.ExtractedEdges = NXOpen.Preferences.GeneralExtractedEdgesOption.Associative
vieworigin2 = NXOpen.Point3d(-50.0, -10.0, 50.0)
projectedViewBuilder2.Style.ViewStylePerspective.ViewOrigin = vieworigin2
projectedViewBuilder2.Placement.AlignmentView.Value = baseView1
projectedViewBuilder2.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
projectedViewBuilder2.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = True
projectedViewBuilder2.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder2.Placement.AlignmentView.Value = baseView1
projectedViewBuilder2.Style.ViewStyleOrientation.HingeLine.ReverseDirection = True
point4 = NXOpen.Point3d(771.52299107142858, 638.37445054945056, 0.0)
projectedViewBuilder2.Placement.Placement.SetValue(NXOpen.TaggedObject.Null, workPart.Views.WorkView, point4)
projectedViewBuilder2.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder2.Placement.AlignmentView.Value = baseView1
nXObject4 = projectedViewBuilder2.Commit()
workPart.DraftingManager.DrawingsUnfreezeOutOfDateComputation()
projectedViewBuilder2.Destroy()
workPart.MeasureManager.SetPartTransientModification()
workPart.Expressions.Delete(expression2)
workPart.MeasureManager.ClearPartTransientModification()
workPart.DraftingManager.DrawingsFreezeOutOfDateComputation()
projectedViewBuilder3 = workPart.DraftingViews.CreateProjectedViewBuilder(NXOpen.Drawings.ProjectedView.Null)
projectedViewBuilder3.Style.ViewStyleOrientation.HingeLine.Associative = True
projectedViewBuilder3.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
projectedViewBuilder3.Parent.View.Value = baseView1
projectedViewBuilder3.Style.ViewStyleGeneral.ToleranceValue = 0.0080000080000000012
projectedViewBuilder3.Style.ViewStyleGeneral.Scale.Numerator = 3.0
projectedViewBuilder3.Style.ViewStyleGeneral.ExtractedEdges = NXOpen.Preferences.GeneralExtractedEdgesOption.Associative
vieworigin3 = NXOpen.Point3d(-50.0, -10.0, 50.0)
projectedViewBuilder3.Style.ViewStylePerspective.ViewOrigin = vieworigin3
projectedViewBuilder3.Placement.AlignmentView.Value = baseView1
projectedViewBuilder3.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
projectedViewBuilder3.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = True
projectedViewBuilder3.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder3.Placement.AlignmentView.Value = baseView1
projectedViewBuilder3.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder3.Placement.AlignmentView.Value = baseView1
workPart.DraftingManager.DrawingsUnfreezeOutOfDateComputation()
projectedViewBuilder3.Destroy()
workPart.MeasureManager.SetPartTransientModification()
workPart.Expressions.Delete(expression3)
workPart.MeasureManager.ClearPartTransientModification()
workPart.DraftingManager.DrawingsFreezeOutOfDateComputation()
baseViewBuilder2 = workPart.DraftingViews.CreateBaseViewBuilder(NXOpen.Drawings.BaseView.Null)
baseViewBuilder2.SelectModelView.SelectedView = modelingView2
baseViewBuilder2.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry
loadStatus2 = workPart.IsFullyLoaded
baseViewBuilder2.SelectModelView.SelectedView = modelingView2
baseViewBuilder2.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
baseViewBuilder2.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = False
baseViewBuilder2.Style.ViewStyleOrientation.Ovt.NormalDirection = NXOpen.Direction.Null
baseViewBuilder2.Style.ViewStyleOrientation.Ovt.XDirection = NXOpen.Direction.Null
baseViewBuilder2.SelectModelView.SelectedView = modelingView2
baseViewBuilder2.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
baseViewBuilder2.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = False
modelingView4 = workPart.ModelingViews.FindObject("Isometric")
baseViewBuilder2.SelectModelView.SelectedView = modelingView4
baseViewBuilder2.Style.ViewStyleOrientation.Ovt.NormalDirection = NXOpen.Direction.Null
baseViewBuilder2.Style.ViewStyleOrientation.Ovt.XDirection = NXOpen.Direction.Null
baseViewBuilder2.Scale.Numerator = 3.0
point5 = NXOpen.Point3d(833.65502542739284, 324.06619235608628, 0.0)
baseViewBuilder2.Placement.Placement.SetValue(NXOpen.TaggedObject.Null, workPart.Views.WorkView, point5)
nXObject5 = baseViewBuilder2.Commit()
workPart.DraftingManager.DrawingsUnfreezeOutOfDateComputation()
baseViewBuilder2.Destroy()
workPart.DraftingManager.DrawingsFreezeOutOfDateComputation()
draftingDrawingSheet1.Open()
projectedViewBuilder4 = workPart.DraftingViews.CreateProjectedViewBuilder(NXOpen.Drawings.ProjectedView.Null)
projectedViewBuilder4.Style.ViewStyleOrientation.HingeLine.Associative = True
projectedViewBuilder4.SecondaryComponents.ObjectType = NXOpen.Drawings.DraftingComponentSelectionBuilder.Geometry.PrimaryGeometry
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
baseView2 = nXObject5
projectedViewBuilder4.Parent.View.Value = baseView2
projectedViewBuilder4.Style.ViewStyleGeneral.ToleranceValue = 0.039191843884530862
projectedViewBuilder4.Style.ViewStyleGeneral.Scale.Numerator = 3.0
projectedViewBuilder4.Style.ViewStyleGeneral.ExtractedEdges = NXOpen.Preferences.GeneralExtractedEdgesOption.Associative
vieworigin4 = NXOpen.Point3d(-70.710678118654755, -8.164965809277259, -5.7735026918962582)
projectedViewBuilder4.Style.ViewStylePerspective.ViewOrigin = vieworigin4
projectedViewBuilder4.Placement.AlignmentView.Value = baseView2
projectedViewBuilder4.Style.ViewStyleBase.Arrangement.SelectedArrangement = NXOpen.Assemblies.Arrangement.Null
projectedViewBuilder4.Style.ViewStyleBase.Arrangement.InheritArrangementFromParent = True
projectedViewBuilder4.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder4.Placement.AlignmentView.Value = baseView2
point6 = NXOpen.Point3d(0.0, 0.0, 0.0)
projectedViewBuilder4.Placement.Placement.SetValue(baseView2, workPart.Views.WorkView, point6)
projectedViewBuilder4.Placement.AlignmentView.Value = NXOpen.TaggedObject.Null
projectedViewBuilder4.Placement.AlignmentView.Value = baseView2
workPart.DraftingManager.DrawingsUnfreezeOutOfDateComputation()
projectedViewBuilder4.Destroy()
workPart.MeasureManager.SetPartTransientModification()
workPart.Expressions.Delete(expression4)
workPart.MeasureManager.ClearPartTransientModification()
theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
workPart.Drafting.ExitDraftingApplication()
if __name__ == '__main__':
main(sys.argv[1:])

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,5 +5,4 @@
4-生成正等测图
所有数值为双精度类型
所有视图比例3:1
图纸内容涵盖内容
根据NXOpen_API.py和NXOpen API生成python代码
NXOpen API生成python代码

View File

@ -0,0 +1,35 @@
def process_lines(lines):
result = []
i = 0
while i < len(lines):
current_line = lines[i].strip()
if i > 0 and current_line == '(value)':
# 如果当前行只包含 (self),将其合并到上一行
prev_line = result.pop()
new_line = prev_line.rstrip() + " (value)"
result.append(new_line + '\n')
else:
result.append(lines[i])
i += 1
return result
def process_file(input_file_path, output_file_path):
try:
with open(input_file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
processed_lines = process_lines(lines)
with open(output_file_path, 'w', encoding='utf-8') as output_file:
output_file.writelines(processed_lines)
print(f"处理完成,结果已保存到 {output_file_path}")
except FileNotFoundError:
print(f"未找到输入文件: {input_file_path}")
# 输入文件路径
input_file = 'a00006.txt-merge.txt-new.txt'
# 输出文件路径
output_file = 'output.txt'
process_file(input_file, output_file)

View File

@ -0,0 +1,28 @@
def process_file(input_file_path, output_file_path):
with open(input_file_path, 'r', encoding='utf-8') as input_file:
lines = input_file.readlines()
processed_lines = []
i = 0
while i < len(lines):
line = lines[i].strip()
if line == 'def':
# 如果当前行只包含 'def'
next_line = lines[i + 1].lstrip() if i + 1 < len(lines) else ''
# 将下一行内容缩进并和 'def' 保持在同一行
new_line = f"def {next_line}"
processed_lines.append(new_line)
i += 2 # 跳过下一行
else:
processed_lines.append(lines[i])
i += 1
with open(output_file_path, 'w', encoding='utf-8') as output_file:
output_file.writelines(processed_lines)
# 输入文件路径
input_file_path = 'a00006.txt-merge.txt-new.txt'
# 输出文件路径
output_file_path = 'output.txt'
process_file(input_file_path, output_file_path)

View File

@ -0,0 +1,34 @@
import re
def process_text(input_file, output_file):
# 打开输入文件并读取内容
with open(input_file, 'r', encoding='utf-8') as f:
lines = f.readlines()
processed_lines = []
i = 0
while i < len(lines):
line = lines[i].strip()
# 检查是否为函数调用语句
if re.match(r'.*\(.*', line):
# 找到函数调用的结束括号
full_line = line
while ')' not in full_line:
i += 1
if i < len(lines):
full_line += lines[i].strip()
# 移除多余的换行符和空格
full_line = re.sub(r'\s+', ' ', full_line)
processed_lines.append(full_line + '\n')
else:
processed_lines.append(line + '\n')
i += 1
# 将处理后的文本写入输出文件
with open(output_file, 'w', encoding='utf-8') as f:
f.writelines(processed_lines)
# 示例用法
input_file = 'a00006.txt-merge.txt-new.txt'
output_file = 'output.txt'
process_text(input_file, output_file)

37
python/two_line.py Normal file
View File

@ -0,0 +1,37 @@
def process_file(input_file_path, output_file_path):
try:
# 打开输入文件进行读取
with open(input_file_path, 'r', encoding='utf-8') as input_file:
lines = input_file.readlines()
processed_lines = []
empty_line_count = 0
for line in lines:
if line.strip() == '':
# 如果当前行为空行
empty_line_count += 1
if empty_line_count <= 2:
# 若空行数量不超过 2则添加该空行
processed_lines.append(line)
else:
# 如果当前行不为空行
processed_lines.append(line)
empty_line_count = 0
# 打开输出文件进行写入
with open(output_file_path, 'w', encoding='utf-8') as output_file:
output_file.writelines(processed_lines)
print(f"处理完成,结果已保存到 {output_file_path}")
except FileNotFoundError:
print(f"未找到输入文件: {input_file_path}")
# 输入文件路径
input_file = 'a00006.txt-merge.txt-new.txt'
# 输出文件路径
output_file = 'output.txt'
process_file(input_file, output_file)