Python Forum
[Maya] MASH Curve node in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Maya] MASH Curve node in Python
#1
Hi,

I am working on a book row generator. For that I want to let the customer place a curve and the books should be placed on that curve. Because I failed to do it with a normal curve I am trying it now with MASH. My problem is now that I can't figure out a way to bring the curve into the Mashnode via my script.
Right now I deleted everything that is in connection with the curve Node. But I was also trying to use ‘mashNetwork.createCurveWarp’, but I can't figure out what the attributes for the command is.

Thank you for every help and hint

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



class SetMaterial:

    # create a shader
    shader = cmds.shadingNode("blinn", asShader=True)
    # a file texture node
    file_node = cmds.shadingNode("file", asTexture=True)
    # a shading group
    shading_group = cmds.sets(renderable=True, noSurfaceShader=True, empty=True)
    # connect shader to sg surface shader
    cmds.connectAttr('%s.outColor' % shader, '%s.surfaceShader' % shading_group)
    # connect file texture node to shader's color
    cmds.connectAttr('%s.outColor' % file_node, '%s.color' % shader)

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=0, max=10, field=True)
        self.thicknessBooks = cmds.intSliderGrp(l="Thickness of Books", min=0, max=10, field=True)
        self.randomSize = cmds.floatSliderGrp(l="Randomize Size", min=0, max=1, 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')

        # set material
        self.material = SetMaterial()
        #self.material.apply_mat_to_object('Line002')

        numberOfBooks = cmds.intSliderGrp(self.numberOfBooks, q=True, v=True)
        scaleOfRandomize = cmds.floatSliderGrp(self.randomSize, q=True, v=True)
        sizeBooks = cmds.intSliderGrp(self.sizeBooks, q=True, v=True)
        thicknessBooks = cmds.intSliderGrp(self.thicknessBooks, 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)

        # creating the randomNode
        self.randomNode = self.mashNetwork.addNode("MASH_Random")

        # changing the initial randomnode attributes
        cmds.setAttr(self.randomNode.name + ".positionX", 0)
        cmds.setAttr(self.randomNode.name + ".positionY", 0)
        cmds.setAttr(self.randomNode.name + ".positionZ", 0)

        # creating the randomNode
        self.randomNode = self.mashNetwork.addNode("MASH_Random")

        # changing the initial randomnode attributes
        cmds.setAttr(self.randomNode.name + ".scaleY", sizeBooks )
        cmds.setAttr(self.randomNode.name + ". scaleX", thicknessBooks)
        cmds.setAttr(self.randomNode.name + ".randEnvelope", scaleOfRandomize)
        cmds.setAttr(self.randomNode.name + ".Envelope", 0.2)


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




BookGenerator()
Reply
#2
Okay after 2 days somebody else found the solution. Maybe somebody have the same problem in the future :)
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a UI with scale tool using python Maya giorgosg12 0 2,161 Jul-21-2020, 09:18 AM
Last Post: giorgosg12
  Line of best fit for forward bias curve? StillAnotherDave 6 3,097 Feb-05-2020, 12:46 PM
Last Post: jefsummers
  Finding the Young's Modulues in a curve stress strain AicramM 1 4,412 Nov-03-2018, 09:01 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020