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!

Macro Catia with holes

Status
Not open for further replies.

gerlado

Mechanical
Oct 17, 2012
23
ES
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
 
Replies continue below

Recommended for you

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

 
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
 
Ok
thank you very much
It will look about

thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top