Reference (hwx.inspire.Attributes)#

class Reference(type=None, **kwds)#

Bases: Attribute

Store a Named entity or Feature.

Use List or ListOfList(Reference) to store multiple values.

Default for references is not currently supported.

Attribute Table#

Name

Type

readonly

bool

required

str

type

NoneType

Method Table#

Name

Description

castForGet (self, obj, value)

Converts and returns the reference value to its external type.

castForSet (self, obj, value)

create (self, obj)

createList (self, listAttr, obj)

createListList (self, listAttr, obj)

getGuiValue (self, obj)

getReferences (self, obj)

getValue (self, obj)

getValueList (self, obj)

getValueListList (self, obj)

populateGuiValue (self, obj, prop)

setValue (self, obj, value)

setValueList (self, obj, value)

setValueListList (self, obj, value)

Example

from hwx.inspire import *

class Obj(GeneralObject):
part    = Reference(Part)
feature = Reference(Feature)

model = newModel()
box = model.createSolidBlock()
cyl = model.createSolidCylinder()
face = cyl.getFeatures(FeaturePlanar)[0]

# Object referencing a part and a feature
obj = Obj(part=box, feature=face)

# Get objects referenced through all attributes
print(obj, 'references', obj.getReferences())
print(box, 'is referenced by', box.getDependents())

# Certain state is propagated to all objects that reference it

def cascadeDestroy():
# Destroying box destroys obj
box.destroy()
assert obj._deleted

def cascadeFeatureDestroy():
# Removing feature destroys obj
# Push pull obj.feature out of existence
obj.feature.pushPull(-1)
assert obj._deleted

def cascadeActiveness():
# obj is inactive if any references are inactive
box.active = False
assert not obj.active

def cascadeVisibility():
# obj is hidden if all its references are hidden
box.visible = False
assert obj.visible # still has a visible reference
cyl.visible = False
assert not obj.visible

# cascadeDestroy()
# cascadeFeatureDestroy
# cascadeActiveness()
cascadeVisibility()
create(obj)#

Creates a attribute for the specified object.

Overridden by the child class create method.

castForSet(obj, value)#

Converts and validates the value of the attribute before setting.

Converts the value it to its internal type (and base units if applicable).

Parameters:
  • obj (GeneralObject) – Object this attribute belongs to.

  • value (Any) – Value of the attribute to set.

Returns:

Validated and converted value.

Return type:

value (Any)

castForGet(obj, value)#

Converts and returns the reference value to its external type.

Parameters:
  • obj (GeneralObject) – Object this attribute belongs to.

  • value (Named) – Value of the attribute to be converted.

Returns:

Converted value.

Return type:

Named | Feature

populateGuiValue(obj, prop)#

Override to customize, prop.value, displayValue, allowedValues.

The prop.value type determines which editor widget used: - bool -> checkbox - str -> line edit - hwtypes.Color -> color picker

Setting prop.allowedValues yields a ComboBox.

prop.displayValue is a str shown when the editor loses focus.

getGuiValue(obj)#

Returns the formatted value, as shown in the Property Editor.

getValue(obj)#

Returns the attribute value of the specified object.

setValue(obj, value)#

Sets the value for the specified object attribute.

createList(listAttr, obj)#

Creates an attribute that has list of values for the specified object.

getValueList(obj)#

Returns the list of values from the specified object.

setValueList(obj, value)#

Sets the specified list of values for the attribute.

createListList(listAttr, obj)#

Creates an attribute that has nested list of values for the specified object.

getValueListList(obj)#

Returns the nested list of values from the specified object.

setValueListList(obj, value)#

Sets the specified nested list of values for the attribute.