Mattias Lindberg

FakePilot

About Me

Expertise
Freelancer
Location
Sweden

Connect

Recent Forum Posts

it’s possible to export a .svg?? Dec. 18, 2018, 2:39 p.m.

I can make the Entagma Python script create a SVG sequence. But trying to use grayOlorin's otl.
Because that one can have color as well.

Even though I managed to replicate it to export for every frame in a new python node, it then somehow does not output color.
Then I have to use the OTL and that has a button I have to click for every frame, for it to work.

Ps. I'm a pure newb when it comes to Python.

This code together with the right fields:

def exportSVG():

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

    filename = node.evalParm("location")
    sizeMult = node.evalParm("sizeMult")
    setColor = node.evalParm("setColorFromAttr")
    colorAttr = node.evalParm("colorAttr")
    addStroke = node.evalParm("addStroke")
    strokeColorR = node.evalParm("strokeColorr")
    strokeColorG = node.evalParm("strokeColorg")
    strokeColorB = node.evalParm("strokeColorb")
    strokeThickness = node.evalParm("strokeThickness")

    import xml.dom.minidom as minidom

    svgFile = minidom.Document()

    svgElement = svgFile.createElement("svg")
    svgFile.appendChild(svgElement)

    # Add code to modify the contents of geo.

    for prim in geo.prims():

        positionString = ""

        for vertex in prim.vertices():

            position = vertex.point().position()
            positionString =  positionString + (str(position[0]*sizeMult) + "," + str(position[1]*sizeMult*-1) + " ")

        #now write to SVG

        polygonElement = svgFile.createElement("polygon")
        polygonElement.setAttribute("points", positionString)

        #Set Fill

        if (setColor == 1):
            color = prim.attribValue(colorAttr)

            red = hou.expandString("`inttohex(round(" + str(color[0]*255) + "))`")
            green = hou.expandString("`inttohex(round(" + str(color[1]*255) + "))`")
            blue = hou.expandString("`inttohex(round(" + str(color[2]*255) + "))`")

            hex = "#" + red[6:8] + green[6:8] + blue[6:8]
            polygonElement.setAttribute("fill", hex)

        else:
            polygonElement.setAttribute("fill", "None")

        #Set Stroke

        if (addStroke == 1):

            red = hou.expandString("`inttohex(round(" + str(strokeColorR*255) + "))`")
            green = hou.expandString("`inttohex(round(" + str(strokeColorG*255) + "))`")
            blue = hou.expandString("`inttohex(round(" + str(strokeColorB*255) + "))`")

            hex = "#" + red[6:8] + green[6:8] + blue[6:8]

            polygonElement.setAttribute("stroke", hex)
            polygonElement.setAttribute("stroke-width", str(strokeThickness))

        svgElement.appendChild(polygonElement)

    #print svgFile.toprettyxml(indent="  ")

    #print filename

    newFile = open(hou.expandString(str(filename)),"w")

    newFile.write(svgFile.toprettyxml(indent="  "))

exportSVG()

Vector graphics Dec. 16, 2018, 2:14 p.m.

Here is Entagma's tutorial on how to import and export SVG:



If you can figure out a way to export a sequence, let me know! :-)

it’s possible to export a .svg?? Dec. 16, 2018, 2:12 p.m.

Entagma made a tutorial on how to export SVG from Houdini with Python.
I am, however, looking for a way to export a sequence.