Jump to content

Marvelous Designer Pattern Transfer Script


Atom

Recommended Posts

Hi All,

I was playing around with a Houdini python script on Windows that examines the points in a Houdini  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 Houdini 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 scripts section.

blender_2_marvelous_designer.gif

This GIF demonstrates the script in action. Each mouse move and click is generated by the python script

Here is how it works.
1.) Draw or import your pattern in Houdini (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.) Place Houdini over top of Marvelous Designer so the left portion of MD is visible behind Houdini.
4.) Install the script in a shelf tool and click the button. Don't move the mouse while the script is running, 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 shelf tool.

Untitled-2.jpg

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.

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 Houdini.

# Click the Tool button and Houdini sends Windows based mouse move and click commands to Marvelous Designer.
# The result of those commands will be a copy of the Houdini curve created inside of Marvelous Designer.
# (c) 2016 Atom.
# see http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx for details

SLEEP_TIME = 0.5
def mouseAndClick (x,y):
    ctypes.windll.user32.SetCursorPos(x,y)
    ctypes.windll.user32.mouse_event(2, 0, 0, 0,0) # left down
    time.sleep(SLEEP_TIME)
    ctypes.windll.user32.mouse_event(4, 0, 0, 0,0) # left up
def keyPress (ascii_code):
    ctypes.windll.user32.keybd_event(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

    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.
else:
    print ("Unable to fetch node [%s]" % node_name) 
Edited by Atom
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...