Hello all
I'm working on macro that will return length of selected linear object (edge, line, spline, etc..)
There are two approach to get object as reference
simply way - when object is selected from tree (asALine, isASplin etc..) or more complicated - when these same (or any other) object is selected from graphic window
here is the whole code:
It works, but I'm wondering if there is any other way to set for example edge as reference without all those 'playing' with string newName
Thanks for all Yours replies.
Łukasz
LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
I'm working on macro that will return length of selected linear object (edge, line, spline, etc..)
There are two approach to get object as reference
simply way - when object is selected from tree (asALine, isASplin etc..) or more complicated - when these same (or any other) object is selected from graphic window
here is the whole code:
Code:
Language="VBSCRIPT"
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1=partDocument1.Part
set selection1=partDocument1.Selection
if selection1.count=1 then
set MeasuredElement1=partDocument1.Selection.Item(1).Value
'msgbox TypeName(MeasuredElement1)
isALine= Instr(1,TypeName(MeasuredElement1),"HybridShapeLine")
isASpline= Instr(1,TypeName(MeasuredElement1),"HybridShapeSpline")
isAConnect= Instr(1,TypeName(MeasuredElement1),"HybridShapeConnect")
if (isALine<>0) or (isASpline<>0) or (isAConnect<>0) then
set ref1=part1.CreateReferenceFromObject(MeasuredElement1)
else
newName= right(MeasuredElement1.Name,Len(MeasuredElement1.Name)-10)
if InStr(1,newName,"REdge")=0 then
msgbox "Select Edge or Line only!"
Exit Sub
else
Pozycja = InStr(1,newName, "None:(Limits1:();Limits2:());Cf11:())")
newName=left(newName,Pozycja+Len("None:(Limits1:();Limits2:());Cf11:())"))
newName=newName&"WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)"
set ref1=part1.CreateReferenceFromBRepName(newName,MeasuredElement1.parent)
end if
end if
Set TheSPAWorkbench = partDocument1.GetWorkbench("SPAWorkbench")
set measurable1 = TheSPAWorkbench.GetMeasurable (ref1)
msgbox measurable1.Length
else
msgbox "Select only ONE element"
end if
End Sub
It works, but I'm wondering if there is any other way to set for example edge as reference without all those 'playing' with string newName
Thanks for all Yours replies.
Łukasz
LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013