DiscussionsIssue archiveData Exchange and Application Framework

Archived discussion

Keep Face Labels after rotating object

Data Exchange and Application FrameworkWed, 07/31/2024 - 11:412 replies

Browse this forum
QuestionAuthor

Hello!

I created the following function that can rotate a model and save it to step.

def rotate_model(file_dir, file_name, axis):
    # set reader
    reader = STEPControl_Reader()
    reader.ReadFile(file_dir+file_name)
    reader.TransferRoots()
    shape = reader.OneShape()
    treader = reader.WS().TransferReader()
    topo = TopologyExplorer(shape)
    faces = list(topo.faces())

    # set writer
    file_out = file_dir + "rot_" + file_name
    writer = STEPControl_Writer()
    writer.Transfer(shape, STEPControl_AsIs)
    finderp = writer.WS().TransferWriter().FinderProcess()
    loc = TopLoc_Location()

    # get labels
    for face in faces:
        item_r = treader.EntityFromShapeResult(face, 1)
        if item_r is None:
            print(face)
            continue
        item_r = StepRepr_RepresentationItem.DownCast(item_r)
        name = item_r.Name().ToCString()

        item_w = stepconstruct_FindEntity(finderp, face, loc)
        if name not in label_classes:
            item_w.SetName(TCollection_HAsciiString(0))
        else:
            item_w.SetName(TCollection_HAsciiString(name))

    # rotate model
    trsf = gp_Trsf()
    if(axis == 'Y'):
        trsf.SetRotation(gp.OY(), 1.57)
    elif(axis== 'X'):
        trsf.SetRotation(gp.OX(), 1.57)
    elif(axis== 'Z'):
        trsf.SetRotation(gp.OZ(), 1.57)
    transform = BRepBuilderAPI_Transform(shape, trsf)
    shape = transform.Shape()

    # write
    writer.Write(file_out)

The problem I am having is that the transformation is not saved, because writer.Transfer(shape) is called way earlier. But if I rotate the shape before that I cannot set the labels for the new rotated shape, because stepconstruct_FindEntity always returns None.

Sorry, I am very new to OCCT. Is there a way to solve this problem?

Discussion

2 archived replies

Posts are displayed in their archived order.

01Commenter-1

Hello, as soon as you call "writer.Transfer(shape, STEPControl_AsIs)", the model is prepared. It is not possible to update shapes (tranfromate them). Any Shape modifications needs to be done before Tranfer method.

Best regards, Commenter-1.

02Author

Hi! You are correct. The problem I'm having is that if I rotate the shape and use the Transfer method on the new shape, I cannot transfer the face names of the old shape. Do you know of a way to solve this issue?

Best regards, Jeff