×
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

Bounding Box Macro for Catia V5 from Mark Forbes...

Bounding Box Macro for Catia V5 from Mark Forbes...

Bounding Box Macro for Catia V5 from Mark Forbes...

(OP)
Absolute great macro written by Mark.
Was wondering what line in the code needs changing so the output would be in inches and not MM.
Thanks in advance...
Script below...

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

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

Right underneath these sets of values:

CODE

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


You just need to add in these values:

CODE

'convert units from metric to imperial for box dimensions
xDim = Math.Round((xDim / 25.4), 2) & " in"
yDim = Math.Round((yDim / 25.4), 2) & " in"
zDim = Math.Round((zDim / 25.4), 2) & " in" 

And you're good to go.

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

Bill - apologies. I checked that code in VBA, but should have run it standalone in a CATScript.

Try this. Insert this code in the same place suggested above:

CODE

'convert units from metric to imperial for box dimensions
xDim = (Round((xDim/25.4), 2)) '& " in"
yDim = (Round((yDim/25.4), 2)) '& " in"
zDim = (Round((zDim/25.4), 2)) '& " in" 

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

Great bit of code.
Thanks Bill for posting and Mark for writing.
Does anyone know why the material name isn't showing? It isn't a problem but would be nice to know.

cheers
Alan

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

Do you have any material applied to the part?

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

Yes, tried a few times with different ones.
It's not an issue, I'm just trying to learn to do this stuff and wondered why.
I thought this code worked like the roughstock command giving you the minimum material size.
Unfortunately it seems to create the stock size from the inertia axis.
Still really handy though.

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

It looks that only works well with parts drawn in oriented XYZ axis system. For parts that has a rotation in this axis. the dimensions, are not so well optimized.

But it's a great macro

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

If you have the "core & cavity design" workbench, there is a bounding box function already implemented.

regards,
LWolf

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

I have seen a similar macro that gives you the option to use either the cog axis or by selecting edges to create the axis.
If I remember correctly it encoded so couldn't see how it was done.
Not having a roughstock option in the basic catia software is a bit of a joke. It should be standard.

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

I'll have a look
thanks :)

RE: Bounding Box Macro for Catia V5 from Mark Forbes...

It's been very many years, I did not remember that I had put my name in the header. I don't even remember whether the PortableScriptCenter was the basis for the code, or an inspiration (most likely the former!). But I do remember that this code (as presented) has severe limitations regarding generating data that is actually useful. The only thing I really found useful was to fill in rough values on a table so they would not appear blank. Anything more than that requires actual work and thought smarty

Here's the old thread, for reference:
http://www.eng-tips.com/viewthread.cfm?qid=341826

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


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close