×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Set edge as reference

Set edge as reference

Set edge as reference

(OP)
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

RE: Set edge as reference

Hi,

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

CODE --> CATScript

' ==============================================================
' 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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources