When I take 2 objects in Maya and combine them, the pivot of the combined object is the center of the world, therefore I am using the Modify → Center Pivot option.
But after that the object has different center from other objects, for example when I set its location to (0, 0, 0) it is not the world's center.
I know I can take the combined object and move it to the world's center and then use Modify → Center Pivot but it is inaccurate.
Is there something I am missing? How can I center an object's pivot and keep it relative to the world?
This is what I mean, as you can see the object is in (0,0,0) location but not the world's center:
What's going on is that when you're using center pivot, instead of effecting the object's translate values it offsets it with its pivots instead (local rotate pivot attribute). So even though your translates are all zero, the values from the pivots cause your object to be offset from the world origin.
Although this makes sense knowing the above, it's still pretty annoying how Maya handles it.
Here's a script that will try to fix that. What it's essentially doing is taking its pivot values, zeroing it out, and adding it to its translation:
Maya 2018
import maya.cmds as cmds
sel = cmds.ls(sl=True)[0] # Get selection.
cmds.xform(sel, cpc=True) # Center its pivot. Comment this out if you don't want to force it to center and use the pivot as-is.
pivots = cmds.xform(sel, q=True, piv=True)[:3] # Get its pivot values.
temp_nul = cmds.createNode("transform") # Create a temporary transform.
cmds.matchTransform(temp_nul, sel) # Align the transform to our object.
try:
cmds.xform(sel, piv=[0, 0, 0]) # Zero-out object's pivot values.
cmds.move(-pivots[0], -pivots[1], -pivots[2], "{}.vtx[*]".format(sel), os=True, r=True) # Negate and move object via its old pivot values.
cmds.matchTransform(sel, temp_nul) # Align the object back to the temporary transform, to maintain its old position.
finally:
cmds.delete(temp_nul) # Delete temporary transform.
cmds.select(sel) # Restore old selection.
Maya 2016 and <
import maya.cmds as cmds
import maya.mel as mel
sel = cmds.ls(sl=True)[0] # Get selection.
mel.eval("CenterPivot;") # Center its pivot. Comment this out if you don't want to force it to center and use the pivot as-is.
pivots = cmds.xform(sel, q=True, piv=True)[:3] # Get its pivot values.
old_tm = cmds.xform(sel, q=True, ws=True, m=True) # Get its transform matrix.
temp_nul = cmds.createNode("transform") # Create a temporary transform.
cmds.xform(temp_nul, ws=True, m=old_tm) # Align it to the matrix.
cmds.xform(temp_nul, os=True, r=True, t=pivots) # Move it to include the pivot offsets.
new_tm = cmds.xform(temp_nul, q=True, ws=True, m=True) # Store it's transform matrix to align to later.
try:
cmds.xform(sel, piv=[0, 0, 0]) # Zero-out object's pivot values.
cmds.move(-pivots[0], -pivots[1], -pivots[2], "{}.vtx[*]".format(sel), os=True, r=True) # Negate and move object via its old pivot values.
cmds.xform(sel, ws=True, m=new_tm) # Align the object back to the temporary transform, to maintain its old position.
finally:
cmds.delete(temp_nul) # Delete temporary transform.
cmds.select(sel) # Restore old selection.
Select your object then execute the script to run it. I tested it on a combined object with random rotations, while being parented to an object with a random rotation. It seems to work ok without popping.
You can also achieve the same effect with a combo of nodes using a polyMoveVertex node instead of scripting.
Related
Hi I need the text to be in a specific format in a spreadsheet to be able to upload it on a translation tool.
I have already used the text split function to separate the text in a cell with bullet points, moving each bullet point to a separate cell.
enter image description here
Then I used the transpose function to separate each set of data. For context, you are looking at fashion products.
The name of the product is on the first row, followed by a list of features (e.g. "Bracciale" means bracelet and it is followed by the list of materials)
enter image description here
Now for the last step, I need these sets to be vertical, not horizontal. Like this:
enter image description here
I would like to set up an automatic system so that every time we receive a list with hundreds of these products we do not need to copy-paste them one below the other.
With pivot tables maybe? Keep in mind that if it is too complex it might be hard to train the translators to do it each time. Please let me know your suggestions. Thank you!
I am not a programmer. I tried pivot tables but the data was in the wrong order and I am not sure how to get the data out from the pivot table with values only without the sub-menus.
My suggestion would be to use the 'Unpivot Columns' feature in the Power Query Editor - it would be really simple.
Steps:
Select the whole range
Go to Data // Get & Transform Data // From Table/Range
Uncheck 'My Table has headers' (unless it does - but doesn't look like it?)
Press OK. This will open Power Query Editor and will have actually given you column names Col1/2/3 etc, but ignore that.
Go to Add Column // Index column
Select all columns EXCEPT the new index column by Shift+clicking on those headers
Go to Transform // Unpivot Columns
Assuming the order is important, click in the Attribute column and Sort Ascending
Click in the Index column and Sort Ascending
Remove the Attribute and Index columns if you want (right click header)
Go to File // Close & Load
You will get a new table - dynamically linked to the first (ie. can be updated/refreshed) - in the unpivoted format.
Let me know if you need more details / screenshot?
Based of this trick, maybe the following is helpfull:
Formula in A5:
=DROP(REDUCE(0,A1:A3,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b,,HSTACK(CHAR(10),"^"),1)))),1)
TEXTSPLIT() will use a combination of newline chars and the circumflex to split the input directly into a vertical array;
Iteration in REDUCE() will allow for stacked results;
DROP() the initial value from results.
I have a data set with the columns Time, fluoresence,compound concentration, and replicate. I plotted the data in ggplot by facet wrapping giving me:
all data
I want to remove the blue line in the center plot where concentration =.316 and replicate =3. I tried:
data %>%
subset(Concentration_uM!=0.316 & replicate!=3)%>%
ggplot()+ ...
which gave me:
subset not as desired.
Note that this removes all of the data where concentration =0.316, then removes all of the data where replicate =3. What I want is to remove only the data where concentration = 0.316 and also replicate =3.
What I want is:
desired subset
I know that I can achieve this by pasting concentration and replicate vectors together into a new vector and subsetting by that (essentially how I made the desired plot), but am wondering if there is a way to avoid creating a new vector.
i am trying to add a table to a presentation using python-pptx with a specific dimensions
i created a slide layout from power-point which contains the table placeholder in the area i want and loaded it using python-pptx.
slide_layout
but regardless of the placeholder dimensions, the table itself after creation is exceeding the placeholder are.
mainly it is dependent on the number of rows as per the documentation "The table's height is determined by the number of rows."
shape_id, name, height = self.shape_id, self.name, Emu(rows * 370840)
i tried to update the placeholder.py file manually and change the row height but the same output appears.
shape_id, name, height = self.shape_id, self.name, Emu(rows * 18429)
the table is insisting on exceeding the placeholder area as per the below image
output
below is my code, any clues ?
from pptx import Presentation
# the presentation including the table placeholder
prs = Presentation('Presentation2.pptx')
slide1 = prs.slides.add_slide(prs.slide_layouts[11])
table_placeholder = slide1.shapes[0]
shape = table_placeholder.insert_table(rows=22,cols=2)
prs.save('test.pptx')
Tables in PowerPoint expand vertically to accommodate new rows; that's just the way they work. You will need to do any resizing yourself, which you may find is a challenging problem. This isn't the same kind of problem when a user is creating a table in the application because they will just make adjustments for fit until it looks best for their purposes.
You'll need to adjust font-size and row-height and perhaps other attributes like column-width etc. based on your application and whatever heuristics you can resolve, perhaps related to the row count and length of text in certain cells and so on.
A table placeholder really just gives a starting position and width.
I have the air quality(link here) dataset that contains missing values. I've imputed them while creating a dummy dataframe[using df.isnull()] to keep track of the missing values.
My goal is to generate a pairplot using seaborn(or otherwise - if any other simpler method exists) that gives a different color for the imputed values.
This is easily possible in matplotlib, where the parameter c of plt.plot can be assigned a list of values and the points are colored(but the problem is I can plot only against two columns and not a pairplot). A possible solution is to iteratively to create subplots against pairs of columns(which can make the code quite complicated!!)
However, in Seaborn (which already has the builtin function for pairplot) you are supposed to provide hue='column-name' which is not possible in this case as the missingness is stored in the dummy dataframe and need to retrieve the corresponding columns for color coding.
Please let me know how I can accomplish this in the simplest manner possible.
I have a QGridLayout instance in a window, to which I dynamically add a series of widgets, depending on which values are checked on another QListView instance.
For each checked item in the list, I add a slider and two labels (for value and name), on a row of the layout, in positions 0, 1, 2.
for index in range(self.model.rowCount()):
if self.model.item(index).checkState():
slid = QSlider(Qt.Horizontal)
sl_val_lbl = QLabel("--")
sl_val_lbl.setMaximumWidth(150) #(a)
#sl_val_lbl.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding) #(b)
sl_name_lbl = QLabel(self.model.item(index).text())
#sl_name_lbl.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
self.sliders.addWidget(slid,index,0)
slid.setMaximumWidth(200)
self.sliders.addWidget(sl_val_lbl,index,1)
self.sliders.addWidget(sl_name_lbl,index,2)
self.sliders_dict[sl_name_lbl.text()] = (slid,sl_val_lbl,sl_name_lbl)
Now, the issue I have is that some of the values the label takes, are actually pretty long strings.
My first solution was (a), i.e. set a certain size for the label. Of course, this may or may not work depending on the actual size of the text to be rendered, and when said text is only few chars long as in the case with floats, this is not a very clean solution.
I then went on trying (b), i.e. setting the expanding policy of the Qlabel to Expanding. This works fine for the label itself, however it goes to overlap with the next Qlabel in the Layout (column 2), covering its value.
In other words, I was expecting the underlying layout structure to stretch with the contained Widgets, which is not happening.
How to obtain the desired effect of having the size of the column in the layout to follow/adapt to that of the contained widgets?