Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set edge as reference

Status
Not open for further replies.

lukaszsz

Aerospace
Oct 16, 2012
71
PL
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:
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
 
Replies continue below

Recommended for you

Hi,

Bellow is an example in a CATScript. Make a part with a pad inside and few holes and test it.

Code:
' ==============================================================
' Purpose: The macro will find the holes in a CATPart and will list them one by one in a message box
' Usage:   1 - A CATPart with Holes should be active
'          2 - Run macro 
' Author: ferdo (Disclaimer: You use this code at your own risk) 
' ===============================================================

Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

dim selection1 as selection
set selection1=CATIA.activedocument.selection

selection1.clear
for i = 1 to shapes1.count
selection1.add shapes1.Item(i)
NEXT
'==============================
'Loop to find holes

Dim xSelObj() As Variant
Dim xObj As Variant
Dim n as Integer
Dim myObj As AnyObject

Dim nCount As Integer
nCount = 0

		for n= 0 to shapes1.count

			  On Error Resume Next
			  Set myObj = selection1.FindObject("CATIAHole")

             			  ReDim Preserve xSelObj(nCount)
               			 Set xSelObj(nCount) = myObj
			  nCount = nCount + 1

		next

  ' Listing holes
  
Dim sList As String
Dim nI As Integer

'Loop for message

		For nI =0 To ncount-3
			
dim referenceX as reference 
 Set referenceX = part1.CreateReferenceFromObject(xSelObj(nI))
 MsgBox referenceX.DisplayName
		Next
   	
part1.Update 

End Sub

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top