Export image crops outer pixels

Export image crops outer pixels

Iev60047
Advocate Advocate
1,916 Views
19 Replies
Message 1 of 20

Export image crops outer pixels

Iev60047
Advocate
Advocate

This issue is fairly well documented on the Revit API forums, but as I have literally 0 idea about how to code in C#, I figure I post it here to see if there is a manual solution. 

 

Basically I am exporting an image from a family editor view, and sometimes the outermost pixel on a family gets cropped out. This is problematic because:

1) I want to systematically export images from families I use to create exact width images for use in a schedule to create a new legend and

2) Takes much more time to manually adjust the crop view to create an inexact image export.

 

Does anyone have any suggestions about how to solve this? I have some C# code from the Revit forum but have no idea how to use it.

0 Likes
Accepted solutions (1)
1,917 Views
19 Replies
Replies (19)
Message 2 of 20

L.Maas
Mentor
Mentor

You could try it with Dynamo. My first rough idea about the script would be something like this:

Manually:

-Start a new Revit project (maybe special prepared template)

-Load in all the families needed for images.

-Create a view with settings  as you prefer.

 

Then run the script which does:

1-Place the family isntance on a location so it is visible in the view

2-If the sizes vary you might think to calculate the size of the family instance (boundingbox)

3-Change the scale of the view to fit the family instance

4-Export image to folder

5-Delete the family instance

6-Go back to step 1 and place the next one. Repeat until finished.

 

Not tested it, so not sure if it will work like this

 

 

 

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

Message 3 of 20

RLY_15
Advisor
Advisor

https://archi-lab.net/image-exporter-for-dynamo/

 

A nice little blog entry on the export node in the archilab package. It looks like scale-to-fit and image width are both options within the (long) list of input nodes, but this is probably a good starting point for a Dynamo-based method.

Message 4 of 20

Iev60047
Advocate
Advocate

I am continuing this thread from the other thread that I accidentally cross-posted here. I apologize. In response to @EATREVITPOOPCAD , changing the export range did not help resolve the issue. In fact the pixels disappearing (being cropped out) appeared on the opposite sides of the model. This is leading me to think that this is a bug. I am posting two pictures of what I mean.

 

@L.Maas and @RLY_15 I honestly don't have too much experience with Dynamo but I'll give it my best shot. I was told by @jeremy.tammik simply to bring this issue up to Revit development's attention, because if I can't do this task manually, then I shouldn't try to code my own work-around in.

0 Likes
Message 5 of 20

Iev60047
Advocate
Advocate

