Showing results for 
Search instead for 
Did you mean: 

Update part (assembly)

Solution Partner Pioneer Solution Partner Pioneer
Solution Partner Pioneer

I have a part with one sketch and one extrude feature based on it.


I need to change expression value (one of sketch's parameters) and update all part(assembly).


I use Python.


# Get the expression by name
expression = self.theSession.Parts.Work.Expressions.FindObject('exp_1')
# Set the undo mark for the current state
markId1 = self.theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Expression")

# Do iteration from min to max values of expression with some step
value = v_min - step
while value < v_max:
    value += step

    # Set a new value for expression
    expression.Value = value

    # Catch the exception if the entire part is failed with update 
        err = self.theSession.UpdateManager.DoUpdate(markId1)
    except Exception as ex:
        # Do something in chase of update failed
        # Roll back to the initial value of exeption
        # We trust initial value. It is updated without errors
        expression.Value = v_init

But it works incorrect. It does not raise an exception if update was failed (the parameter of sketch might be failed).


How to fix this problem?



Re: Update part (assembly)

Had the same problem - the sketches do not raise an Exception when they fail.


You can check them manually, and raise your own exception when that happens.


def checkSketchesForConflictingConstraints(part=None):
    """Sketches with conflicting constraints (e.g. because of expression changes)
    do not raise Exceptions by themselves, but they don't update.
    This function checks all sketches in part and raises an Exception if they are
    in conflict.

    Keyword Args:
        part: Defaults to workPart.
        Exception: If conflicting constraints are found.
    theSession = NXOpen.Session.GetSession()
    if not part:
        part = theSession.Parts.Work
    for sketch in part.Sketches:
        if sketch.GetStatus()[0] == NXOpen.SketchStatus.InconsistentlyConstrained:
            raise Exception("Error: Sketch {} has conflicting constraints".format(sketch))


Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX11 | RHEL7 | Python