0

I'm trying to alter a user selected parameter of a selected CATPart in an assembly via CADSelection. Ultimatelly this will go into a GUI in VBA and the user will, select the CATPart, open the macro and via the GUI change whatever parameters he requires. I've recorded the macro and tweaked around with this for a while now, but i can't seem to finish this.

My tree is:

Product;

-Part;

-Part_Teste_2;

-Part_Teste_3;

-Part_Teste_4;

-Part_Teste_5;

All of the above "Part_Teste" have 3 parameters one of them is called "Comprimento"

How do I change make sure that the macro alters the selected CATPArt's parameter instead of ("Part_Teste_3.CATPart")?

The macro that I have so far is:

Language="VBSCRIPT"

Sub CATMain()

Set oProductDoc = CATIA.ActiveDocument

Set oProd = oProductDoc.Product

Set oDocs = CATIA.Documents

Set oSelection = CATIA.ActiveDocument.Selection

If oSelection.Count < 1 then

    MsgBox "Pick some components using cad selection.","No components were selected"

Else

    Set oPartDoc = oDocs.Item("Part_Teste_3.CATPart")

    Set oPart = oPartDoc.Part

    Set oParam = oPart.Parameters

    Set oLength = oParam.Item("Comprimento")

    oLength.Value = 50.000000

End If

oSelection.Clear

oProd.Update

End Sub
Castella
  • 3
  • 1
  • 7

1 Answers1

0

When you select in an assembly, the LeafProduct property of the SelectedEntity object returned by Selection.Item() will contain the instance product owning the selected object.

So, if you are selecting something which belongs to a part while working in an assembly, get the instance product of the part...

Dim oInstProd as Product 
Set oInstProd = oSel.Item(1).LeafProduct

Then from there get the part object:

Set oPart = oInstProd.ReferenceProduct.Parent.Part
C R Johnson
  • 964
  • 1
  • 5
  • 12