狮猿社CATIA

CATIA VBA测量选中line/spline

2020-02-04  本文已影响0人  锦囊喵

以下代码片段使用selectelment3及SpaWorkbench实现:
原文链接

Dim PD1 as PartDocument
Dim Sel 'as Selection ''Sometimes it is needed to comment the selection to use the .SelectElement3 method'
Dim InputObjType(0)
Dim SelectionResult as string    
Dim LineToMeasure as AnyObject    
Dim I as Integer    
Dim SpaWorkbench as SPAWorkbench
Dim Measurable as Measurable

InputObjType(0) = "AnyObject"

'set PD1 = Catia.ActiveDocument'
set Sel = PD1.Selection
Set TheSPAWorkbench = pd1.GetWorkbench("SPAWorkbench")    

Sel.Clear
SelectionResult= Sel.SelectElement3(InputObject, "Select objects to list names", True, CATMultiSelTriggWhenUserValidatesSelection, False)

If SelectionResult = "Ok" or SelectionResult = "Normal" then 'Check if user did not cancel the Selection'
    For i = 1 to Selection.Count
        Set LineToMeasure = Sel.Item(i).Value
        set Measurable = SpaWorkbench.GetMeasurable(LineToMeasure)

        'Measure whatever you need here.'
    Next
End If

以下使用参数及公式,并配合Query及length函数:
原文链接
如果所测元素全部在一个几何集("cableway_curves" ),可以创建一个totalLength 的参数,并使用如下公式:

totalLength = length(cableway_curves->Query("Curve",""))

否则,可以使用如下公式(假设几何集名称为cableway.1, cableway.2 ... ):

totalLength = length(myPart->Query("Curve","x.Name->Search(\"cableway.\")==0"))

以下写法可以作为参考:

Query("Curve","x->IsSupporting(\"GSMDirection\")==false") 

上一篇下一篇

猜你喜欢

热点阅读