PYCATIA sketch update

"I'm currently writing a code that uses pycatia to receive variables from a sketch through Excel and update the CATIA shape. However, when I run the code, the variables from the sketch section are not being updated. I'm unsure about what went wrong and how to correct it. Could you possibly assist me with this issue? The code simply takes the width and height from the sketch to update the pad."

-------------------------------------------------------------------------------------------------------------------------------------------------------------

import os

import sys


sys.path.insert(0, os.path.abspath('..\\pycatia'))

##########################################################


from pycatia import catia

from pycatia.enumeration.enumeration_types import cat_constraint_type, cat_constraint_mode, cat_constraint_angle_sector

from pycatia.mec_mod_interfaces.part import Part

import pandas as pd


# load data from PAD_DIM.xlsx


df = pd.read_excel('PAD_DIM.xlsx')


length = df.loc[0, 'H']

width = df.loc[0, 'W']


caa = catia()

document = caa.documents.open('pad.CATPart')

document = caa.active_document


part = document.part

part = Part(part.com_object)


hybrid_bodies = part.hybrid_bodies

sketches = hybrid_bodies.item(1).hybrid_sketches


catia.refresh_display = True


for i in range(1, sketches.count+1):

sketch=sketches.item(i)

if sketch.name == 'sketch_section':

 

sketch.open_edition()

constraints = sketch.constraints


for j in range(1, constraints.count + 1):

constraint = constraints.item(j)  


print(constraint.name)

 


if constraint.name == 'H':

length__ = constraint.dimension

length__.Value = length # Modify the dimension value

print (length__.Value)



if constraint.name == 'W':

length__ = constraint.dimension

length__.Value = width # Modify the dimension value

print (length__.Value)


sketch.close_edition() # Close the sketch edition


# Update the sketch after modifying the constraints

part.update()


# document.close() # Close the document


# Save the document with a different name

new_document_name = 'D:\\pynew_pad10.CATPart'

document.save_as(new_document_name)