How do you get the name of a piece of geo when all you have is a component of that geo (uvs, faces, verts, edges)?
so for example I have:
MeshVertex(u'pCubeShape1.vtx[0]') #replace that with any of the following (uvs, faces, edges)
and what I would like to end up with is:
nt.Transform(u'pCube1')
How can I do this?
Say vtx = MeshVertex(u'pCubeShape1.vtx[0]')
then the transform/geo can be found using:
import pymel.core as pc
transforms = pc.listTransforms(vtx.node())
transform = transforms[0] #in case there is only one.
As your example, let's say v = MeshVertex(u'pCubeShape1.vtx[0]')
import pymel.core as pm
transform = v.node().getParent()
select(transform)
I know this question has already been answered, but I thought I'd post my way of doing this so that others can see different ways :)
Hope this helps
Related
So in my project that is on football(soccer), what I want to find is how a title winning team goes on a winning run. For eg. 18 wins in a row that helped them to the title. So I want to show the trend/pattern of how they're winnning the consecutive games. So I have a csv file in which i have columns of W/D/L ( win/draw/loss) which consist of the data for this pattern. I'm doing my project using Python but the person who obtained the image using R of which I have no idea about. So if anyone could help me in obtaining this image in Python or R, it would be appreaciated.
The image has been attached below. Thanks for any help :).
WDL pattern of teams
Here's one way to do it in R using some made up data:
library(ggplot2)
#Some test data
set.seed(0)
testdata <- expand.grid(Team=c("Liverpool","Man U","Man City","Leicester", "Wolves"), Game=1:27)
testdata$Result <- sample(factor(c("Win","Draw","Loss"), levels=c("Win","Draw","Loss")), length(testdata[[1]]),
replace=TRUE, prob=c(0.4,0.2,0.4))
#plot
ggplot(testdata, aes(x=Game, y=as.numeric(Result), fill=Result)) + facet_grid(Team~., switch="y") +
geom_tile(colour="grey80", width=1,height=1) + scale_y_reverse(breaks=NULL) +
ylab("") + scale_fill_manual(values=c(Win="green3",Draw="Orange",Loss="Red"))
This results in the following plot:
If your data is not ordered with the teams in descending order, you'd need to convert testdata$Team to a factor ordered by the position in the league, see this question for example.
I want to print all atoms except H (hydrogen) from the pdb file. Here is the file
https://github.com/mahesh27dx/molecular_phys.git
Following code prints the objects of the file
import numpy as np
import mdtraj as md
coord = md.load('alanine-dipeptide-nowater.pdb')
atoms, bonds = coord.topology.to_dataframe()
atoms
The result looks like this
From this table I want to print all the elements except H . I think it can be done in python using the list slicing. Could someone have any idea how it can be done?
Thanks!
You probably should clarify that you want help with mdtraj or pandas specifically.
Anyway, it's as simple as atoms.loc[atoms.element != 'H'].
You can do the following:
print(*list(df[df.element!='H']['element']))
If you want the unique elements, you can do this:
print(*set(df[df.element!='H']['element']))
So I am trying to make a painterly node group with Python code straight so I can use it for future projects but I can't seem to get the power part of the formula in nuke to work from this colour difference formula( I'm also new to Nuke so if there is a better way of writing this please let me know it would be awesome thank you, or if I'm doing this wrong completely also let me know)
The following formula for color difference is used to create the
difference image: |(r1,g1,b1) – (r2,g2,b2)| = ((r1 – r2)^2 + (g1
–g2)^2 + (b1 – b2)^2)^1/2.
nRedShuffle = nuke.nodes.Shuffle()
nRedShuffle['red'].setValue('red')
nRedShuffle['green'].setValue('red')
nRedShuffle['blue'].setValue('red')
nRedShuffle['alpha'].setValue('red')
nGreenShuffle = nuke.nodes.Shuffle()
nGreenShuffle['red'].setValue('green')
nGreenShuffle['green'].setValue('green')
nGreenShuffle['blue'].setValue('green')
nGreenShuffle['alpha'].setValue('green')
#...(so on for the rest of rgba1 and rgba2)
nGreenShuffle2 = nuke.nodes.Shuffle()
nGreenShuffle2['red'].setValue('green')
nGreenShuffle2['green'].setValue('green')
nGreenShuffle2['blue'].setValue('green')
nGreenShuffle2['alpha'].setValue('green')
nBlueShuffle2 = nuke.nodes.Shuffle()
nBlueShuffle2['red'].setValue('blue')
nBlueShuffle2['green'].setValue('blue')
nBlueShuffle2['blue'].setValue('blue')
nBlueShuffle2['alpha'].setValue('blue')
#I am having troubles with the powers below
redDiff = nuke.nodes.Merge2(operation='minus', inputs=[nRedShuffle2, nRedShuffle])
redDiffMuli = nuke.nodes.Merge2(operation='multiply', inputs=[redDiff, redDiff])
greenDiff = nuke.nodes.Merge2(operation='minus', inputs=[nGreenShuffle2, nGreenShuffle])
greenDiffMuli = nuke.nodes.Merge2(operation='multiply', inputs=[greenDiff, greenDiff])
blueDiff = nuke.nodes.Merge2(operation='minus', inputs=[nBlueShuffle2, nBlueShuffle])
blueDiffMuli = nuke.nodes.Merge2(operation='multiply', inputs=[blueDiff, blueDiff])
redGreenAdd = nuke.nodes.Merge2(operation='plus', inputs=[redDiffMuli, greenDiffMuli])
redGreenBlueAdd = nuke.nodes.Merge2(operation='plus', inputs=[redGreenAdd, blueDiffMuli])
Here are at least two ways to implement Color Difference formula for two images. You can use difference op in Merge node or you can write a formula in field for each channel inside MergeExpression node:
Expression for each channel is as simple as this:
abs(Ar-Br)
abs(Ag-Bg)
abs(Ab-Bb)
Python commands
You can use .nodes.MergeExpression methodology:
import nuke
merge = nuke.nodes.MergeExpression(expr0='abs(Ar-Br)',
expr1='abs(Ag-Bg)',
expr2='abs(Ab-Bb)')
or regular .createNode syntax:
merge = nuke.createNode('MergeExpression')
merge['expr0'].setValue('abs(Ar-Br)')
merge['expr1'].setValue('abs(Ag-Bg)')
merge['expr2'].setValue('abs(Ab-Bb)')
Full code version
import nuke
import nukescripts
red = nuke.createNode("Constant")
red['color'].setValue([1,0,0,1])
merge = nuke.createNode('MergeExpression')
merge['expr0'].setValue('abs(Ar-Br)')
merge['expr1'].setValue('abs(Ag-Bg)')
merge['expr2'].setValue('abs(Ab-Bb)')
yellow = nuke.createNode("Constant")
yellow['color'].setValue([1,1,0,1])
merge.connectInput(0, yellow)
nuke.toNode('MergeExpression1').setSelected(True)
nukescripts.connect_selected_to_viewer(0)
# Auto-alignment in Node Graph
for everyNode in nuke.allNodes():
everyNode.autoplace()
Consider! MergeExpression node is much slower that regular Merge(difference) node.
In maya I am simulating hair and I want to lock the curves that are jittering. I duplicated those curves to make blend shapes, but there are too many to blend shape them individually. Is there a way to script to solve this? I think the way is to slice to get the name/number of the curves and blendShape all of them with a loop. But since I'm new to scripting I need help.
You can get follicles with this command :
fols = cmds.ls(type='follicle')
After that, find the curves simulated :
crvs = cmds.ls(fols, dag=True, type='nurbsCurve')
Loop through those curves and use :
dup = cmds.duplicate(c)[0] # where c is the iterator of the for loop on crvs
then :
bs = cmds.blendShape(dup, c)
You have few flags on every command but it should help you like name, weight and few more.
I don't have maya for few weeks so I hope it will help you
EDIT :
Not that follicle curves are set as intermediate, for blendshaping, you might need to temporarly set them :
cmds.setAttr(c+'.io', 0)
bs = cmds.blendShape(dup, c)
cmds.setAttr(c+'.io', 1)
I am looking at the sample code from the link below (Example 2: Italy Street Image with Wave Style).
https://github.com/dipanjanS/practical-machine-learning-with-python/blob/master/notebooks/Ch12_Deep_Learning_for_Computer_Vision/Neural%20Style%20Transfer%20Results%20-%20High%20Resolution.ipynb
Also, looking at input images from the link below.
https://github.com/dipanjanS/practical-machine-learning-with-python/tree/master/notebooks/Ch12_Deep_Learning_for_Computer_Vision/results/italy%20street
My question is this. Why is iteration_1.png to iteration_20.png being read into the code?
is_content_image = io.imread('results/italy street/italy_street.jpg')
is_style_image = io.imread('results/italy street/style1.png')
is_iter1 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_1.png')
is_iter5 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_5.png')
is_iter10 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_10.png')
is_iter15 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_15.png')
is_iter20 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_20.png')
It seems like you would read in italy_street.jpg and style1.png, and the code should do the work of blending the images together, so after several iterations they are merged into a contamination of the two images. This seems intuitive, rather than doing 'io.imread' for several images, and then saving each image after each iteration. Am I missing something basic here? Or, is there a better demo other there, which shows how to blend two images together? Thanks for the look.