Actually, now I am thinking of it, no matter what, I will need to use the export image function at some level (I looked into the archi-lab dynamo exporter tool and it's basically what I already found/programmed) and the export image function is limited by ZoomType enumeration. I need to implement something that turns on the cropped view parameter, adjusts it to fit the family and then increases its size by a small factor. Essentially, someone who knows how to program dynamo nodes would need to turn this:

 

drafting.CropBoxActive = true;
drafting.CropBoxVisible = true;

private static void ExtendViewCrop(View drafting, Group detail)
        {
            BoundingBoxXYZ crop = (drafting!= null ? drafting.CropBox : null);
            if (crop == null || crop.Max == null || crop.Min == null || crop.Transform == null || detail == null)
                return;
            BoundingBoxXYZ detailBox = detail.get_BoundingBox(drafting);
            BoundingBoxXYZ extendedCrop = new BoundingBoxXYZ();
            extendedCrop.Transform = crop.Transform;

            if (detailBox == null || detailBox.Max == null || detailBox.Min == null)
                return;

            extendedCrop.Max = detailBox.Max + (extendedCrop.Transform.BasisX + extendedCrop.Transform.BasisY / 2) * 0.03;
            extendedCrop.Min = detailBox.Min + (-extendedCrop.Transform.BasisX + -extendedCrop.Transform.BasisY / 2) * 0.03;
            drafting.CropBox = extendedCrop;
        }

 

into a dynamo node. I do not know how to do that. In addition, this code was written to handle a group, not a family view. I am also not sure what kind of instance "drafting" is. I assume it is an variable of type Document, but I could be wrong.

0 Likes
Message 6 of 20

L.Maas
Mentor
Mentor

Here a very basic implementation in Dynamo.

-Select the view.

-Select the object(s).

-Find the bounding box around the object(s)

-Set the crop view to the size of the bounding box.

-Export the view as image to a file in a directory.

 

It is an already functioning script, however limited it is yet.

 

LMaas_1-1660166705599.png

 

You can increase the complexity of this script to get the behaviour you want. You can do things like increase the size of the crop view. Instead of a single item you can repeat the process with a list of items. Maybe you want extend it that the script first places the object somewhere before starting the process.

All depending on how you set up your project and which parts you want to automate.

Start simpe and then slowly extend it as needed.

 

If you are lucky you do not have to program anything new and just use the nodes available.

 

 

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

Message 7 of 20

Iev60047
Advocate
Advocate

@L.Maas Thanks once again! Figured out how to use dynamo! Now running into problems again. It seems that when I redefine the bounding box to feed into creating a new setcropbox function, it throws up an error. I have no idea how to solve it. The original bounding box doesn't have problem in creating a new setcropregion. In fact, when I deconstruct and reconstruct the original bounding box for some reason the View.SetCropBox node breaks down again, even though the bounding box is exactly the same. 

Export_Image.png

Oh lordy, am I getting frustrated. I am attaching the dynamo file. As soon as I can figure this out, it will be a major hurdle surpassed in the right direction.

0 Likes
Message 8 of 20

Iev60047
Advocate
Advocate

Hmm, no matter what I try, I am not able to set the cropregion to a boundingbox. I think it may have something to do with the create boundingbox by corners node. At what point can I report a bug?

0 Likes
Message 9 of 20

iainsavage
Mentor
Mentor

What is the error message which displays above the yellow node when you expand the stickynote?

Message 10 of 20

iainsavage
Mentor
Mentor

I don't know if this is the problem but at the left side of the script you've got max point at the top, min at the bottom but at the right side you've got them the other way around so the error is possibly that you have max less than min as you feed into the last node?

Message 11 of 20

L.Maas
Mentor
Mentor

See the same issue. Take a quick look, but did not dind the cause.

Decided to look at different approach. Used view.setcropboxcurves, it is from MEPover package.

 

Note: Always mark when you use external packages. People without that package installed might find it difficult to find from which package it is coming.

 

 

LMaas_0-1660207303377.png

 

In these types of script it is better to set the run mode to Manual instead of Automatic

LMaas_1-1660207750502.png

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

Message 12 of 20

Iev60047
Advocate
Advocate

Thanks @L.Maas for the assistance again. Yes, I tried that script out, but it seems the problem is that the MEPover library node SetCropBoxCurves does not change the view crop region. In fact, besides the blue outline that appears with the geometry preview, I do not know what the cropbox actually means. I tried this out with the ExportImage plugin from Archi-lab. The ExportImage node recognizes th elight blue lines in the preview, but when I turn the preview off, the recognition of the "border" stops.

 

@iainsavage The error that occurs when I try to set the crop box is a null object error.

 

Iev60047_0-1660221438181.png

Edit: To clarify I end up with this result:

Iev60047_1-1660221920281.png

 

 

0 Likes
Message 13 of 20

iainsavage
Mentor
Mentor

Did you correct this:

iainsavage_0-1660221976764.png

 

Message 14 of 20

Iev60047
Advocate
Advocate

Yup! Min and max are fixed, thanks for that. Here is the current dynamo graph.

Capture_Image_2022-08-11_08-47-18.png

0 Likes
Message 15 of 20

L.Maas
Mentor
Mentor

This is the "crop box" in Revit

 

LMaas_0-1660223108291.png

 

When actrivated it hides the elements outside that box (the annotation crop is to hide some annotation elements)

 

If you see something blue highlighted in Revit it means that it is selected or it might be a preview from Dynamo

LMaas_1-1660223400028.png

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

0 Likes
Message 16 of 20

Iev60047
Advocate
Advocate

Okay, then the setboxbycurves, is not setting the crop box appropriately. That picture I submitted above, is when I hovered over the air terminal. It's funny because the crop box created by setcropbox actually hide the element.

0 Likes
Message 17 of 20

L.Maas
Mentor
Mentor

Ok, not sure what is going on

 

This is in my case with 50 and 500 offset.

LMaas_0-1660224197734.png

LMaas_1-1660224253554.png

 

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

0 Likes
Message 18 of 20

Iev60047
Advocate
Advocate
Accepted solution

Weird! I cannot figure that one out. @L.Maas I can see from your picture that your crop region is lining up with the curves used by setcropboxbycurve. That is not the case for me. But I just got it to work when I converted the modified bounding box into a polysurface and back into a bounding box! This was a long time coming. Would you mind sharing the revit file, the dynamo script and successful run picture of your dynamo graph? I realize that I was in imperial units which was probably making things act weird. I can then test it, and verify what exactly is going wrong on my end. 

 

I am attaching the function (not cleaned up), graph and revit file I used.

0 Likes
Message 19 of 20

L.Maas
Mentor
Mentor

It is based on the standard (metric) Autodesk Mechanical Template from Revit 2022.

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

0 Likes
Message 20 of 20

Iev60047
Advocate
Advocate

I accepted my last post as the solution, just because I have not been able to run anything else that accomplished my objective. But if I do, I will be sure to note their dynamo code works as well!

0 Likes