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!

Need help in this CATIA VB Script

Status
Not open for further replies.

Seenivas28

Mechanical
Mar 22, 2015
6
IN
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.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top