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!

Formulas using macro 1

Status
Not open for further replies.

Costin Ruja

Electrical
Oct 19, 2011
87
RO
Good morning !

I need to link the native parameters in a part (part number, revision, definition...) to some other additional parameters which I have made.

I have a working script to generate these additional parameters, script that is made using the record function. It works fine, but then I have to input the formulas by hand.

Can you guys advise me how to make another script to automatically generate also the formulas ?

Below you can find the sample code to generate the additional parameters.

Code:
ub CATMain()Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim product1 As CATBaseDispatch
Set product1 = partDocument1.GetItem("Part1")

Dim parameters1 As Parameters
Set parameters1 = product1.UserRefProperties

Dim strParam1 As StrParam
Set strParam1 = parameters1.CreateString("Denumire", "")

strParam1.ValuateFromString "Brida"

Dim parameters2 As Parameters
Set parameters2 = product1.UserRefProperties

Dim strParam2 As StrParam
Set strParam2 = parameters2.CreateString("Cod specificatie", "")

strParam2.ValuateFromString "16100-L2-001"

Dim parameters3 As Parameters
Set parameters3 = product1.UserRefProperties

Dim strParam3 As StrParam
Set strParam3 = parameters3.CreateString("Descriere", "")

strParam3.ValuateFromString "Foaie de carton electrotehnic gros 10mm"

Dim parameters4 As Parameters
Set parameters4 = product1.UserRefProperties

Dim strParam4 As StrParam
Set strParam4 = parameters4.CreateString("Nomenclator", "")

strParam4.ValuateFromString "Placi, blocuri, foi"

Dim parameters5 As Parameters
Set parameters5 = product1.UserRefProperties

Dim strParam5 As StrParam
Set strParam5 = parameters5.CreateString("Unitate de masura", "")

strParam5.ValuateFromString "kg"

Dim parameters6 As Parameters
Set parameters6 = product1.UserRefProperties

Dim strParam6 As StrParam
Set strParam6 = parameters6.CreateString("CATMaterial", "")

strParam6.ValuateFromString "IEC 60641-3-1 B 3.1A"

Dim parameters7 As Parameters
Set parameters7 = product1.UserRefProperties

Dim strParam7 As StrParam
Set strParam7 = parameters7.CreateString("Standard", "")

strParam7.ValuateFromString "Weidmann"

Dim parameters8 As Parameters
Set parameters8 = product1.UserRefProperties

Dim strParam8 As StrParam
Set strParam8 = parameters8.CreateString("Producator", "")

strParam8.ValuateFromString "…"

Dim parameters9 As Parameters
Set parameters9 = product1.UserRefProperties

Dim strParam9 As StrParam
Set strParam9 = parameters9.CreateString("ID", "")

strParam9.ValuateFromString "CuE"

Dim parameters10 As Parameters
Set parameters10 = product1.UserRefProperties

Dim realParam1 As RealParam
Set realParam1 = parameters10.CreateReal("Densitate", 0.000000)

realParam1.ValuateFromString "1250.1"

Dim parameters11 As Parameters
Set parameters11 = product1.UserRefProperties

Dim realParam2 As RealParam
Set realParam2 = parameters11.CreateReal("Volum brut", 0.000000)

realParam2.ValuateFromString "1250.1"

Dim parameters12 As Parameters
Set parameters12 = product1.UserRefProperties

Dim realParam3 As RealParam
Set realParam3 = parameters12.CreateReal("Volum net", 0.000000)

realParam3.ValuateFromString "1250.1"

Dim parameters13 As Parameters
Set parameters13 = product1.UserRefProperties

Dim realParam4 As RealParam
Set realParam4 = parameters13.CreateReal("Masa bruta", 0.000000)

realParam4.ValuateFromString "1250.1"

Dim parameters14 As Parameters
Set parameters14 = product1.UserRefProperties

Dim realParam5 As RealParam
Set realParam5 = parameters14.CreateReal("Masa neta", 0.000000)

realParam5.ValuateFromString "1250.1"

End Sub

As for an example, how would the code look if i want to add some formulas which state

Part number = Cod specificatie
Description = Descriere
CATmaterial = Material





Best regards,
Costin Ruja
 
Replies continue below

Recommended for you

Hi

Short example, hope I understood what you want to do.

Capture_sj4gta.jpg


Code:
Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim product1 As CATBaseDispatch
Set product1 = partDocument1.GetItem("1")

Set product1 = product1.ReferenceProduct



'~ '''''''''''''''''''
msgbox "Please select a parameter in what InertiaVolume you want to use in spec. tree "

Set Selection = partDocument1.Selection
Dim InputObjectType(0) 

InputObjectType(0)="AnyObject" 

     Status=Selection.SelectElement2(InputObjectType,"Select an element",false)
     if (Status="Cancel") then
         Selection.Clear : Exit Sub
     end if
     
     Set myselection= Selection.Item(1).Value
    
InVol = myselection.name

strLastName = Trim ( Mid( InVol, Instr(InVol, "\")+1) ) 

SplitPath = Split(strLastName,"\")
MyInVol = SplitPath(Lbound(SplitPath))
msgbox "You will use : " & MyInVol

'~ '''''''''''''''''''''''''

'material user parameter

Dim parameters3 As Parameters
Set parameters3 = product1.UserRefProperties

Dim strParam4 As StrParam
Set strParam4 = parameters3.CreateString("Material", "")

strParam4.ValuateFromString ""

Set product1 = product1.ReferenceProduct

'~ Dim part1 As Part
Set part1 = partDocument1.Part

Dim relations3 As Relations
Set relations3 = part1.Relations

Dim formula3 As Formula
Set formula3 = relations3.CreateFormula("Formula.7", "", strParam4, "PartBody\Material ")

formula3.Rename "Formula.7"

'volum user parameter

Dim parameters1 As Parameters
Set parameters1 = product1.UserRefProperties

Dim realParam2 As RealParam
Set realParam2 = parameters1.CreateReal("volum", 0.000000)

realParam2.ValuateFromString "0"

Dim relations1 As Relations
Set relations1 = part1.Relations

Dim formula1 As Formula
Set formula1 = relations1.CreateFormula("Formula.5", "", realParam2, "InertiaVolume.1\Volume ")

formula1.Rename "Formula.5"

'masa user parameter

Dim parameters2 As Parameters
Set parameters2 = product1.UserRefProperties

Dim realParam3 As RealParam
Set realParam3 = parameters2.CreateReal("masa", 0.000000)

realParam3.ValuateFromString "0"

Dim relations2 As Relations
Set relations2 = part1.Relations

Dim formula2 As Formula
Set formula2 = relations1.CreateFormula("Formula.6", "", realParam3, "InertiaVolume.1\Mass ")

formula2.Rename "Formula.6"



part1.Update 

End Sub

Regards
Fernando

- Romania
- EU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top