Inkscape.org
Beginners' Questions How to most efficiently add a rectangle slightly larger than some arbitrary object for exporting?
  1. #1
    wastenot wastenot @wastenot

    This is what I'm after just in case there is some quicker way to do it than what I'm doing right now with multiple steps. Steps that I'd like to avoid:

    I add a bunch of objects, rectangles, text and so on. I group them all and then export it into a PNG file.  When I view the PNG file, I see there are areas were the objects are *not* that show through. That is by design I guess, but in this case, I don't want that. What I want is the entire group of objects to include a rectangle with some controllable foreground and background colors, and that is, I'd say, about 0.25 inches margin. Then I would want it to be put into the background and the entire thing exported. Then, when it is viewed, the objects in the group in front and the filled rectangle is in back.

    I can do all of the above in multiple steps, but I would like to have some type of button that allows me to select the group, and say "wrap with rectangle" and from then would create the rectangle, put it into the background, and then regroup the entire object.  And here's the key: I want to not have to do all of that manually.

     

    I searched for extensions and couldn't find anything. I did find something close under the Path menu for outset and dynamic outset, but it seems to only work on paths and creates a sort of "halo" of a path object.

     

    Thanks!

    wn

     

  2. #2
    Tyler Durden Tyler Durden @TylerDurdenβš–

    The Document Properties panel has a Custom size section where the page size can be set by the size of the selection plus pre-settable margins.

    I'd make the background opaque, then I'd select-all-in-all-layers, and resize the page as above with some margin and export PNG including all elements

     

  3. #3
    wastenot wastenot @wastenot

    Thanks Tyler. Good to know that is one possibility. However, I often have to do what I need to do on multiple separate groups within the same page, because the rectangle I want drawn around it needs to have its own fill and stroke color. I was really after some add-on or extension to do this.  I'll keep searching.

  4. #4
    brynn brynn @brynn

    Welcome to the forum!

    I'm posting this without seeing wastenot's 2nd message (it's still in moderation).  I see that TD may have answered part of the problem.  But I'm so unclear with the

    wastenot

    I see there are areas were the objects are *not* that show through

    and other things, that I can't be sure if all the issues have been covered.

    So if all your issues have not been covered, would you please share an SVG file, and as well, either explain what you want relative to that file, or show an image that depicts what you want?

    Then we can give a correct answer on....well, if not the first try, at least a lot faster than trying to guess what you mean.

    Based on my current understanding, short of writing a custom script, I can't see doing all that in one click.  But once I understand the situation, I would guess there will be some helpful shortcuts we could suggest.

  5. #5
    wastenot wastenot @wastenot

    I will do so, just as soon as I can figure out why this forum is giving me fits on posting replies.

  6. #6
    wastenot wastenot @wastenot

    Hi brynn,

    I've attached a functional specification of a tool that I want.  My original post was a bit vague. This takes it in the opposite extreme with lots of detail.

    Now, I ask to see if such a tool exists, to mean is there an extension that someone has already written that does this.  If there isn't I will have to decide if it is worth the bother to write such an extension myself given the nice documentation I found. But I don't want to "reinvent the wheel".

    Thanks,

    wn

    How To Most Efficiently Add A Rectangle Slightly Larger Than
  7. #7
    brynn brynn @brynn
    *

    Wow!  Math guy (or gal).

    I got a little bit lost with the math-like symbols in your explanation.  So I might be missing or not understanding a couple of details.  But I'm pretty sure there is no extension even remotely similar to this.

    It sounds like you need an easy way to present something like screenshots, except they are drawings, in a nice, consistent format.

    The biggest problem is your insistence on the equal margins around the drawing.  If it weren't for that, this would be relatively easy.  Let me ask, have you thought of the following approach?

    • select the text and drawing
    • note the height/width on Selection tool control bar
    • draw a filled rectangle of that size, plus the needed margin  (I mean, you can't tell me that this simple math is too much for you, haha!)
    • move the rectangle to the back
    • center the drawing in that rectangle

    That certainly would be faster than the routine with the guides and 4 spacer squares.  Centering is done using Object menu > Align and Distribute > Center on Vertical Axis, plus Center on Horizontal Axis.  Choosing from the Relative To: dropdown menu at the top decides whether you center the rectangle to the group or the group to the rectangle.  (One of these days I'm going to get around to asking for a Center It button....)

    Regarding the possible bug you mentioned.  That Traceback error comes from an extension.  But you didn't mention using any extension.  You said "type ctrl+c".  I assume that means Ctrl key + c key, right, the copy shortcut?  You didn't mean to type c-t-r-l and etc, right?

    I can't reproduce that, at least on 0.92.3.  Although I couldn't find a big gray rectangle to the left.  I tried it on one of the big gray rectangles in your explanation.  I think there is a 3rd party extension called Ink2Canvas, which exports the drawing to HTML5.  But you would have to have specifically installed it, and been trying to use it at the time. 

    You said you hacked around it, and I can't help but wonder if some previous hacking might have something to do with this error?  I mean, I can't really decipher those traceback errors in detail.  But somehow the Ink2Canvas extension must be involved with it, if not directly.

    Edit

    Just thought of an alternate routine.  If you can find some kind of screenshot app or software which allows for making equal margins, you could even skip the rectangle.  Typically the screenshot app would not support transparency, and would give you a white background (or whatever color you want).  As long as you don't use the checkboard option for Inkscape.

    • #8
      wastenot wastenot @wastenot

      Sorry for the mathtastical rendition there. You got the gist though, which is I need a bigger rectangle centered on the bounding box comprised by the objects on the inside, and the rectangle shoved in the back so that the objects are on top of it. The net result is when both the filled rectangle and the objects in front are exported into a PNG file, and the PNG file opened with "eog" (Linux app to display images), then there are no "alpha channel" checkerboxes shown there because every pixel is opaque.

       

      Yes when I do this in practice, you better believe I don't use those tiny rectangles, but is what I would have to spell out for someone writing an extension to do all of these steps for me without me having to really lift a finger beyond specifying what margin there is, and colors and fill attributes for the rectangle. The extension would do the math calculations which aren't that hard to do in code.

      I could probably whip this out myself and if I do I'll write back here.

      As to the traceback: I don't think I have any extensions installed other than what is coming in by way of the Inkscape that Ubuntu 19.10 installs by default:

       

      $ dpkg --list inkscape
      Desired=Unknown/Install/Remove/Purge/Hold
      | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
      |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
      ||/ Name           Version      Architecture Description
      +++-==============-============-============-=================================
      ii  inkscape       0.92.4-4     amd64        vector-based drawing program
      $

      Thanks for your feedback though.

    • #9
      brynn brynn @brynn
      *

      Hhmm, I thought you mentioned having found the intro guide for writing extensions.  But now I can't seem to find, so maybe someone else said it.   😡  Just in case you didn't find it, this might help:  https://inkscape.org/develop/extensions/

      Oh, and also worth mentioning.  There's a good chance this new extension won't work in version 1.0.  Apparently something about Inkscape changes so significantly in 1.0, that it makes most 3rd party extensions unable to work.  We're just in the process of documenting the changes so extension authors can consult the info to upgrade their extensions.  We can contact you when it's ready, if you like (and if you provide...[ewww, deja vu!] contact info).

    • #10
      wastenot wastenot @wastenot

      Got it.

      I replied to my other thread just now (https://inkscape.org/forums/extensions/versions-and-api-shift-for-092x-to-10/#c9860)  as a result of my discovery of what you mentioned above.

      So, my effort to write an extension for this particular "wrap a rectangle behind a bunch of objects" use-case is on hold until the API's stabilize to my satisfaction.

      brynn, thank you very much for your help here!! I've learned a lot and has got me unstuck to so I can move forward. I'm looking forward to the good stuff coming down in 1.x!!

    • #11
      brynn brynn @brynn

      Oh good, I'm glad you found that board.  I totally forgot about those messages.

      You're welcome. 

    Inkscape Inkscape.org Inkscape Forum Beginners' Questions How to most efficiently add a rectangle slightly larger than some arbitrary object for exporting?