MASH - adding curve node via Python


#1

Hi,

I am sorry I am really new in Python programming and I am really stuck.
I still tying to figure out what the best way is, to create a book row generator. My books should be following a spline. I tried it with MASH now, but my problem is, that I can’t figure out how to put a curve node in there via the script.
I also tried to use the curve warp, but unfortunately I can’t figure out what the attribute for ‘mashNetwork.createCurveWarp’ is.

I am thankful for every help :slight_smile:

import os
import MASH.api as mapi
import maya.cmds as cmds

class BookGenerator:

def __init__(self):
    self.win=cmds.window('Book Generator', exists=True)
    if (self.win == 1):
        cmds.deleteUI('Book Generator', exist=True)


    self.win = cmds.window(title='Book Generator', widthHeight=(450, 850))
    cmds.columnLayout(adj=True, rs=10)
    cmds.text('!Please select spline!')
    self.sizeBooks = cmds.intSliderGrp(l="Size of Books", min=1, max=10, field=True)
    self.thicknessBooks = cmds.intSliderGrp(l="Thickness of Books", min=1, max=10, field=True)
    self.randomSize = cmds.intSliderGrp(l="Randomize Size", min=1, max=10, field=True)
    self.numberOfBooks = cmds.intSliderGrp(l="Number of Books", min=1, max=30, field=True)

    self.saveLocation = self.create_custom_save_location()


    cmds.button(label='Create mesh Network', command=self.createMashNetwork)

    cmds.showWindow(self.win)

    ####create save location######
def create_custom_save_location(self, path_name='customData'):
    proj_dir = cmds.internalVar(userWorkspaceDir=True)
    new_dir = os.path.join(proj_dir, path_name)
    if not os.path.exists(new_dir):
        os.makedirs(new_dir)

    return new_dir

def load_fbx(self, *args):
    self.find_Book = os.path.join(self.saveLocation, 'Book.fbx')
    cmds.file(self.find_Book, i=True, type='fbx')
    cmds.select('Line002')


#create Mesh Network
def createMashNetwork(self, *args):
    self.loadFbx = self.load_fbx()
    cmds.select('Line002')
    numberOfBooks = cmds.intSliderGrp(self.numberOfBooks, q=True, v=True)

    self.mashNetwork = mapi.Network()

    # creating the network
    self.mashNetwork.createNetwork(name="MASH_Network#")
    self.mashNetwork.setPointCount(numberOfBooks)

    # setting the distribution distance to 0
    cmds.setAttr(self.mashNetwork.distribute + ".amplitudeX",numberOfBooks*3)

    cmds.select('MASH5_ReproMesh')
    self.mashNetwork.createCurveWarp(name='Warped')

BookGenerator()


#2

Okay after 2 days somebody else found the solution. Maybe somebody has the same problem in the future :slight_smile:
Just add the command

cmds.connectAttr(‘curve1’ + ‘.worldSpace[0]’, ‘MASH1_Curve’ + “.inCurves[0]”, force=1)

curve1 is the Name of the curve in the scene and MASH1_Curve the name of the curveNode

Cheers


#3

This post was flagged by the community and is temporarily hidden.