Maxscript Python addModifier - python

I'm writing maxscript in python and the following code throws a type error:
import MaxPlus
res = MaxPlus.Core.GetRootNode()
#This is just as example that I use the first child.
child = MaxPlus.INode.GetChild(res,0)
morpherFP = MaxPlus.FPValue()
MaxPlus.Core.EvalMAXScript("Morpher()", morpherFP)
morpher = MaxPlus.FPValue.Get(morpherFP)
MaxPlus.INode.AddModifier(child, morpher)
And from the MaxScript Listener I always receive the following error:
type 'exceptions.TypeError' in method 'INode_AddModifier', argument 2 of type 'Autodesk::Max::Modifier'"
while the type of morpher is Animatable(Morpher) and Animatable is a subclass of Modifier. Could someone help me with this?
Thank you in advance

I think I found a possible solution (The only thing I know is that the MaxScript Listener doesn't throw an error):
import MaxPlus
res = MaxPlus.Core.GetRootNode()
#I use the first child as example
child = MaxPlus.INode.GetChild(res,0)
morpher = MaxPlus.Factory.CreateObjectModifier(MaxPlus.ClassIds.Morpher)
MaxPlus.INode.AddModifier(child, morpher)
# the following also seems to work aka it does not throw any errors
child.InsertModifier(morpher,1)
Let me know if it is not correct or there is an easier or more understandable way.

Related

How to build CDK Assembly using Python aws_cdk.cx_api

I'm desperate so any help is appreciated.
I'm trying to modify my current CDK out using cloud assembly in Python.
I can't find any examples, nor proper documentation for python, only reference guide.
This is my code:
import os
import subprocess
import aws_cdk.cx_api as cxapi
import aws_cdk.cloud_assembly_schema as cxschema
class my_class():
def synth():
ASSEMBLY_PATH = 'igor_cdk'
result = subprocess.run(['cdk', 'synth', '-o', ASSEMBLY_PATH], stdout=subprocess.PIPE)
my_stuff = result.stdout.decode('utf-8')
new_stack_name = original_stack_name+TEMP_OUT
print(new_stack_name)
cloud_assembly = cxapi.CloudAssembly(ASSEMBLY_PATH);
orig_stack_assembly = cloud_assembly.get_stack_by_name(original_stack_name)
logical_Ids = orig_stack_assembly.find_metadata_by_type("aws:cdk:logicalId")
cab = cxapi.CloudAssemblyBuilder(ASSEMBLY_PATH)
cab.add_artifact(new_stack_name, type = cxschema.ArtifactType.ASSET_MANIFEST, properties = orig_stack_assembly.manifest)
Then, In my dummy test, I call this:
print(stack_info.synth("Test", "Targeta"))
And that's executed with pytest.
Just for comparison, I got it working in Typescript:
const cab: CloudAssemblyBuilder = new CloudAssemblyBuilder(ASSEMBLY_PATH);
cab.addArtifact(new_stack_name, stack.manifest);
cab.buildAssembly();
I expected similar/same behavior, but I just can't figure out how to do it in python, and since my whole code base is in python, I'd just love to have it all done in one place, rather than reworking the whole thing in TS.
Edit:
If I pass the stack.manifest, I'm getting the following error:
jsii.errors.JSIIError: Value did not match any type in union:
Wire struct type '#aws-cdk/cloud-assembly-schema.ArtifactManifest' does not match expected '#aws-cdk/cloud-assembly-schema.AwsCloudFormationStackProperties', Wire struct type '#aws-cdk/cloud-assembly-schema.ArtifactManifest' does not match expected '#aws-cdk/cloud-assembly-schema.AssetManifestProperties',
Wire struct type '#aws-cdk/cloud-assembly-schema.ArtifactManifest' does not match expected '#aws-cdk/cloud-assembly-schema.TreeArtifactProperties',
Wire struct type '#aws-cdk/cloud-assembly-schema.ArtifactManifest' does not match expected '#aws-cdk/cloud-assembly-schema.NestedCloudAssemblyProperties'
And if I pass the whole stack assembly object, I run in even weirder problem:
jsii.errors.JavaScriptError:
RangeError: Maximum call stack size exceeded
at /private/var/folders/z6/c91mcs6j4g93t2856_p_51nr0000gn/T/jsii-kernel-35iS5M/node_modules/#aws-cdk/cx-api/lib/cloud-assembly.js:307:53

Create A FIX Message using Quickfix Python

I am a very new user to Quickfix Python. I want to send a QuoteRequest. My function to create a new quote request message is as below:
import quickfix as fix
def create_quote_request():
message = fix.Message()
header = message.getHeader()
header.setField(fix.MsgType(fix.MsgType_QuoteRequest))
gp = fix.Group()
gp.setField(fix.Symbol("GBPUSD"))
gp.setField(fix.Side(fix.Side_BUY))
gp.setField(fix.Account("TestAcc"))
gp.setField(fix.Currency("GBP"))
message.addGroup(gp)
fix.Session.sendToTarget(message, self.sessionID)
When I execute the code, I am getting error as below:
NotImplementedError: Wrong number r type of arguments for overloaded function 'new_group'.
Possible C/C++ prototypes are:
FIX::Group::Group(int, int)
FIX::Group::Group(int, int, int const[])
FIX::Group::Group(int, int, message_order const &)
FIX::Group::Group(FIX::Group const &)
I did read the documentation and found that the Group object requires arguments
Group(int field, int delim)
Not sure what to pass the values for field and delim. Appreciate your response and help.
not sure I´m on time to help. But I will try. I think #JimmyNJ is giving you proper answer.
According to official doc you can easily do it, but you don´t have to use a generic group, you have to use specific group available to your kind of message.
As far as I know, you should program something like this.
from quickfix44 import QuoteRequest
import quickfix as fix
message = QuoteRequest()
group = QuoteRequest.NoRelatedSym()
group.setField(fix.Symbol("GBPUSD"))
group.setField(fix.Side(fix.Side_BUY))
group.setField(fix.Account("TestAcc"))
group.setField(fix.Currency("GBP"))
message.addGroup(group)
I´m assuming you want to add these 4 tags into NoRelatedSym group, based in their tag numbers. I´ve also used FIX 44 version, maybe you are using a different version, but main idea is the same.

Getting a selection in 3ds Max into a list in Python

I am writing in Python, sometimes calling certain aspects of maxscript and I have gotten most of the basics to work. However, I still don't understand FPValues. I don't even understand while looking through the examples and the max help site how to get anything meaningful out of them. For example:
import MaxPlus as MP
import pymxs
MPEval = MP.Core.EvalMAXScript
objectList = []
def addBtnCheck():
select = MPEval('''GetCurrentSelection()''')
objectList.append(select)
print(objectList)
MPEval('''
try (destroyDialog unnamedRollout) catch()
rollout unnamedRollout "Centered" width:262 height:350
(
button 'addBtn' "Add Selection to List" pos:[16,24] width:88 height:38
align:#left
on 'addBtn' pressed do
(
python.Execute "addBtnCheck()"
)
)
''')
MP.Core.EvalMAXScript('''createDialog unnamedRollout''')
(I hope I got the indentation right, pretty new at this)
In the above code I successfully spawned my rollout, and used a button press to call a python function and then I try to put the selection of a group of objects in a variable that I can control through python.
The objectList print gives me this:
[<MaxPlus.FPValue; proxy of <Swig Object of type 'Autodesk::Max::FPValue *' at 0x00000000846E5F00> >]
When used on a selection of two objects. While I would like the object names, their positions, etc!
If anybody can point me in the right direction, or explain FPValues and how to use them like I am an actual five year old, I would be eternally grateful!
Where to start, to me the main issue seems to be the way you're approaching it:
why use MaxPlus at all, that's an low-level SDK wrapper as unpythonic (and incomplete) as it gets
why call maxscript from python for things that can be done in python (getCurrentSelection)
why use maxscript to create UI, you're in python, use pySide
if you can do it in maxscript, why would you do it in python in the first place? Aside from faster math ops, most of the scene operations will be orders of magnitude slower in python. And if you want, you can import and use python modules in maxscript, too.
import MaxPlus as MP
import pymxs
mySel = mp.SelectionManager.Nodes
objectList = []
for each in mySel:
x = each.Name
objectList.append(x)
print objectList
The easiest way I know is with the
my_selection = rt.selection
command...
However, I've found it works a little better for me to throw it into a list() function as well so I can get it as a Python list instead of a MAXscript array. This isn't required but some things get weird when using the default return from rt.selection.
my_selection = list(rt.selection)
Once you have the objects in a list you can just access its attributes by looking up what its called for MAXscript.
for obj in my_selection:
print(obj.name)

pyvmomi:error when calling RelocateVM

Hi I am using pyvmomi API, to perform vmotions against a cluster when DRS is set to manual mode. I am going through a vcenter and querying a cluster and getting recommendation and using that to perform the Vmotions. The code is something like this.
content=getVCContent(thisHost, {'user':username,'pwd':decoded_password},logger)
allClusterObj = content.viewManager.CreateContainerView(content.rootFolder, [pyVmomi.vim.ClusterComputeResource], True)
allCluster = allClusterObj.view
for thisDrsRecommendation in thisCluster.drsRecommendation:
print thisDrsRecommendation.reason
for thisMigration in thisDrsRecommendation.migrationList:
print ' vm:', thisMigration.vm.name
while True:
relocate_vm_to_host(thisMigration.vm.name,thisMigration.destination.name, allClusterObj.view)
#FUNCTION definition
def relocate_vm_to_host(vm, host , allCluster):
for thisCluster in allCluster:
for thisHost in thisCluster.host:
if thisHost.name == host:
for thisVm in thisHost.vm:
print 'Relocating vm:%s to host:%s on cluster:%s' %(thisVm.name,thisHost.name,thisCluster.name)
task = thisVm.RelocateVM(priority='defaultpriority')
I am getting an error saying the attribute doesn't exist.
AttributeError: 'vim.VirtualMachine' object has no attribute 'RelocateVM'
But the pyvmomi documentaion here https://github.com/vmware/pyvmomi/blob/master/docs/vim/VirtualMachine.rst
has a detailed explanation for the method
RelocateVM(spec, priority):
Anyone know what's the reason the method is missing? I also tried checking the available methods of the object ,that has RelocateVM_Task ,instead of RelocateVM(for which I couldn't find documentation) When I used that I get this error
TypeError: For "spec" expected type vim.vm.RelocateSpec, but got str
I checked the documentation for vim.vm.RelocateSpec, I am calling it in a function , but still throws an error.
def relocate_vm(VmToRelocate,destination_host,content):
allvmObj = content.viewManager.CreateContainerView(content.rootFolder, [pyVmomi.vim.VirtualMachine], True)
allvms = allvmObj.view
for vm in allvms:
if vm.name == VmToRelocate:
print 'vm:%s to relocate %s' %(vm.name , VmToRelocate)
task = vm.RelocateVM_Task(spec = destination_host)
Any help is appreciated.
Thanks
Looks like a mistake in the documentation. The method is called Relocate (and not RelocateVM).
Note, BTW, that in your first sample you're not passing the destination host to the call to Relocate so something is definitely missing there.
You can see some samples at https://gist.github.com/rgerganov/12fdd2ded8d80f36230f or at https://github.com/sijis/pyvmomi-examples/blob/master/migrate-vm.py.
Lastly, one way to realize you're using the wrong name is by calling Python's dir method on a VirtualMachine object. This will list all properties of the object so you can see which methods it has:
>>> vm = vim.VirtualMachine('vm-1234', None)
>>> dir(vm)
['AcquireMksTicket', [...] 'Relocate', 'RelocateVM_Task', [...] ]
(abbreviated output)

