Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Bodies with Material Applied inside a Product

Status
Not open for further replies.

camahiahua

Automotive
Joined
Nov 16, 2010
Messages
4
Location
DE
Hi everyone,

I have a CATProduct and I need to select all the Bodies which have a material applied. I know there are some queries by the search command in order to filter the searchs, but I dont know how to achieve my goal with this query.

What I was doing first, was to select all the Bodies within the Product with the next command

Selection.Search "'Part Design'.Body;all"

And then I am checking each Body at a time to know if there is any material applied.

Set Body = Selection.Item(k).Value
TheMaterialManager.GetMaterialOnBody Body, TheMaterial
Density =TheMaterial.AnalysisMaterial.GetValue("SAMDensity")

if there is no material applied i will get an error by reading the density so with this Err.Number<>0 I know there is no material.

I know my solution is not very elegant, so I am trying to find another method with a query or something

Do you guys know any other way to do this with a query or other method?

Thanks in Advance
 
Hi,

If you want to select only those bodies which doesn't have any material assigned you can use (in CATScript)

Language="VBSCRIPT"

Sub CATMain()

CATIA.StartCommand("Collapse all")

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

selection1.Search "NameInGraph=*Material=None*,all"

End Sub

Regards
Fernando
cadromania.net - Romanian CAD forums
 
Update...

The script above is not so good if you don't have any material applied...in this case I suggest to check the density of each part, usually if you don't have any material, CATIA will apply by default density of 1000.

Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim partDoc As Document
Set partDoc = productDocument1.Part

Dim partRoot As Document
Set partRoot = productDocument1.Part
MsgBox "The density is " & partRoot.Density

End Sub

Regards
Fernando
cadromania.net - Romanian CAD forums
 
Thanks for your help,

what I am doing is to check like ferdo said the density, but in my case the density of all bodies. Because in a Part I could have diferent bodies and maybe one doesnt have any material applied and the density of the Part wouldnt be 1000 (not uniform).

this is the code

Set Inertias = TheSPAWorkbench.Inertias
Selection.Search"'Part Design'.Body;all"

for k = 1 to Selection.Count

Set Body = Selection.Item(k).Value
Set inertia = Inertias.Add (Body)
if Inertia.Density <> 1000 Then
MsgBox(Body.Name & " Doesnt have any materlial properties")
End If
Next
 
So, you want in fact something like this, isn't it?

Sub CATMain()

Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")

Set Inertias = TheSPAWorkbench.Inertias
Set Document = CATIA.ActiveDocument

Dim Selection1 As Selection
Set selection1 = Document.Selection
selection1.Search "Name=*body*,all" 'Or "CATPrtSearch.BodyFeature,all" if you want only PartBody

for k = 1 to Selection1.Count

Set Body = Selection1.Item(k).Value

MsgBox Selection1.Item(k).LeafProduct.Name

Set inertia = Inertias.Add (Body)
if Inertia.Density <> 1000 Then
MsgBox(Body.Name & " Has material properties")

Else

MsgBox Body.Name & "Has NO MATERIAL properties", vbInformation, "NO MATERIAL"

End If

Next

End Sub

Regards
Fernando
cadromania.net - Romanian CAD forums
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top