|
二次开发时,经常用到,特征找体,特征找边这之类的。
写了一个例子,创建一个块,再创建一个圆柱进行求差,再求第一个块特特征各边的标识,打印出来。
源代码如下:
- # NX 10.0.3.5
- # by TangKangLin QQ:125317589 2018.02.05
- import NXOpen
- import NXOpen.UF
- def main():
- try:
- theSession = NXOpen.Session.GetSession()
- theUfSession = NXOpen.UF.UFSession.GetUFSession()
- theUI = NXOpen.UI.GetUI()
-
- #创建立方体
- cornerPt = [0.0, 0.0, 0.0]
- edgeLen = ["100.0", "50.0", "25.0"]
- blockFeatTag = theUfSession.ModlFeatures.CreateBlock1(NXOpen.UF.Modl.FeatureSigns.NULLSIGN, cornerPt, edgeLen)
- #创建圆柱体并求差
- featSign = NXOpen.UF.Modl.FeatureSigns.NEGATIVE
- blockBodyTag = theUfSession.Modeling.AskFeatBody(blockFeatTag)
- cylOrigin = [50.0, 25.0, 0.0]
- cylHeight = "40.0"
- cylDiam = "25.0"
- cylDirection = [0.0, 0.0, 1.0]
- cylFeatTag = theUfSession.ModlFeatures.CreateCylinder(featSign, blockBodyTag, cylOrigin, cylHeight, cylDiam, cylDirection)
-
- #获取体上所有的边
- allEdgesList = theUfSession.Modeling.AskFeatEdges(blockFeatTag)
- listCount = theUfSession.ModlGeneral.AskListCount(allEdgesList)
-
- #打印所有的边标识
- theSession.ListingWindow.Open()
- for index in range(0, listCount):
- edgeTag = theUfSession.ModlGeneral.AskListItem(allEdgesList, index)
- tempStr = "第%d边的Tag为: %d"%(index, edgeTag)
- theSession.ListingWindow.WriteLine(tempStr)
- except Exception as ex:
- theUI.NXMessageBox.Show("温馨提示", NXOpen.NXMessageBox.DialogType.Error, str(ex))
- if __name__ == '__main__':
- main()
复制代码
|
|