Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

Register Log in

CATIA MACRO

girishksmvk

New member
HI
NEED HELP IN GETTING EXPORTING INERTIA VALUE(IozG)
FROM CATIA TO MS.EXCEL USING CATVBA SCRIPT.
SAMPLE CODE GIVEN BELOW. BUT GETTING INERTIA IS NOT
WORKING.
PLS HELP

==================================


Language="VBSCRIPT"
Sub CATMain()
' ******************************* test if product is open
*****************************
If CATIA.Documents.Count = 0 Then
MsgBox "There is no CATIA Documents open. Open a
Product file and run this script again.", ,msgboxtext
Exit Sub
End If
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1
Then
MsgBox "Active CATIA Document is not a Product. Open
a Product file and run this script again.", ,msgboxtext
Exit Sub
End If
' ******************************* variables
*******************************************
Set cad = CATIA.ActiveDocument
Set sel = cad.selection
set prod=cad.Product.Products
'msgboxtext="e3bom - Bill of Material"
dim tab(4,1999)
k=0
' ******************************* test if some parts is
selected **********************
If sel.count =0 Then
MsgBox "No any parts for BOM is selected. Select some
parts and run this script again.", ,msgboxtext
Exit Sub
End If
If sel.count >=1999 Then
MsgBox "Number of selected parts for BOM exceeds
1999. Program error.", ,msgboxtext
Exit Sub
End If
' ******************************* load
************************************************
for i=1 to prod.count
for j=1 to sel.count
if prod.item(i).name=sel.item(j).reference.name
then
k=k+1
tab(1,k)=prod.item(i).PartNumber
tab(2,k)=sel.item(j).reference.name
tab(3,k)=prod.item(i).DescriptionRef
tab(4,k)=1
end if
next
next
' ******************************* sort
************************************************
if k>1 then
for i=1 to k-1
for j=i+1 to k
if tab(1,i)>tab(1,j)then
tab(1,1999)=tab(1,j)
tab(2,1999)=tab(2,j)
tab(3,1999)=tab(3,j)
tab(4,1999)=tab(4,j)
tab(1,j)=tab(1,i)
tab(2,j)=tab(2,i)
tab(3,j)=tab(3,i)
tab(4,j)=tab(4,i)
tab(1,i)=tab(1,1999)
tab(2,i)=tab(2,1999)
tab(3,i)=tab(3,1999)
tab(4,i)=tab(4,1999)
end if
next
next
' ******************************* count
***********************************************
for i=1 to k-1
for j=i+1 to k
if tab(1,i)=tab(1,j) and j<=k then
tab(1,j)=tab(1,k)
tab(2,j)=tab(2,k)
tab(3,j)=tab(3,k)
tab(4,j)=tab(4,k)
tab(4,i)=tab(4,i)+1
k=k-1
end if
next
next
end if
' ******************************* output to excel
*************************************
'for i=1 to k
'msgbox i & " " & tab(1,i) & " " & tab(2,i) & " " &
tab(3,i) & " " & tab(4,i)
'next
Dim xlApp
Err.Clear
On Error Resume Next
' set xlApp = GetObject(,"com.sun.star.ServiceManagerR")
set xlApp = GetObject(,"EXCEL.Application")
if Err.Number <> 0 Then
Err.Clear
'Set xlApp = CreateObject("com.sun.star.sheet")
Set xlApp = CreateObject("EXCEL.Application")
end If
xlApp.Visible = True
xlApp.Workbooks.Add
if Err.Number <> 0 Then
msgbox "Can't open excel.", ,msgboxtext
workbook.Close
xlApp.Quit
end if
row=2
col=1
xlApp.Cells(row, col+1).Value = "BILL OF MATERIALS"
xlApp.Cells(row, col+1).Font.Bold = true
xlApp.Cells(row, col+1).Font.Size = 15
xlApp.Cells(row, col+1).Font.ThemeColor =
xlThemeColorLight1
xlApp.Cells(row, col+1).Font.Color = -11489280

