×
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

Need help in this CATIA VB Script

Need help in this CATIA VB Script

Need help in this CATIA VB Script

(OP)
Hi all,

I wanted to import 3D point coodrinates from CATIA to excel sheet using a CATScript. I wanted the coordinates to be imported one by one, in the same order which I select the points in CATIA. I tried using SelectElement3 as it allows to select multiple parts. But I got the following error all time.

"Compile Error:

Function or interface marked as restricted, or the function uses an
Automation type which is not supported in visual basic"


Below is the code:

Dim Excel As Object
Dim workBooks As Object
Dim workBook As Object
Dim workSheets As Object
Dim workSheet As Object
Dim XYZ(2) As Variant
--------------------------------------------------------------

Sub CATMain()
Dim partDocument1 As PartDocument
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(1)
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridbody1 As HybridBody
Set hybridbody1 = hybridBodies1.Item(1)
Dim hybridShapes1 As hybridShapes
Set hybrdishapes1 = hybridbody1.hybridShapes
Dim hybridShape1 As HybridShape
Set hybridShape1 = hybridShapes1.Item(1)

Dim pointSelect As Selection
Set pointSelect = CATIA.ActiveDocument.Selection

Dim pArray(0) As Variant
Dim showStatus

pArray(0) = "Point"
showStatus = pointSelect.SelectElement3(pArray, "Select Points", False, CATMultiSelTriggWhenUserValidatesSelection, False)
StartExcel
ExportPoint
End Sub
-------------------------------------------------------------------
Sub StartExcel()
Err.Clear
On Error Resume Next
Set Excel = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set Excel = CreateObject("EXCEL.Application")
Excel.Application.Visible = True
End If
Set workBooks = Excel.Application.workBooks
Set workBook = workBooks.Add
Set workSheets = workBook.workSheets(1)
Set workSheet = workBook.Sheets(1)
workSheet.Cells(1, "A") = "No"
workSheet.Cells(1, "B") = "Name"
workSheet.Cells(1, "C") = "X"
workSheet.Cells(1, "D") = "Y"
workSheet.Cells(1, "E") = "Z"
End Sub
--------------------------------------------------------------------
Sub ExportPoint()
Dim pSel As Selection
Set pSel = CATIA.ActiveDocument.Selection
Dim pCount As Integer
Set pCount = pSel.Count
Dim element, pointCoord
For i = 1 To pCount
Set element = pSel.Item(i)
Set pointCoord = element.Value
Point.GetCoordinates XYZ
workSheet.Cells(i + 1, "A") = i
workSheet.Cells(i + 1, "B") = Point.Name
workSheet.Cells(i + 1, "C") = XYZ(0) * 0.03937
workSheet.Cells(i + 1, "D") = XYZ(1) * 0.03937
workSheet.Cells(i + 1, "E") = XYZ(2) * 0.03937
Next i
End Sub

The error is in the highlighted part of the code. Please help me out in this. What could be the reason for this error? Did I not use the SelectElement3 properly?

Thanks in Advance.


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