Page 1 of 1

Blender Curve To Marvelous Designer

Posted: Fri Jul 22, 2016 7:50 pm
by Atom
Hi All,

I was playing around with a Blender python script on Windows that examines the points in a Blender bezier curve and then creates a series of mouse clicks out of that point data that gets sent to the Marvelous Designer 2D window. The end result is your pattern is transferred from Blender to Marvelous Designer.

It is kind of crude and it works only on Windows but I thought I'd offer it up here in the Tricks section.
This GIF demonstrates the script in action. Each mouse move and click is generated by the python script.
blender_2_marvelous_designer.gif (17.28 KiB) Viewed 3145 times
Here is how it works.
1.) Draw or import your pattern in Blender (start simple, and remember to set your points to Vector, curves are not transferred.)
2.) Launch Marvelous Designer and place it in fullscreen mode. Select the 2D view only so it fills the entire screen.
3.) Open the attached blender scene file, which contains the python script that generates the mouse movements, and place it on top of Marvelous Designer but to the right so the left hand portion of MD can bee seen behind blender.
4.) Click the Run Script button in Blender and don't move the mouse, wait for the script to finish.
5.) The script has a built-in time delay of 0.5 seconds between mouse moves to allow Marvelous Designer to process the new mouse command.

The 2D zoom grid, in Marvelous Designer, determines at what scale the newly transferred pattern comes in as. So you can set the 2D grid zoom before you run the script. But you can, of course, resize it to your need once the pattern is inside of MD.

Here is my screen setup before I click the Run Script button.
Untitled-1.jpg (463.93 KiB) Viewed 3145 times

Houdini Curve To Marvelous Designer

Posted: Fri Jul 22, 2016 8:36 pm
by Atom
And here is the Houdini version of the python script leveraging the same auto mouse move technique.

The code expects that your curve was drawn in the top viewport (SPACE-1), it fetches XY pairs from the XZ point values in the curve. You will have to specify the path to the final node in your curve SOP network by changing the variable in node_name in this script to point to your node. For best results follow up your curve1 node with a transform1 node and set the transform scale to 60-100. When curves are too small this technique does not work. Houdini's internal values seem to be 100 times smaller than Blender.
Untitled-2.jpg (223.02 KiB) Viewed 3125 times
Place this code in a Houdini shelf tool and follow the above Blender directions as far as screen setup and running are concerened.

Code: Select all

import hou, time
import ctypes

# This script attempts to transfer a Houdini curve to Marvelous designer as a pattern.
# Place Marvelous Designer in full screen mode and click the 2D window button in the lower right corner.
# Now that Marvelous Designer is in 2D mode and occupying the full screen 
# place Houdini on top and to the right to reveal the 2D marvelous screen area behind Blender.

# Click the Tool button and Houdini sends Windows based mouse move and click commands to Marevelous Designer.
# The result of those commands will be a copy of the Houdini curve created inside of Marvelous Designer.
# (c) 2016 Atom.
# see for details

def mouseAndClick (x,y):
    ctypes.windll.user32.mouse_event(2, 0, 0, 0,0) # left down
    ctypes.windll.user32.mouse_event(4, 0, 0, 0,0) # left up
def keyPress (ascii_code):

# Step #1.
# Click Marvelous Designer Polygon tool.
#mouseAndClick (325,80)                         # Create Rectangle Tool.
mouseAndClick (280,80)                          # Create Polygon Tool.

# Now transfer the curve to the Marvelous Designer screen space.
x_offset = 240
y_offset = 240
scale = 1

node_name = "transform1"
n = hou.node('/obj/curve_object1/%s' % node_name)
if n != None:
    x_start = -1
    y_start = -1
    i = 0
    for p in n.geometry().points():
        x = int(x_offset + p.position()[0]) * scale
        y = int(y_offset + p.position()[2]) * scale
        if i == 0:
            # Save start on first click.
            x_start = x
            y_start = y
        mouseAndClick (x,y)
        i += 1 
        print x,y
    if x_start != -1:
        # Make last click return to the starting location.
        mouseAndClick (x_start,y_start)
    keyPress(27)        # Send an ESC keystroke, we are done creating the polygon.
    print ("Unable to fetch node [%s]" % node_name)

Re: Blender Curve To Marvelous Designer

Posted: Sun Jul 24, 2016 7:04 pm
by LoriGriffiths
That is amazing. I had no idea you could do such a thing working from one program to another.

If I ever need help with a Blender script, I know who I'm going to ask! ;)

Re: Blender Curve To Marvelous Designer

Posted: Fri Dec 08, 2017 8:53 pm
by dela
Hi there,

question im was trying to look at this script with blender 2.78c on OSX. Does ctype only come on a window system, i dont know anything about that. Is there more info on this?

sorry i should be more specific. Actually i guess ctype is there but it doesnt have the windll. So perhaps i should check for a darwin version should i?
This is the error from the console

Code: Select all

AttributeError: module 'ctypes' has no attribute 'windll'

Re: Blender Curve To Marvelous Designer

Posted: Fri Dec 08, 2017 9:22 pm
by dela
Aha i noticed the microsoft link up top. So your excecuting some winows mouse coordinates function which is excecued from blender which probably records the vertices and uses that to recreate the garment. Thats super clever!

Re: Blender Curve To Marvelous Designer

Posted: Sat Dec 09, 2017 12:23 am
by dela
Wow!!! you the man! hahaha..

After some digging, i found a nice little OSX app which can do sort of the same. Because the commands are quite easy i can do without that pause you added. This app can do a whole string of commands at once.

I knew how to run a app and pass some arguments, just need to find out how i could run this app from system base level. I got it working and ill post a example, i need to have some different starting coordinates cause of different MD version.

Re: Blender Curve To Marvelous Designer

Posted: Sat Dec 09, 2017 7:12 am
by dela
Hey ive been working on the script and converted it to a addon. Ive added some features and have sort calculated the best size for convertion. Still need to do some work. I noticed that when svg or ai is imported the curve is set to cyclic, which in blender look likes its a closed border but when exported to MD its not closing the 2d pattern. When i looked at your example you added the last vertex close to the first. This took me a while to notice :) But i think its a easy fix.

Any how here's the progress of today. You can select one of the curves from the scene using a dropdown or use a selected one. Also ive added a warning for scale, i noticed when scale isnt 1 the convertion is weird. So added a check there and a option to apply scale.

Hope this still also works for windwos though, im using OSX only. I would like to post this on blender artist if you dont mind. Though the OSX users need to some more hustle to get it to work, thats a pitty...

Here's a little anim