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!

Measure overall dimensions - export to BOM 3

Status
Not open for further replies.

GeorgeIr

Mechanical
Mar 27, 2013
3
RO
thread560-274467

Hi, everyone.
Is there anny fast way to measure the XYZ overall dimensions of a complex part or assembly? When I buildup a BOM I need to put the part dimensions into it and it's painstaking to measure each part. It would be nice to have some settings in the BOM generator from Catia or if some one knows a macro for BOM customization-automatic part overall dimension/rough stock (export to Excel) better yet.


Hi all,

Anyone found a solution for this problem?

Thanks!
 
Replies continue below

Recommended for you

If You do the measure, next step is to define new properties for each part (e.g. XDim, YDim, ZDim, Volume, etc..) and put there (as values) measured values. Finally, You will be able to create customized BOM using those properties (this step doesn't require any Macros).

Do You have any experience in scripting?

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum
 
GeorgeIr said:
and it's painstaking to measure each part

Select main Product
Open Measure Inertia
Click: Customize... Select only Principal Axes the OK
Export and voila! - You will get txt file with listed BBL's dimensions of each Part/Product In Your assembly

Anyway, I've tried method GetTechnologicalObject("Inertia")
and then GetPrincipalAxes PrincipalAxes
but array (15 cells) containing PrincipalAxes has 9 double cells and 6 empty - probable there should be BBL dimension

Any suggestions? It is a bug or my mistake/misunderstanding

Here is a small code
Code:
Sub CATMain()
Set productDocument1 = CATIA.ActiveDocument
MsgBox productDocument1.Product.Products.Item(1).Name
GetProductInertia (productDocument1.Product.Products.Item(1))
End Sub

Sub GetProductInertia(MeasuredProduct)
  Dim PrincipalAxes(15)
   Set ProductInertia = MeasuredProduct.ReferenceProduct.GetTechnologicalObject("Inertia")
 ProductInertia.GetPrincipalAxes PrincipalAxes
 
For i = 0 To 14
MsgBox PrincipalAxes(i) & "  as: " & TypeName(PrincipalAxes(i))
Next

End Sub

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum
 
Hi,

Thanks for your answers, I will try this things in short time(1-2days), and I return with opinions.
I don't have experiences with scripting...

With respect,
George
 
Hi,

This code is retrieving only BBLx value in a CATPart....you can modify the code as you wish...


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 strParamName As String
Dim objParam As Parameter
strParamName = "BBLx"
Set objParam = objInertiaParams.Item(strParamName)

' get it's value (in a string)
Dim strParamValue As String
strParamValue = objParam.ValueAsString()

' display value
Call MsgBox("Value of inertia parameter " & strParamName & " = " & strParamValue)

End Sub

Regards
Fernando

 
Code:
Sub CATMain()
 Dim ProdDoc
 Dim ActProdSel
 Dim ActProd
 Set ActProd = CATIA.ActiveDocument.Product
 Dim Listed
 Listed = ""

 Set ActProdSel = CATIA.ActiveDocument.Selection
For i = 1 To CATIA.Documents.Count
Set ProdDoc = CATIA.Documents.Item(i)

If TypeName(ProdDoc) = "PartDocument" Then
 Set Prod = ProdDoc.Product
Set parameters1 = Prod.UserRefProperties

 ActProdSel.Clear
 ActProdSel.Add ProdDoc.Part

k1 = ActProd.Parameters.Count


 CATIA.StartCommand ("Measure Inertia")
Sleep (2000)
k2 = ActProd.Parameters.Count

For j = k1 + 1 To k2

If Right(ActProd.Parameters.Item(j).Name, 4) = "BBLx" Then

 Xdim = ActProd.Parameters.Item(j).Value
 
 Ydim = ActProd.Parameters.Item(j + 1).Value

 Zdim = ActProd.Parameters.Item(j + 2).Value
End If
 
Next

 
 Err.Clear
  On Error Resume Next
    Set dimension1 = parameters1.Item("BBLx")
    errNumber = CLng(Err.Number)
If errNumber <> 0 Then
Set dimension1 = parameters1.CreateDimension("BBLx", "LENGTH", 0#)
dimension1.Value = Xdim
Else
dimension1.Value = Xdim
End If

 Err.Clear
  On Error Resume Next
    Set dimension2 = parameters1.Item("BBLy")
    errNumber = CLng(Err.Number)
If errNumber <> 0 Then
Set dimension2 = parameters1.CreateDimension("BBLy", "LENGTH", 0#)
dimension2.Value = Ydim
Else
dimension2.Value = Ydim
End If

 Err.Clear
  On Error Resume Next
    Set dimension3 = parameters1.Item("BBLz")
    errNumber = CLng(Err.Number)
If errNumber <> 0 Then
Set dimension3 = parameters1.CreateDimension("BBLz", "LENGTH", 0#)
dimension3.Value = Zdim
Else
dimension3.Value = Zdim
End If


End If
Next

End Sub

I'm working on code that measure, read and export BBl's to PartDocument's properties. Unfortunatelly, it didn't work, because Command "Measure Inertia" Starts only once or twice (depends on no of parts in assy). Any ideas how to fix it? I've been trying sendkeys, pause macro, show msgbox but it didn't get me any closer... I'm waiting for Yours advices

With regards
Lukasz

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
I accomplished this task by doing this sequence:
Open each part in the assembly in its own window,
Select the part object,
Measure the inertia,
Pull out the values I wanted and write them to custom properties,
Save the part,
Then close that part window,
Repeat for each part.

I found a several things though that you should consider:
First, I couldn't figure out how to close the measure dialog. The hack way to close it that seems to work is to run the save command.
Second, if the part already had a measure saved in it, then the solution could be suspect. (I didn't have the checking for multiples that Ferdo has, above)
Third, after processing several parts (maybe one or two hundred?) Catia could become unstable and quit responding. The better solution to this was to run the script based on all parts in a folder (open and close each file one at a time). The other better solution was to run on the user-selected part one at a time.
Fourth, it would get the bounding box based on the finished solid's principle axes, and not in any kind of deliberate orientation like say what you would make a drawing view of.

I don't claim the best way, but it seemed to work halfway well. I could probably post the code tomorrow when I get to the office.

Last point, and this is important - check the purpose of filling this information into your BOM! If the purpose is to get "normal" dimensions, this method won't work for you. You the designer need to pick which measurement directions are valid. If the purpose is to list the stock material that the part should be made from, this method will not deliver correct results. However, if your purpose is to fill in "something" so that your customer looks at the table and doesn't see a bunch of blanks, and no one will really look at it later anyway, then this is the ticket.

Cheers,

Mark
 
Here is the code I made for handling a single part. I had a couple other variations, but it's all based on the same idea and methods. When you run the macro from your assembly, you need to pick a part (from the tree or from 3D) and then it will operate on that level.
There were some specific bits in here about materials that were managed by our PDM system, you can find those and delete if you wish. It was relevant to me because we were supposed to fill that information into customer BOMs along with the X/Y/Z values.


Code:
'Bounding Box Macro
'This function applies the geometric properties length, width, height
'Written by Mark Forbes
'Assumptions: PDB_MASS filled in by pdm system, Definition filled in as Material by pdm

Option Explicit

Sub CATMain()

On Error Resume Next

Dim oPartDoc As PartDocument
Dim oCurrentDoc As Document
Dim oPart As Product
Dim oInertia As Inertia
Dim InputObjectType(1) As Variant
Dim Status As String
Dim oSelection As Variant
Dim bCloseDoc As Boolean

Set oCurrentDoc = CATIA.ActiveDocument

'Exclude Drawings
If Right(oCurrentDoc.Name, 4) = "wing" Then
    MsgBox "This function only operates on a part or product"
    Exit Sub
End If


Set oSelection = oCurrentDoc.Selection

If Right(oCurrentDoc.Name, 4) = "Part" Then
    Set oPart = oCurrentDoc.Product
    oSelection.Add oPart
    GoTo RunBBOpenWindow
End If


If Right(oCurrentDoc.Name, 4) = "duct" Then
        bCloseDoc = True
        InputObjectType(0) = "Part"
        InputObjectType(1) = "Product"
        oSelection.Clear
        Status = oSelection.SelectElement2(InputObjectType, "Pick a Part, Escape to Cancel", False)
        If Status = "Cancel" Then Exit Sub
        Set oPart = oSelection.Item2(1).LeafProduct.ReferenceProduct
        If oPart.Name = oCurrentDoc.Product.Name Then
            bCloseDoc = False
            GoTo RunBBOpenWindow
        End If
        CATIA.StartCommand "open in new window"
End If

RunBBNewWindow:

Set oPart = CATIA.ActiveDocument.Product
Dim oSelection2
Set oSelection2 = CATIA.ActiveDocument.Selection
oSelection2.Add oPart

RunBBOpenWindow:


CATIA.StartCommand "Measure Inertia"

Dim xDim As String
Dim yDim As String
Dim zDim As String

xDim = oPart.Parameters.GetItem("BBLx").Value
yDim = oPart.Parameters.GetItem("BBLy").Value
zDim = oPart.Parameters.GetItem("BBLz").Value

xDim = CStr(Round(xDim, 0))
yDim = CStr(Round(yDim, 0))
zDim = CStr(Round(zDim, 0))

Dim oMatParam As Parameter
Dim sMatParam As String
Set oMatParam = oPart.Parameters.GetItem("Definition")

sMatParam = oMatParam.ValueAsString

Dim oMassParam As Parameter
Dim sMassParam As String
Set oMassParam = oPart.UserRefProperties.GetItem("PDB_MASS")


sMassParam = oMassParam.ValueAsString
If sMassParam = "" Then sMassParam = "0"

If sMassParam = "0" Then
    sMassParam = ""
    If Right(CATIA.ActiveDocument.Name, 4) = "Part" Then
        Set oInertia = oPart.GetTechnologicalObject("Inertia")
        
        Select Case oInertia.Density
        
            Case 0
                sMassParam = ""
                
            Case 1000
                sMassParam = ""
            
            Case Else
                sMassParam = CStr(Round(oInertia.Mass, 1))
                   
        End Select
               
    End If
    
End If


CATIA.StatusBar = "Start Creating Params"

Call SetParam(oPart, "LENGTH", xDim)
Call SetParam(oPart, "WIDTH", yDim)
Call SetParam(oPart, "THICKNESS/DIAMETER", zDim)
Call SetParam(oPart, "MATERIAL", sMatParam)
Call SetParam(oPart, "MASS", sMassParam)


MsgBox "Properties Applied:" & _
        vbCrLf & "LENGTH: " & xDim & _
        vbCrLf & "WIDTH: " & yDim & _
        vbCrLf & "THICKNESS/DIAMETER: " & zDim & _
        vbCrLf & "MATERIAL: " & sMatParam & _
        vbCrLf & "MASS: " & sMassParam & _
        vbCrLf & "Check Results Carefully!", vbOKOnly, oPart.Name

CATIA.DisplayFileAlerts = False
CATIA.StartCommand "Save"
'CATIA.ActiveDocument.Save
CATIA.DisplayFileAlerts = True


If bCloseDoc = True Then CATIA.ActiveDocument.Close

CATIA.StatusBar = "Macro Finished"

End Sub

Sub SetParam(ByRef oPart As Product, Name As String, Value As String)

On Error GoTo CreateParam
Dim sParam As Parameter
Err.Clear

Set sParam = oPart.UserRefProperties.GetItem(Name)
sParam.ValuateFromString CStr(Value)
    
GoTo Finish
    
CreateParam:
oPart.UserRefProperties.CreateString Name, CStr(Value)

Finish:


End Sub
 
Hi all,

Idea was to take this dimensions for all parts from product and put them in BOM. Your script, I understand that take dimensions for only one part...but if you select each part from product, one after one, the values is in same BOM? or in other BOM file?


Thanks,
With respect,

 
Yes, this script only operates on one selection. I made a couple other variations, for example working on every file in a folder. The X/Y/Z values are written into the part properties. Afterward, the CATIA BOM export can use the part properties to export to Excel. Acutally doing the BOM export is an additional step, but now that information is available to be used in each part.

I only showed one way to approach your problem (others showed other methods also), and it's only a part of the whole process. I hope also you will understand the limitations to this approach, and why it might easily give you wrong information.

Cheers,
Mark
 
Hi,

Mark gives a good point of view regarding Bounding Box , everything is related to how you want to get those dimensions....a star from me for this and for code.

To see very clear which are the risks, see picture attached, right hand are values coming from measure inertia, left hand values coming from the macro which is in CATIA Portable Script Center (with pick of a local axis when starting the macro).

The approach can be different, depending also if you have a PDM system or not, if you want to have everything parametric or not a.s.o.

Personally I would prefer to have parameters in CATPart properties which could be update at each modification of the part but this depends also by the rules imposed by each company when creating the parts....

Of course, a macro can be done to make it run in a CATProduct, here you have the examples, we are waiting to see your code and help you with you have problems to finish. Creating a macro is taking time....

Regards
Fernando

 
If You want to keep User ref properties up-to-date with Yours model changing, The best approach in My opinion is to create formulas that connect User RefProp with InertiaMeasure (another advantage is that You can choose specified bodies that beinge masured)

here is example code ( anyway - CATIA doesn't offer to set formula for User Ref Properties without scripting, but You probably know this approach)


1. Open a part
2. Measure Inertia
3. Rename Your Measure to "MeasureForBoundingBox"
4. Run Macro

Code:
Option Explicit

Sub CATMain()

Dim oCurrentDoc As Document
Dim oPartProd As Product
Dim oPart As Part
Dim ProdParams As Parameters
Dim oPartRelations As Relations
Dim PartFormula1 As Formula
Dim PartFormula2 As Formula
Dim PartFormula3 As Formula
Dim paramDimension1 As Dimension
Dim paramDimension2 As Dimension
Dim paramDimension3 As Dimension

Set oCurrentDoc = CATIA.ActiveDocument


    Set oPartProd = oCurrentDoc.Product
    Set oPart = oCurrentDoc.Part
    
Set ProdParams = oPartProd.UserRefProperties
Set oPartRelations = oPart.Relations

Set paramDimension1 = ProdParams.CreateDimension("BBLx", "LENGTH", 0#)
Set PartFormula1 = oPartRelations.CreateFormula("BBLx_formula", "", paramDimension1, "MeasureForBoundingBox\BBLx")

Set paramDimension2 = ProdParams.CreateDimension("BBLy", "LENGTH", 0#)
Set PartFormula2 = oPartRelations.CreateFormula("BBLy_formula", "", paramDimension2, "MeasureForBoundingBox\BBLy")

Set paramDimension3 = ProdParams.CreateDimension("BBLz", "LENGTH", 0#)
Set PartFormula3 = oPartRelations.CreateFormula("BBLz_formula", "", paramDimension3, "MeasureForBoundingBox\BBLz")


End Sub

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top