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

isMaterial

bool

readonly

bool

required

str

type

NoneType

Method Table#

Name

Description

castForGet (self, obj, value)

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)#

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

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 attribute value to its external type.

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

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

Returns:

Converted value.

Return type:

value (Any)

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.