×
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 Catia Macro

Need help in Catia Macro

Need help in Catia Macro

(OP)
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 :)

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