×
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

Macro Catia with holes

Macro Catia with holes

Macro Catia with holes

(OP)
Hi friends
I try to find a macro that can you read me the total number of holes of a catia part
The code is the follow:


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

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

Next

part1.Update

End Sub



My Problem is that this macro can´t read the hole made with a rectangular or circullar pateerm

If it posible, someone can you help me whit this

And How can export the information of this hole (Thread, length...etc)


Thank you very much for all

RE: Macro Catia with holes

to find patterns in partdesign:

Set myObj = selection1.FindObject("CATIAPattern")
msgbox myObj.itemtocopy.name <- it's item's name, e.g. Hole.1, If You have array of Holes You can easily check if ItemToCopy refers to Holes or other Shapes

to get parameters:

set params = part1.parameters
msgbox params.item(1).name <-thats the way You can list all Your parameters.


I would be glad (and Author probably too) if anyone show how to get list of parameters related to specified object, eg Shape

RE: Macro Catia with holes

Hi,

I believe there is a similar thread in the forum. Anyway...catscript...and of course, you need to modify according to your needs.

Language="VBSCRIPT"

Sub CATMain()

Dim oPartDoc As PartDocument
Dim oBody As Body
Dim oHole As Hole
Dim i As Integer
Dim selection1 As Selection
Dim selection2 As Selection
Dim oHoleName As HoleName
Dim oHoleType As HoleType
'*******************************
CATIA.DisplayFileAlerts = False
Dim Message, Style, Title, Response, MyString
Message = ("You must have a temp folder in your C drive " &_
""&(chr(13))&_
" Do you want to continue ?")
Style = vbYesNo + vbDefaultButton2 'Define buttons.
Title = "Extract holes parameters to text file"
Response = MsgBox(Message, Style, Title)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes"
Else

If Response = vbNo Then
MyString = "No"
Exit Sub

End If
End If
'*************************************
Set document = CATIA.ActiveDocument

Set filesys = CATIA.FileSystem
crlf = chr(10)
filename = "c:\temp\Holes_parameters_of_"&document.Name&".txt"
if filesys.FileExists(filename) Then
filesys.DeleteFile(filename)
End If
Set file = filesys.CreateFile(filename,True)
Set stream = file.OpenAsTextStream("ForWriting")
err=0
'**************************************************************
iHoleInSelection = True
Set oPartDoc = CATIA.ActiveDocument
Set oBody = oPartDoc.Part.Bodies.Item("PartBody")

Set selection1 = oPartDoc.Selection
selection1.Search "(Name=PartBody* & CATPrtSearch.BodyFeature),all"

Set selection2 = oPartDoc.Selection
selection2.Search "Type=Hole,sel"

stream.write("Crt_no"&" "&"Hole_Name"&" "&"Hole_Dia"&" "&"Hole_Type"&crlf) 'first line in output file

For i=1 To selection2.Count

Set oHole = selection2.Item(i).Value
Set oHoleName = selection2.Item(i).Value
Set oHoleType = selection2.Item(i).Value

MsgBox CStr(oHoleName.Name) & " " & " " & "Diameter=" & CStr(oHole.Diameter.Value) & " " & "Type=" & CStr(oHole.Type)

stream.write(i&" "&oHoleName.Name&" "&oHole.Diameter.Value&" "&oHole.Type&crlf)

Next

End Sub

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Macro Catia with holes

(OP)
Hello Ferdo

Thank you very much for your message
I found it very useful

Elsewhere
I still can not solve the problem of the pattern rectangullar and circular, because the way of lukaszs doesn´t work me.
Could you help me with the media into the holes counter?

Thank you very much

RE: Macro Catia with holes

Frankly speaking I don't have much time.

What I can suggest is: if you find already the parent of the pattern (in other words itemtocopy as Lukaszsz suggest), the problem is almost solved, no?

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Macro Catia with holes

(OP)
Ok
thank you very much
It will look about

thank you very much

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