不适用
05-31-2018
10:58 PM
你好,我在工作中遇到一个问题,现在希望通过ilogic实现对部件所有引用的零件进行XYZ三方向的长度测量,目前尝试过如下代码,但是发现偏差比较大,
'check this file is an assembly Dim doc As Document = ThisApplication.ActiveDocument If doc.DocumentType = kPartDocumentObject Then MessageBox.Show("这个规则只能在部件环境下运行!", "错误") Return End If ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get the assembly component definition. Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition ' Get all of the leaf occurrences of the assembly. Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences Dim NameList As New ArrayList() ' Iterate through the occurrences and collect the name. Dim oOcc As ComponentOccurrence Dim modX As Double Dim modY As Double Dim modZ As Double For Each oOcc In oLeafOccs Try otester =Parameter(oOcc.Name, "滚轮内径") '获取模型的外形尺寸 modX = (oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10 modY = (oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y ) * 10 modZ = (oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10 'Round to 0 modXr = Round(Abs(modX), 0) modYr = Round(Abs(modY), 0) modZr = Round(Abs(modZ), 0) minB=MinOfMany(modXr,modYr,modZr) maxB=MaxOfMany(modXr,modYr,modZr) iProperties.Value(oOcc.Name, "Custom", "最大")=maxB iProperties.Value(oOcc.Name, "Custom", "最小")=minB Catch End Try Next
滚轮外径是实际尺寸是正确值,而通过上方代码得到的最大值出入很大,厚度尺寸没问题。
后来在零件环境下发现利用ilogic中的测量的代码得到的结果就非常正确,
iProperties.Value("Custom", "xx")=Measure.ExtentsLength iProperties.Value("Custom", "YY")=Measure.ExtentsWidth iProperties.Value("Custom", "ZZ")=Measure.ExtentsHeight
问题:如何在部件中去利用Measure.ExtentsLength这个代码去测量所有引用的零件的尺寸。
已解决! 转到解答。
Link copied