How to use TideSDK openFolderChooseDialog

I'm trying to use TideSDK and python tp get the user to select a folder from the hard drive. Everything works, but I have no idea how obtain which folder the user selected.
I can't seem to find documentation on what Ti.UI.UserWindow.openFolderChooseDialog returns and what kind of object the callback function uses. I just get errors that "window" in "onopen" in my code below is a None Type object when I try to print it out.
Is there any documentation on the proper use of the openFolderChooseDialog, what signature the callback needs to be and how to get the Folder/directory from the dialog?
My code:
def onopen(window):
Ti.App.stdout("------------------ Opening Dialog")
Ti.App.stdout(window)
def burndir():
try:
dir = Ti.UI.getCurrentWindow().openFolderChooserDialog(onopen)
Ti.App.stdout(dir)
except:
Ti.App.stderr("------ There was an error: ")
Ti.App.stderr(sys.exc_info()[0])
Ti.App.stderr(sys.exc_info()[1])
Ti.App.stderr(sys.exc_info()[2])
Any help is much appreciated
I found the answer in a Javascript Code example here:
https://github.com/appcelerator/titanium_developer/blob/master/Resources/perspectives/projects/js/projects.js#L1338
It appears that openFolderChooserDialog return nothing (a None object in Python). The callback function passes one argument which is a StaticBoundList (a Tuple object in Python) that contains all of the selected folders (in case of allowing multiple selections)
Here is the updated code:
def onopen(window):
if (len(window) > 0):
Ti.App.stdout("------------------ Opening Dialog")
Ti.App.stdout(window[0])
else:
Ti.App.stdout("------------------ Nothing Selected")
def burndir():
try:
Ti.UI.getCurrentWindow().openFolderChooserDialog(onopen)
except:
Ti.App.stderr("------ There was an error: ")
Ti.App.stderr(sys.exc_info()[0])
Ti.App.stderr(sys.exc_info()[1])
Ti.App.stderr(sys.exc_info()[2])
I hope this helps someone struggling to find the same documentation!

Categories

Resources