What's new

How to access the owner of a parameter in a part through API?

DannyG72

New Member
Looking at the Equation Editor, I can see multiple parameters.
i.e. A1, A2.... with Equations, Result, Type, Owner, Source, Comment.

Iterating through the parameters in the file:
The owner value is missing.

Code:
part = CurrentPart()
for i in range(len(part.Parameters)):
    print(dir(part.Parameters[i]))

['AttachToExcel', 'Comment', 'Equals', 'Equation', 'ExcelCell', 'ExcelSheet', 'ExcelWorkbook', 'GetHashCode', 'GetType', 'MemberwiseClone', 'Name', 'RawValue', 'ReferenceEquals', 'ToString', 'Type', 'Units', 'Value', '_Parameter', '_Session', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']


If the owner column isn't available here, Is it possible to go the other way? i.e. iterate through the planes in the part, then find Plane.defined_by...A1 ?
I want to programatically update A1 to a new value.
 
Last edited:

stepalibre

Alibre Super User
iterate through the planes in the part, then find Plane.defined_by...A1 ?
Planes are inside the DesignSession. You can call DesignSession.DesignPlanes.Item("eee").Parameters to get the parameters of a plane. This is true for other collections.

You can update a parameter by name:
Python:
part = CurrentPart()
aa = part.GetParameter("A1")
aa.Value = 100

Is the goal to update a specific plane's parameter by name?
Plane -> BasePlatePlane1 -> Parameter -> A1 -> Value -> 2.5

I use the comment column to add more data to parameters, see "eee" plane below. Adding the owner to a parameter comment is a nice way to know the owner from the API. The owner is the feature where the parameter is being used. You access the feature to get its parameters, if the API allows it.

1714669496437.png
1714670686278.png
 
Last edited:

stepalibre

Alibre Super User
Example code converted from VB.Net to IronPython:
Python:
import sys
import clr
sys.path.append(r"C:\Program Files\Alibre Design 27.0.1.27039\Program")
sys.path.append("C:\Program Files\Alibre Design 27.0.1.27039\Program\Addons\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal
alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
import AlibreScript
from AlibreScript.API import *
myPart = Part(root.TopmostSession)
session = root.Sessions.Item(0)
DesignSession = session
try:
    plane_count = DesignSession.DesignPlanes.Count
    for i in range(plane_count):
        plane = DesignSession.DesignPlanes.Item(i)
        name = plane.Name
        #print(name)
        if name not in ["XY-Plane", "YZ-Plane", "ZX-Plane"]:
            print("Owner: {0}".format(name))
            print("Number of parameters: {0}".format(plane.Parameters.Count))
            first_param = plane.Parameters.Item(0)
            print("Parameter Name: {0}".format(first_param.Name))
except Exception as e:
    print("Error iterating over DesignPlanes: {0}".format(str(e)))
1714674932163.png
 
Top