col=0
xlApp.Cells(row, col+1).Font.Bold = true

row=4
xlApp.Cells(row, col+1).Value = "PART NO"
xlApp.Cells(row, col+2).Value = "PART NAME"
xlApp.Cells(row, col+4).Value = "QUANTITY."
xlApp.Columns.Columns(3).Columnwidth = 30
xlApp.Columns.Columns(4).Columnwidth = 50
for i=1 to 8
xlApp.Cells(row,col+i).Interior.Colo rIndex = 40
xlApp.Cells(row,col+i).Font.Bold = true
xlApp.Cells(row,col+i).HorizontalAli gnment = 3
xlApp.Cells(row,col+i).borders.LineS tyle = 1
xlApp.Cells(row,col+i).borders.weigh t = -4138
next

for i=1 to k
xlApp.Cells(row+i,col+1).Value = tab(1,i)
xlApp.Cells(row+i,col+2).Value = tab(2,i)
xlApp.Cells(row+i,col+3).Value = tab(3,i)
xlApp.Cells(row+i,col+4).Value = tab(4,i)
for j=1 to 8
xlApp.Cells(row+i,col+j) .Interior.ColorIndex = 19
xlApp.Cells(row+i,col+j) .Font.Bold = false
xlApp.Cells(row+i,col+j) .borders.LineStyle = 1
next
next
xlApp.Cells(row+i,col).Select

















row=0
col=5
xlApp.Cells(1,4).Select
xlApp.Columns.Columns(col+0).Columnwidth = 22
xlApp.Columns.Columns(col+1).Columnwidth = 10
xlApp.Columns.Columns(col+2).Columnwidth = 10
xlApp.Columns.Columns(col+3).Columnwidth = 10
xlApp.Columns.Columns(col+4).Columnwidth = 10
xlApp.Cells(row,col+0).Value = msgboxtext

xlApp.Cells(row,col+0).Font.Bold = true&n bsp;
row=row+2
xlApp.Cells(row,col+0).Value = "Main product name: " &
CATIA.ActiveDocument.name
xlApp.Cells(row,col+0).Font.Bold = true&n bsp;

row=row+2
xlApp.Cells(row,col+0).Value = "PART NAME"
xlApp.Cells(row,col+1).Value = "MASS (Kg)"
xlApp.Cells(row,col+2).Value = "VOLUME (mm3)"
xlApp.Cells(row,col+3).Value = "INERTIA "
xlApp.Cells(row,col+0).HorizontalAlignment = 3
xlApp.Cells(row,col+1).HorizontalAlignment = 3
xlApp.Cells(row,col+2).HorizontalAlignment = 3
xlApp.Cells(row,col+3).HorizontalAlignment = 3
xlApp.Cells(row,col+4).HorizontalAlignment = 3
xlApp.Cells(row,col+0).Font.Bold = true
xlApp.Cells(row,col+1).Font.Bold = true
xlApp.Cells(row,col+2).Font.Bold = true
xlApp.Cells(row,col+3).Font.Bold = true
xlApp.Cells(row,col+4).Font.Bold = true
row=row+1

set cad=CATIA.ActiveDocument
Set spa=cad.GetWorkbench("SPAWorkbench")
set docs=CATIA.Documents
set prod = cad.Product
set prods = prod.Products



for i=1 to prods.count

MASS=prods.item(i).Analyze.mass
vol=prods.item(i).Analyze.Volume
prtNum =prods.Item(i).PartNumber


inertia=prods.Item(i).GetTechnologicalObject("Inertia")



xlApp.Cells(row,col+0).Value = prtNum
xlApp.Cells(row,col+1).Value = MASS
xlApp.Cells(row,col+2).Value = vol
xlApp.Cells(row,col+3).Value = inertia(5)
xlApp.Cells(row,col+4).Value = cog(2)
row=row+1


next







End Sub
=============================================
 

Sponsor

Top