Search code examples
pythonabaqus

canvasObjects; found PartInstance, expecting tuple in Abaqus/CAE


I'm developening an Abaqus/CAE plug-in, in this plug-in i'm using the gui toolkit, and i have a button that uses the PickStep, on click the button i can select a PartInstance in the viewport.

Then i want to export the selected PartInstance to an .obj file but when i try it, abaqus displays an error.

This is an example of my PICK BUTTON:

        # PICK BUTTON 1
        pickHf = FXHorizontalFrame(p=col2, opts=0, x=0, y=0, w=0, h=0, pl=0, pr=0, pt=0, pb=0, hs=DEFAULT_SPACING,
                                   vs=DEFAULT_SPACING)
        # Note: Set the selector to indicate that this widget should not be
        # colored differently from its parent when the 'Color layout managers'
        # button is checked in the RSG Dialog Builder dialog.
        pickHf.setSelector(99)
        label1 = FXLabel(p=pickHf, text='' + ' (None)', ic=None, opts=LAYOUT_CENTER_Y | JUSTIFY_LEFT)

        pickHandler1 = DBPickHandler(form, form.uper, 'Select a 3D, discrete and dependent meshed instance', INSTANCES,
                                     1, label1)
        icon = afxGetIcon('select', AFX_ICON_SMALL)
        FXButton(p=pickHf, text='\tPick Items in Viewport', ic=icon, tgt=pickHandler1, sel=AFXMode.ID_ACTIVATE,
                 opts=BUTTON_NORMAL | LAYOUT_CENTER_Y, x=0, y=0, w=0, h=0, pl=2, pr=2, pt=1, pb=1)

I save the value in an ObjectKeyword:

self.uper = AFXObjectKeyword(self.cmd, 'uper', True, pickedDefault)

This is how i export the PartInstance to .obj:

    print 'Uper - ' + uper[0].name
    f.write('Uper - '+uper[0].name+'\n')
    session.writeOBJFile(fileName='C:/temp/Uper.obj', canvasObjects=(uper[0]))

That displays and error, and i also tried this:

print 'Fixed - ' + fixed[0].name
    f.write(fixed[0].name+'\n')
    fixedobj = open('Fixed.obj', 'w')
    pickle.dump(fixed[0], fixedobj)
    fixedobj.close()

But that does not work either.

I get this error:
canvasObjects;found PartInstance, expecting tuple


Solution

  • This answer will help you. On your call to session.writeOBJFile you are trying to create a one element tuple for the canvasObjects argument. Simply wrapping the item in parentheses won't achieve that. You need to add a comma to make it a tuple:

    session.writeOBJFile(fileName='C:/temp/Uper.obj', canvasObjects=(uper[0],))
    

    The Abaqus documentation says this about canvasObjects:

    canvasObjects

    A sequence of canvas objects to export.

    I'm not sure if PartInstance is considered a canvas object or not, but you may still have problems even after correcting the argument to be a tuple. If so, make sure the items of the tuple are proper canvas objects.