×
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

How search item to copy?

How search item to copy?

How search item to copy?

(OP)
Hi Again

Here it´s my code for read holes and thread, and show them in a worksheet of Excel



Sub export()

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

Dim i

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



Dim sList As String
Dim nI As Integer



For nI = 0 To nCount - 3

Dim referenceX As Reference
Set referenceX = part1.CreateReferenceFromObject(xSelObj(nI))

Next

part1.Update

Dim Excel As Object
Dim Sheets As Object
Dim Sheet As Object


On Error Resume Next
Set Excel = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set Excel = CreateObject("EXCEL.Application")
Else
Err.Clear
MsgBox "Please note you have to close Excel", vbCritical
Exit Sub
End If

Excel.Visible = True

Dim workbooks
Dim myworkbook
Dim myworksheet

Set workbooks = Excel.Application.workbooks
Set myworkbook = Excel.workbooks.Add
Set myworksheet = Excel.ActiveWorkbook.Add
Set myworksheet = Excel.Sheets.Add

Excel.Cells(1, 4) = "diameter"
Excel.Cells(1, 5) = "thread"

Dim iAnzahlGew
selection1.Search "CATPrtSearch.Hole.Threaded=TRUE,all"
iAnzahlGew = selection1.Count

Dim valor As Integer
valor = 0


Dim Hole
For i = 1 To iAnzahlGew
Set Hole = selection1.Item2(i).Value
Excel.Cells(1 + i, 4) = Hole.Diameter.Value
Excel.Cells(1 + i, 5) = Hole.HoleThreadDescription.Value
valor = valor + 1
Next

If valor > 1 Then
valor = valor - 1
End If

Excel.Cells(3 + valor, 1) = "Holes"
Excel.Cells(2, 3) = selection1.Count ' numero de roscas


Dim iHoleInSelection
iHoleInSelection = True
Dim oPartDoc
Dim OBody
Set oPartDoc = CATIA.ActiveDocument
Set OBody = oPartDoc.part.Bodies.Item("PartBody")

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

Dim selection2
Set selection2 = oPartDoc.Selection

selection2.Search "CATPrtSearch.Hole.Threaded=FALSE,all"



For i = 1 To selection2.Count

Dim oHole
Dim oHoleName
Dim oHoleType

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

Excel.Cells(2 + valor + i, 4) = CStr(oHole.Diameter.Value)
Excel.Cells(2 + valor + i, 5) = CStr(oHoleName.Name)



Next
End Sub



Please, someone can you show me how read the circullar or rectangullar pattern, and how obtain the number of item to copy of each pattern?

Thanks

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