Macro for apply material

Anil Sankar

Macro for apply material

Hi

Can u pls provide me code for apply material to a part. i want to create a macro which will add material like steel to a part according to our choice.

Kimmo Takala

RE: Macro for apply material
(in response to Anil Sankar)
There is something
http://www.coe.org/Collaboration/DiscussionForum/ActiveDiscussions/tabid/210/view/topic/forumid/10/postid/108828/Default.aspx

Kimmo Takala

RE: Macro for apply material
(in response to Anil Sankar)
' ***********************************************************************
' Purpose: Apply material properties to Part automatically
' Version: 1.0
' Author: CLM
' Languages: CATScript
' Locales: English
' CATIA version: V5R14
' Date: 5/6/05
' ***********************************************************************

Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim RootPart As Part
Set RootPart = partDocument1.Part

'
' -----------------------------------------------------------
' Open the material library (.CATMaterial file)
' In this case, the default library
' -----------------------------------------------------------
'

Dim FilePath
FilePath = "C:\Program Files\Dassault Systemes\B17\intel_a\startup\materials\Catalog.CATMaterial"

Dim Material_document As Document
Set Material_document = CATIA.Documents.Open(FilePath)
Set Material_document = CATIA.ActiveDocument

'
' -----------------------------------------------------------
' Retrieve the families of materials from the library
' Read the families of materials in this catalog (8 families)
' -----------------------------------------------------------
'

Dim Families_list As MaterialFamilies
Set Families_list = Material_document.Families

Dim Nb_families As Integer
Nb_families = Families_list.Count
Dim FamiliesName As String
FamiliesName = Families_list.Name

'
' -----------------------------------------------------------
' Retrieve the 5th family of the library (Painting family)
' -----------------------------------------------------------
'

Dim Fifth_family As MaterialFamily
Dim family_no As Integer
family_no = 5
Set Fifth_family = Families_list.Item(Family_no)
Dim FamilyName As String
FamilyName = Fifth_family.Name

'
' -----------------------------------------------------------
' Retrieve the material number 14,19 and 33 of the family
' -----------------------------------------------------------
'

Dim Materials_list As Materials
Set Materials_list = Fifth_family.Materials

Dim Nb_materials As Integer
Nb_materials = Materials_list.Count

Dim material_no As Integer
' material 14 is DS Red
material_no = 14
Dim Material14 As Material
Set Material14 = Materials_list.Item(material_no)

material_no = 19
' material 19 is DS Yellow
Dim Material19 As Material
Set Material19 = Materials_list.Item(material_no)

material_no = 33
' material 33 in DS Light Blue
Dim Material33 As Material
Set Material33 = Materials_list.Item(material_no)

Set Manager = RootPart.GetItem("CATMatManagerVBExt")

'
' -----------------------------------------------------------
' Other objects to apply material to are:
' ApplyMaterialOnBody: Apply a material to a body
' ApplyMaterialOnHybridBody: Apply a material to a Hybrid Body
' ApplyMaterialOnProduct: Apply a material to a Product
' -----------------------------------------------------------
'

linkMode = 0
Manager.ApplyMaterialOnPart RootPart,Material33,linkMode

Material_document.Close

RootPart.Update

End Sub

Anil Sankar

RE: Macro for apply material
(in response to Anil Sankar)

Hi KTakala ,

Thanks a lot. That works absolutely fine.

Daniel Pavon

RE: Macro for apply material
(in response to Anil Sankar)
Hi Ktakala,
what's the logic about the numbers?
How can I find out what is the number of a specific material that I want?
Try out and check is not valid =D

Daniel Pavon

Luiz Henrique Silva

RE: Macro for apply material
(in response to Daniel Pavon)

you can retrieve it from its name using string too