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!

Need help in Catia Macro

Status
Not open for further replies.

Aviatorbarath

New member
Dec 27, 2012
35
US
Hi .. I wrote a macro whihc takes the inertia parameter from catia and writes it in excel. I m struck in between; i tried to put a loop; it stops working. can someone help me with debuggin this code


Sub CATMain()
On Error Resume Next
' suppose you have Part document opened in active window
Dim PartDoc As PartDocument
Set PartDoc = CATIA.ActiveDocument

Dim PartRoot As Part
Set PartRoot = PartDoc.Part

' get parameters collection
Dim objPartParams As Parameters
Set objPartParams = PartRoot.Parameters

' find desired "Inertia" object, which name is defined in strInertiaName variable
Dim objSelection As Selection
Set objSelection = PartDoc.Selection

Dim objInertia As Object
Dim strInertiaName As String
strInertiaName = "InertiaVolume.1"

Call objSelection.Search("'Digital Mockup'.Measure.Name='" & strInertiaName & "',all")

If (objSelection.Count = 0) Then
Call MsgBox("No inertia with name " & strInertiaName & " can be found! Exiting...", vbCritical, "Inertia not found")
Exit Sub
ElseIf (objSelection.Count > 1) Then
Call MsgBox("Multiple inertias named " & strInertiaName & " found! Exiting...", vbCritical, "Inertia not found")
Exit Sub
Else
Set objInertia = objSelection.Item(1).Value
End If

' retrieving all parameters related to particular inertia
Dim objInertiaParams As Parameters
Set objInertiaParams = objPartParams.SubList(objInertia, True)

' get parameter called strParamValue (in this case "BBLx")
Dim strParam() As Parameter
Dim objParam() As Parameter
Dim strParamValue() As String
strParam(1) = "Gx"
strParam(2) = "Gy"
strParam(3) = "Gz"

For i = 1 To 3

Set objParam(i) = objInertiaParams.Item(strParam(i))

' get it's value (in a string)

strParamValue(i) = objParam(i).ValueAsString()

Next i

' display value
Call MsgBox("Value of inertia parameter " & strParam(1) & " = " & strParamValue(1))
Call MsgBox("Value of inertia parameter " & strParam(2) & " = " & strParamValue(2))
Call MsgBox("Value of inertia parameter " & strParam(3) & " = " & strParamValue(3))

'Start Excel

Set xlApp = CreateObject("Excel.Application")
'xlApp.Visible = True
'Set xlWB = xlApp.Workbooks.Add ' create a new workbook
' or
Set xlWB = xlApp.Workbooks.Open("D:\Barath\Automation\Trial.xlsx")
'Set xlWB = xlApp.Workbooks.Open("C:\Foldername\Filename.xls")
' open an existing workbook
' example excel operations
With xlWB.Worksheets(1)

For i = 1 To 3
.Cells(i, 1).Value = strParamValue(i)

Next i

xlWB.Save
End With
xlWB.Close False ' close the workbook without saving
xlApp.Quit ' close the Excel application
Set xlWB = Nothing
Set xlApp = Nothing



End Sub

Thanks
Barath :)

 
Replies continue below

Recommended for you

Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top