Say I have an ASC file with 100 (x,y,z) coordinates (representing a helix-like world line trajectory). I want to import that file in Maya and create a NURBS with each of the coordinate from my ASC file as a control point.
I know how to import asc files in python but I don't know how to create NURBS control point out of it!
I assume it should be a simple script but I am new to MEL script and Maya driven Python. Any script snippet in MEL or Python to get it working?
Thanks!
the curve command takes an argument with the flag p (for 'points'). So a simple linear curve from 0,0,0 to 1,0,0 looks like
import maya.cmds as cmds
cmds.curve( p=[(0,0,0), (1,0,0)], d = 1)
and a degree-3 nurbs curve might look like
cmds.curve( p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9)], d=3 )
Your script will have to convert the asc points to XYZ values. If you are reading these yourself from a text file you'll have to the use standard python open command to open and read from a file. If you already have locators or other physical objects in your scene you can get their positions with the xform command. This will get the position of an object named 'locator_name_goes_here' as an XYZ tuple.
loc_pos = cmds.xform('locator_name_goes_here', q=True, t=True, ws=True)
So.to run a curve through a bunch of points you would collect all of their positions in a big list and then pass that whole list to the curve command's p flag:
# assuming all locators or objects are selected in order
locator_positions = []
for each_locator in cmds.ls(sl=True):
locator_positions.append (cmds.xform(each_locator, q=True, t=True, ws=True)
cmds.curve(p=locator_positions, d=3)
Related
I have a geodataframe with many polygons. I'd like to automate differencing with a loop, to do this with each preceding and following polygon and add them to a new gdf:
new_gdf = polygon[0:1].overlay(polygon[1:2], how='difference')
I am able to do this one at a time, but I'd like to find a more efficient way, especially when I will (someday) have a lot of polygons.
Would anyone have an idea of how I might do this? I'm trying to use iterrows(), but am failing on the exact syntax.
Thank you in advance.
Instead of overlay() you might be looking for GeoSeries.difference()
Returns a GeoSeries of the points in each aligned geometry that are
not in other.
Would be something like this:
from shapely.geometry import Polygon
import geopandas as gpd
# sample polygons
polys = gpd.GeoDataFrame(geometry=[
Polygon([(0,0), (2,0), (2,2), (0,2)]),
Polygon([(1,1), (3,1), (3,3), (1,3)]),
Polygon([(2,2), (4,2), (4,4), (2,4)]),
Polygon([(3,3), (5,3), (5,5), (3,5)])])
# polys.iloc[:-1] : rows 0 .. 2 (exclude last row as df sizes must match)
# polys.iloc[1:] : rows 1 .. 3
# align=False : do not aligns GeoSeries based on their indices;
# order of elements is preserved.
diffs = polys.iloc[:-1].difference(polys.iloc[1:], align=False)
Sample polys GeoDataFrame:
Resulting diffs GeoDataSeries:
So, right now, the formula below successfully queries data from another file, butthis based on a column's data as the criteria. The need is to have more than one criteria and I'm not sure if thecolumn to be compared against needs to come in as an additional query, together with the first query...so I'm lost here.
This is the formula I'm using:
=Arrayformula(
if(F9:F="";"";
vlookup(A9:A;
QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxxXXXXXXXxxxxxXXXX/edit";"Costura!A1:R");
"select Col6, Col8, Col14";0)
;2;0)
)
)
Here's a sample file with dummy data!
can be done like this:
=ARRAYFORMULA(IF(B6:B="",,IFNA(VLOOKUP(A6:A&B6:B,
{QUERY(Data!A1:J, "select A", 0)&
QUERY(Data!A1:J, "select H", 0),
QUERY(Data!A1:J, "select J", 0)}, 2, 0))))
which will translate into this:
=ARRAYFORMULA(IF(B6:B="",,IFNA(VLOOKUP(A6:A&B6:B,
{IMPORTRANGE("1gh5w0czg2JuoA3i5wPu8_eOpC4Q4TXIRhmUrg53nKMU", "Data!A:A")&
IMPORTRANGE("1gh5w0czg2JuoA3i5wPu8_eOpC4Q4TXIRhmUrg53nKMU", "Data!H:H"),
IMPORTRANGE("1gh5w0czg2JuoA3i5wPu8_eOpC4Q4TXIRhmUrg53nKMU", "Data!J:J")}, 2, 0))))
For a system like this, the best practice is just to import the entirety of the imported data in a tab of it's own, then run a vlookup to that tab using "both" criteria. This will simplify your formulas and also does not increase processing time at all. Just hide the "naked" import tab.
I will demonstrate on your sample sheet in two tabs beginning with "MK".
but the basic idea is an ampersanded (&'ed) [search key] in your VLOOKUP()
=ARRAYFORMULA(IFERROR(VLOOKUP(A6:A&B6:B,{MK_Data!A:A&MK_Data!H:H,MK_Data!J:J},2,0)))
I want to use FashionGen dataset that has 2 h5 format file for train and validation data. The h5 file's list of datasets are like this:
index
index_2
input_brand
input_category
input_composition
input_concat_description
input_department
input_description
input_gender
input_image
input_msrpUSD
input_name
input_pose
input_productID
input_season
input_subcategory
And I just need the "Input_image" and "Input_description" datasets. Would you mind help me please?
Details depend on the dataset dtype and shape and Python objects to be created. This code will get you started. Review h5py docs for details. h5py Quick Start Guide. Note: dataset and group names are case sensitive. Be sure to verify if they are "Input_image" or "input_image".
with h5py.File(filename,'r') as h5f:
# create NumPy array from image dataset:
image_arr = h5f['input_image'][:]
# create NumPy array from description dataset:
descr_arr = h5f['input_description'][:]
Note: if the datasets are too large to fit into memory, you can use h5py dataset objects and reference as-if they are NumPy arrays. The code is very similar. See below:
with h5py.File(filename,'r') as h5f:
# create h5py object of images dataset:
image_ds = h5f['input_image']
# create NumPy object of description dataset:
descr_ds = h5f['input_description']
I'm basically importing both Tables from this website.
Q1. When I'm importing data via IMPORTHTML and sorting out results, some results are showing as "5 cases or less". It's making it hard to sort it out. I want these to come after 0. How can I make sure of that?
Q2. I wish to import only the numbers from the element. It's basically a whole phrase. How do I only import the last number, in such case, 1,991?
Here is my Sample Google Sheet
try:
=ARRAY_CONSTRAIN(SORT({IMPORTHTML(
"https://santemontreal.qc.ca/en/public/coronavirus-covid-19/",
"table", 1), REGEXREPLACE(SUBSTITUTE(IMPORTHTML(
"https://santemontreal.qc.ca/en/public/coronavirus-covid-19/", "table", 1),
"5 cases or less", 0), "\*", )*1}, 6, 0), 99^99, 2)
not sure if you want 3rd and 4th column too so if you do then change 2 to 4
=REGEXREPLACE(IMPORTXML(
"https://santemontreal.qc.ca/en/public/coronavirus-covid-19/",
"//div[#id='c36390']/h4[2]"), "(.*) ", )*1
I have a animation which is okay from 1 to 50 keys. after 50th key I want the keys to be rotated by 180 degrees
I can use the below command to rotate 1 controller in 1 selected key
//mel
rotate -y 50 -ws -p 5 6 7;
but is very time consuming how can I do it for all selected controllers and keys ?
so it there a straight forward way to execute a mel command on keys. and how to proceed doing something like this?
I'm doing this in python, since it's far easier to solve in Python than mel. It's pretty bare bones but it should be a good starting point:
import maya.cmds as cmds # cmds is the python version of mel's api
obj = 'rig:rig:Root' # your obj.. in real code you'd make a
# function and ask for an object name
attributes = 'rx', 'ry', 'rz' # need to ask where the keys for on each channel
rotation_keys = set() # this avoids duplications of key times
# collect a list of all the frames which have any rotation key
for attrib in attributes:
for key in cmds.keyframe(obj, attribute = 'rx', q=True, tc=True):
rotation_keys.add(key)
# sort them by time, you now have a list of every rotate key time
keyframe_list = sorted(rotation_keys)
for key in keyframe_list:
if key > 50:
# scrub to the right time
cmds.currentTime(key)
# apply the rotation relatively
cmds.xform(obj, rotation = [0,180,0], ws =True, relative = True)
# get the channel values and make sure they are all keyed
for attrib in attributes:
new_value = cmds.getAttr(obj + "." + attrib)
cmds.setKeyframe(obj, attribute = attrib, time = key, value = new_value)
The simple solution is to group your animated node, and set a key to rotate the group after frame 50.
If that's not an option, there is a common technique for putting the result of accumulated hierarchical animation onto a single node. It uses constraint nodes. You don't need to do any programming, but you can script the steps if you like.
Create a locator at the origin.
Select your node and shift select the locator.
Choose Constrain->Orient
Choose Constrain->Point (not necessary, but visually helpful)
Select the locator only.
Choose Edit->Keys->BakeSimulation [] (keys from channel-box, sample
by 1,disable implicit control)
Hilight translate and rotate channels in the channel box and hit the
Bake button.
The locator now moves and rotates with your node. The key values may be different if your node is in some hierarchy, but the motion should be coincident. Now you can modify the motion and transfer it back with the same process:
Group the locator, set the group pivot and and animate the group
until the locator has the desired motion.
Delete the keys on your node.
Select the locator and shift select your node.
Choose Constrain->Orient, then choose Constrain->Point.
Now your node moves with the modified locator motion. At this stage, you can modify the locator animation further, tweak, add more group transforms and so on. Your node will update.
Finally, select your node and choose Keys->BakeSimulation with the same options as above, and delete the locator group.