Scale of SVG exported from Houdini

   2001   1   0
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
In Entagmas tut(https://vimeo.com/282137418) they show how to export as svg so it can be used is something like Illustrator.

As an exercise I've created some rows boxes that would fit 8.5 x 11 inch paper

My issue is that when I open the svg in Illustrator the scaling is way down very small.(Illustrator art board set to 8.5 x 11 inches)

In the hip I set up preference to inches and create the boxes accordingly.

I changed the python from the tut to be ‘hardwired’ for 8.5 x 11.

So I am wondering if someone that's good with python could show me what I did wrong, or suggest how to get the scaling?

I can do a manual scaling to get it to fit, but would like to be able to code it.


node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.


filename     = node.evalParm('file_name')
stroke_width = node.evalParm('stroke_width')

box = geo.boundingBox()
minv = box.minvec()
size = box.sizevec()


width  = 8.5
height = 11


def write_path(fp, points):
  if not points:
    return
  data = 'M{} {} '.format(points[0].x(), points[0].y())
  for p in points[1:]:
    data += 'L{} {} '.format(p.x(), p.y())
  fp.write('<path d="{}" stroke="black" stroke-width="{}pxy" fill="none"/>\n'.format(data, stroke_width))


  
with open(filename, 'w') as fp:
  fp.write('<?xml version="1.0" standalone="no"?>\n')
  fp.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')
  fp.write('<svg width="8.5in" height="11in" version="1.1" xmlns="http://www.w3.org/2000/svg">\n')
  for prim in geo.iterPrims():
    if prim.type() != hou.primType.Polygon:
      continue
    points = [v.point().position() for v in prim.vertices()]
    write_path(fp, points)
  fp.write('</svg>')

Attachments:
SVG Export.hiplc (262.9 KB)

User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
Well for whatever reason the python doesn't work with defining the sizes in inches,

But if one works out the ‘equivalant’ in pixels, then everything falls into place with the proper scaling.

So, in case someone in the future attempts the same thing:

In Houdini Preferences > Hip File Options, instead of inches, I just use any ‘single’ unit option( whole number integer - one that does not do a conversion to non whole float value ).

Then create the boxes accordingly based on the Illustrator doc information on its' pixel size for an 8.5 x 11 inch layout.

Then in the above code set the line from :

fp.write('<svg width="8.5in" height="11in" version="1.1" xmlns="http://www.w3.org/2000/svg">\n')

To that Illustrator doc pixel size as :

fp.write('<svg width="612px" height="792px" version="1.1" xmlns="http://www.w3.org/2000/svg">\n')

P.S. I suspect the original issue is that even though like in the above line change, it must only be applying to the file size as a whole (like a container). In that it's not also converting my point positions also (even though the ‘unit’ positions have the proper values, e.g. min x is -4.25, max x is 4.25. So the reason it's small in scale is that it's interpreting those dimensions as pixel values, making it small. So maybe there is a python format option for the point values to be converted: otherwise I would have to do my own conversion in the setup pre python sop, or in the python sop itself.
Edited by BabaJ - Sept. 2, 2019 10:43:57
  • Quick Links