Book a Demo

Author Topic: Printing Diagrams from an Add In  (Read 4647 times)

divido

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Printing Diagrams from an Add In
« on: March 13, 2007, 06:06:17 am »
I am writing an Add-In, and after collecting a list of all the diagrams in the model, the add-in filters out a subset of them. I then want to send that subset to the printer, much as if a user had open each of them and printed a copy. I haven't stumbled upon any operation that allows me to do so, nor any one else having the same problem.

The only thing I can think of is to have each diagram saved as an image to file (or to the clipboard) and then having that image printed using my own printing code. This is undesirable, though, because image captured diagrams have tight borders around the elements of a diagram, as opposed to bordering the page. Moreover, multi-page diagrams will print with a broken border, and the second page will be unnamed with an image, where 'normal' printing prints a second border.

Is there a way to do this?

Thanks,
David

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing Diagrams from an Add In
« Reply #1 on: March 13, 2007, 06:58:05 am »
David,

Take a look at the Tools | Options | Diagram dialog. At the lower right you will see settings for Diagram Frames. Setting or clearing these as appropriate may solve your problem. You might also want to look at the Opaque Diagram Labels settings, since these work in concert with frames.

David
No, you can't have it!

divido

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Printing Diagrams from an Add In
« Reply #2 on: March 13, 2007, 07:16:54 am »
David,

I looked, as you suggested at the Options dialog. I see the three check boxes for Diagram Frames. I played around a little to confirm my suspicions, and it seems that they turn on or off the diagram frames for various output types.

I think I spoke vaguely about my diagram frame problems. I want to be able to programmatically select diagrams and send them to the printer via an Add-In. I can't find a way to say diagram.Print(), which is what I really want. My discussion on frames was sort of a backup plan. Instead of diagram.Print(), I might be able to say diagram.SaveToFile(), then using my own internal code load the image into memory and print it.

This backup plan is undesired because of the way EA outputs to images versus to printed pages. When printing a page with a diagram on it, the frame is (almost) 8.5 by 11, going around the outside of the printed page. The diagram boxes are then inside it somewhere. When outputting to an image, the frame is close to the boxes (since you presumably wouldn't want a lot of internal white space in an image file). The second issue with this backup plan is when a diagram is large, and therefore spans two pages. Opening it and printing through EA causes each page to have its own border, both labeled in the top-left. An image, though, simply gets wide enough to fit it. If I print that image, it will span two pages, but only have one large border around the both of them. The behavior I want it identical to the Print option, but I cannot find a way to do it programmatically.

Nevertheless, your suggestion did offer another alternative.. I could save the diagram without a frame, then add the frame (or frames) myself afterward (with appropriate internal white space). This is a lot more work than I wanted to do to print a diagram, though. I'm still hoping there is an easier way.

Continued Thanks,
David

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing Diagrams from an Add In
« Reply #3 on: March 13, 2007, 08:56:40 am »
OK...

This is not going to make you entirely happy - it didn't do much for me when I waded through this stuff the first time - but it might at least get you out of your bind.

If you are creating and add-in the runs within an EA session you are going to have the sort of problem you describe. You can always write the necessary code to set up a device independent page yourself - whether you do this in .Net, an earlier Windows paradigm, or some other means, depends on your development environment. Having done that you can then print as you wish.

[Note that EA is Australian, and your page size may default to A4 unless you take precautions in your code. Note also that Sparx uses its own page sizing methods. Read the documentation for how this is done; be persistent, as it is spread out over several sections.]

If you are writing an automation project that runs separately from EA - from an icon or the start menu for example - you need to do other things. First, you need to capture the image in the first place. EA presents only a few methods for doing this, which you've grasped.

You can get the diagram in an image format through the clipboard, with limited ability to select the format. I did some work with this a while back, and I think there are only 1 or 2 formats that actually work. What you get is what you'll see in this case. There is a bit of flexibility in how you read the image from the clipboard, but not much. In any case you'll need to look up how Windows handles clipboard data, since whatever flexibility is determined by the clipboard, not EA.

You can also save the image to a file. There are two methods for doing this. One (SaveDiagramImageToFile) allows EA to decide everything. The other (PutDiagramImageToFile) allows you to specify the diagram, the file, and to a lesser extent the format.

My advice is to see if the clipboard works for you. Try setting the default diagram type in EA to see if this helps. [But first read the documentation in detail since very few (if any) settings will change things.]

If the clipboard doesn't do it, then you'll have to drop a file and read it back. [Yes, I know it's a pain, and it bugs me too.] Try the various formats to see if one gives you both: acceptable presentation, and the ability to resize as required. If one of these works for you then program on.

HTH, David
No, you can't have it!

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Printing Diagrams from an Add In
« Reply #4 on: March 13, 2007, 09:52:38 am »
I didn't think A4 was peculiarly Australian ... in the way that Letter is peculiarly North American !!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing Diagrams from an Add In
« Reply #5 on: March 13, 2007, 12:02:34 pm »
I agree, A4 is not Australian. It's just non North American.
No, you can't have it!