ExportImage Does Not Include Family Instance

I’m trying to create images of family types placed in the project. When I run this the images show up blank. I’ve placed some detail lines to make sure I’m capturing the correct area. I also commented out the delete method and they still do not print despite being able to see them in the image area after the script runs.

t.Start()

# desktopPath = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
testPath = "L:/Revit/Development/Issues/3 - Examples/2024-11-06 - Elec - Electrical Legend Tests/Family Images"

imgOption = ImageExportOptions()
imgOption.ZoomType = ZoomFitType.Zoom
imgOption.Zoom = 100
imgOption.PixelSize = 300
imgOption.SetViewsAndSheets([views[0].Id])
imgOption.ExportRange = ExportRange.SetOfViews

imgOption.HLRandWFViewsFileType = ImageFileType.JPEGMedium

types = []
for eT in eTypes:
    types.append(family.Document.GetElement(eT))

for eT in types:
    typeName = DB.Element.Name.__get__(eT)
    filePath = testPath + "/" + typeName
    imgOption.FilePath = filePath
    eT.Activate()
    y = 0
    z = 0
    x = 0
    coor = XYZ(x, y, z)
    l = doc.Create.NewFamilyInstance(coor, eT, level[0], StructuralType.NonStructural)
    doc.ExportImage(imgOption)
    doc.Delete(l.Id)

dprint("Script Complete")

t.Commit()

I’m wondering if I need to do the export after the transaction or as a separate transaction.

So you are trying to place a family and then export in the same transaction?

move the export after the transaction. after the transaction is committed the document will regenerate the view and then changes will be available for export

Edit:
Oh you want to delete. Create a transactiongroup, then place the family in a transaction inside the transactiongroup. then rollback the transactiongroup after the export (which is outside the transaction but inside the transationgroup). no delete needed

2 Likes

So I just added TransactionGroup and it appears to be working. First time using that with minimal problems. There are now a whole bunch of transactions in the undo menu. I’m guessing there is a way to get rid of those.

Fixed! Us Assimilate() instead of Commit() on the group.

1 Like

Thanks for the help I figured it out as you were posting. I don’t think I want to rollback the transactiongroup because generating the images is step 1 of this script and I want to keep future changes so I need the transaction to actually commit.