artbycrunk / vscode-maya

A Visual Studio Code extension with support for coding for Maya.
MIT License
43 stars 9 forks source link

Maya command highlighting within .py #4

Closed PolyShifter closed 5 years ago

PolyShifter commented 5 years ago

Hi there I'm a newb when it comes to code writing and same to Visual Studio Code. I was wondering if there is a way to be working in a python script and still get the highlighting and the mel definitions and stuff. For me it only works inside a mel command. I'm sure there's a way and I'm just a fool for not finding it. I've tried googling it and I can't figure out the right question to ask. Sorry if this is posted in the wrong spot!

artbycrunk commented 5 years ago

hey @PolyShifter, do you have an example of the code where you write MEL inside a python file??

Visual Studio Code will switch context based on the currently detected language of the file, which I'm guessing is set to Python, in which case there will be no autocomplete or highlighting on MEL code unless you force set the file`s language to MEL.

PolyShifter commented 5 years ago

Oh darn! Okay, I was hoping to kind of add the MEL like... errr definitions to VSC's python definitions or something like that. Like, where I can see both when I'm typing in .py file. An example of python writing with MEL would be as follows:

import maya.cmds as mc

def replace_objects_single(*args):
    ###Search and replace objects and match hierarchy and name.
    inputText=''
    replaceObjectsUI = mc.promptDialog(title="Replace Objects with new Object",
                        message="Enter New Asset Name:",
                        button=['OK','Cancel'],
                        defaultButton='OK',
                        cancelButton='Cancel',
                        dismissString='Cancel')
    if replaceObjectsUI == 'OK':
        inputText=mc.promptDialog(query=True, text=True)

    selected = mc.ls(selection=True)
    for item in selected:
        mc.select(inputText, replace=True)
        mc.duplicate(returnRootsOnly=True, upstreamNodes=True, renameChildren=True)
        newObj = mc.ls(selection=True)
        childrenOfSelected = mc.listRelatives(mc.ls(sl=True), allDescendents=True)
        for child in childrenOfSelected:
            if mc.nodeType(child) == 'mesh':
                mc.select(child, replace=True)
                transNodeName=mc.listRelatives(parent=True)
                transNodeName= ''.join(transNodeName)
                newShapeName = transNodeName + 'Shape'
                newShapeName
                mc.rename(child, newShapeName)
        mc.select(clear=True)
        mc.select(item, replace=True)
        mc.select(newObj, toggle=True)
        mc.pointConstraint(offset=[0,0,0], weight=1)
        mc.orientConstraint(offset=[0,0,0], weight=1)
        mc.scaleConstraint(offset=[1,1,1], weight=1)
        mc.select(clear=True)
        mc.select(item, replace=True)
        mc.delete()

I'm not the cleanest coder by any means haha but this is pretty standard python/mel coding. This would be a .py script, and I would look for say, "scaleConstraint" but in VSC it won't show anything, and won't understand that as a command. Or show me all the awesome tags and stuff.

PolyShifter commented 5 years ago

Oh darn! Okay, I was hoping to kind of add the MEL like... errr definitions to VSC's python definitions or something like that. Like, where I can see both when I'm typing in .py file. An example of python writing would be as follows: import maya.cmds as mc def replace_objects_single(*args):

Search and replace objects and match hierarchy and name.

inputText=''
replaceObjectsUI = mc.promptDialog(title="Replace Objects with new

Object", message="Enter New Asset Name:", button=['OK','Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel') if replaceObjectsUI == 'OK': inputText=mc.promptDialog(query=True, text=True)

selected = mc.ls(selection=True)
for item in selected:
    mc.select(inputText, replace=True)
    mc.duplicate(returnRootsOnly=True, upstreamNodes=True,

renameChildren=True) newObj = mc.ls(selection=True) childrenOfSelected = mc.listRelatives(mc.ls(sl=True), allDescendents =True) for child in childrenOfSelected: if mc.nodeType(child) == 'mesh': mc.select(child, replace=True) transNodeName=mc.listRelatives(parent=True) transNodeName= ''.join(transNodeName) newShapeName = transNodeName + 'Shape' newShapeName mc.rename(child, newShapeName) mc.select(clear=True) mc.select(item, replace=True) mc.select(newObj, toggle=True) mc.pointConstraint(offset=[0,0,0], weight=1) mc.orientConstraint(offset=[0,0,0], weight=1) mc.scaleConstraint(offset=[1,1,1], weight=1) mc.select(clear=True) mc.select(item, replace=True) mc.delete() I'm not the cleanest coder by any means haha but this is pretty standard python/mel coding.

On Thu, May 30, 2019 at 9:52 AM Savio Fernandes notifications@github.com wrote:

hey @PolyShifter https://github.com/PolyShifter, do you have an example of the code where you write MEL inside a python file??

Visual Studio Code will switch context based on the currently detected language of the file, which I'm guessing is set to Python, in which case there will be no autocomplete or highlighting on MEL code unless you force set the file`s language to MEL.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/artbycrunk/vscode-maya/issues/4?email_source=notifications&email_token=AMGQMUPADJLWOFHTA4R7DPDPYAA6XA5CNFSM4HQ4AFYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWS3ZBA#issuecomment-497400964, or mute the thread https://github.com/notifications/unsubscribe-auth/AMGQMUJRNDND7KBROYPL7SLPYAA6XANCNFSM4HQ4AFYA .

artbycrunk commented 5 years ago

Firstly this is not MEL, it is all python. For the autocomplete to work you need to do this... https://github.com/artbycrunk/maya-completion

PolyShifter commented 5 years ago

Omg I even double posted. Sorry about that.

Yeah I knew it was python, but I'm using maya commands within, so I didn't really know how to word my question properly. Thanks for helping me out! This is fantastic!!

artbycrunk commented 5 years ago

No problem, glad to help. Closing this issue, let me know if you have any other concerns.