Maya polySoftEdge - attributes

I am writing a mesh exporter plugin for Maya.
I am struggling to get the default polySoftEdge input value for a particular kMesh node. Maya ships with a default of 30.0, but I suspect this can be changed so am treating it as an unknown.
So the problem is the polySoftEdge input node doesn't appear as an input value on the mesh until you select the mesh in the viewer, then in the top menu bar click "normals -> set normal angle" and finally apply a new angle value and the polySoftEdge1 node should appear in the inputs of the selected mesh.
At this point I can get the value by using MEL from my plugin:
float $val = polySoftEdge -query -angle polySoftEdge1;
looking at this link:
http://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/Maya-Tech-Docs/Nodes/polySoftEdge-html.html#attrangle
The attribute is available directly to the API ( rather than having to go through MEL ) but I have no idea how to access it?
Thanks.

If you want to query for a polySoftEdge node using the API, you can use an MItDependencyGraph iterator object with the shape node as the root and the filter set to kPolySoftEdge.
Here is a snippet written in the Python flavour of the API to print the polySoftEdge of the selected object(s):
import maya.OpenMaya as OpenMaya
selectionList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selectionList )
selectionIter = OpenMaya.MItSelectionList( selectionList )
dnNodeFn = OpenMaya.MFnDependencyNode()
dagNodeFn = OpenMaya.MFnDependencyNode()
dnGraphNodeFn = OpenMaya.MFnDependencyNode()
while not selectionIter.isDone():
dnObject = OpenMaya.MObject()
selectionIter.getDependNode( dnObject )
dnNodeFn.setObject( dnObject )
dagIter = OpenMaya.MItDag()
dagIter.reset( dnObject )
while not dagIter.isDone():
dagObject = OpenMaya.MObject()
dagObject = dagIter.currentItem()
if dagObject:
dagNodeFn.setObject( dagObject )
if dagObject.apiType() == OpenMaya.MFn.kMesh:
dnGraphIter = OpenMaya.MItDependencyGraph(dagObject,
OpenMaya.MFn.kPolySoftEdge,
OpenMaya.MItDependencyGraph.kDownstream)
while not dnGraphIter.isDone():
dnGraphNodeFn.setObject( dnGraphIter.currentItem() )
print "shape: %s" % ( dagNodeFn.name() )
print "polySoftEdge-node-name: %s" % ( dnGraphNodeFn.name() )
print "value: %f" % ( dnGraphNodeFn.findPlug("angle").asMAngle().asDegrees() )
dnGraphIter.next()
dagIter.next()
selectionIter.next()
Sample output:
shape: pSphereShape1
polySoftEdge-node-name: polySoftEdge1
value: 180.000000

Related

Cannot get PyMeshLab running (filter_sketchfab.dll does not seem to be a Qt Plugin.)

im absolutely new to this and struggle with following the tutorial from PyMeshLab (https://pymeshlab.readthedocs.io/en/latest/about.html).
What i want to do:
open a file (e.g. xyz.ply - point cloud) via PyMeshLab
some filter action
save filtered file (e.g. as xyz.obj)
My "code" is stitched together from the tutorias "Load Mesh", "Apply a Filter" and "Save Mesh".
It prompts already a warning when importing the library
import pymeshlab
..
->
Warning:
Unable to load the following plugins:
filter_sketchfab.dll: filter_sketchfab.dll does not seem to be a Qt Plugin.
Cannot load library C:\Users\bvis\AppData\Local\Programs\Python\Python39\lib\site-packages\pymeshlab\lib\plugins\filter_sketchfab.dll: Das angegebene Modul wurde nicht gefunden.
Any ideas?
Thanks
I also get this warning. Still, it seems to work except for print functions like "MeshSet.print_filter_list()", which you might have copied from the example code. You can easily replace the print functions with functions on module level:
import pymeshlab
pymeshlab.print_pymeshlab_version()
filters = pymeshlab.filter_list()
print(filters)
pymeshlab.print_filter_parameter_list('discrete_curvatures')
Results:
PyMeshLab 0.2 based on MeshLab 2020.12d
['alpha_complex_shape', 'ambient_occlusion', 'annulus', 'box_cube', ... 'voronoi_sampling', 'voronoi_scaffolding', 'voronoi_vertex_coloring']
Please note: some parameters depend on the mesh(es) used as input of the
filter. Default values listed here are computed on a 1x1x1 cube
(pymeshlab/tests/sample/cube.obj), and they will be computed on the input mesh
if they are left as default.
surface_reconstruction_screened_poisson filter - list of parameter names:
visiblelayer : bool = False
depth : int = 8
fulldepth : int = 5
cgdepth : int = 0
scale : float = 1.1
samplespernode : float = 1.5
pointweight : float = 4
iters : int = 8
confidence : bool = False
preclean : bool = False
Other MeshSet functions work for me without issues, e.g.:
ms = pymeshlab.MeshSet()
ms.load_new_mesh('test.ply')
ms.apply_filter('discrete_curvatures')
ms.save_current_mesh(output_vis)

slider.value values not getting updated using ColumnDataSource(Dataframe).data

I have been working on COVID19 analysis for a dashboard and am using a JSON data source. I have converted the json to dataframe. I am working on plotting bar chart for "Days to reach deaths" over a "States" x-axis (categorical values). I am trying to use a function to update the slider.value. Upon running the bokeh serve with --log-level=DEBUG, I am getting a following error:
Can someone provide me with any direction or help with what might be causing the issue as I am new to Python and any help is appreciated? Or if there's any other alternative.
Please find the code below:
cases_summary = requests.get('https://api.rootnet.in/covid19-in/stats/history')
json_data = cases_summary.json()
#Data Cleaning
cases_summary=pd.json_normalize(json_data['data'], record_path='regional', meta='day')
cases_summary['loc']=np.where(cases_summary['loc']=='Nagaland#', 'Nagaland', cases_summary['loc'])
cases_summary['loc']=np.where(cases_summary['loc']=='Madhya Pradesh#', 'Madhya Pradesh', cases_summary['loc'])
cases_summary['loc']=np.where(cases_summary['loc']=='Jharkhand#', 'Jharkhand', cases_summary['loc'])
#Calculate cumulative days since 1st case for each state
cases_summary['day_count']=(cases_summary['day'].groupby(cases_summary['loc']).cumcount())+1
#Initial plot for default slider value=35
days_reach_death_count=cases_summary.loc[(cases_summary['deaths']>=35)].groupby(cases_summary['loc']).head(1).reset_index()
slider = Slider(start=10, end=max(cases_summary['deaths']), value=35, step=10, title="Total Deaths")
source = ColumnDataSource(data=dict(days_reach_death_count[['loc','day_count', 'deaths']]))
q = figure(x_range=days_reach_death_count['loc'], plot_width=1200, plot_height=600, sizing_mode="scale_both")
q.title.align = 'center'
q.title.text_font_size = '17px'
q.xaxis.axis_label = 'State'
q.yaxis.axis_label = 'Days since 1st Case'
q.xaxis.major_label_orientation = math.pi/2
q.vbar('loc', top='day_count', width=0.9, source=source)
deaths = slider.value
q.title.text = 'Days to reach %d Deaths' % deaths
hover = HoverTool(line_policy='next')
hover.tooltips = [('State', '#loc'),
('Days since 1st Case', '#day_count'), # #$name gives the value corresponding to the legend
('Deaths', '#deaths')
]
q.add_tools(hover)
def update(attr, old, new):
days_death_count = cases_summary.loc[(cases_summary['deaths'] >= slider.value)].groupby(cases_summary['loc']).head(1).reindex()
source.data = [ColumnDataSource().from_df(days_death_count)]
slider.on_change('value', update)
layout = row(q, slider)
tab = Panel(child=layout, title="New Confirmed Cases since Day 1")
tabs= Tabs(tabs=[tab])
curdoc().add_root(tabs)
Your code has 2 issues
(critical) source.data must be a dictionary, but you're assigning it an array
(minor) from_df is a class method, you don't have to construct an object of it
Try using source.data = ColumnDataSource.from_df(days_death_count) instead.

XGetWindowProperty and ctypes

Question
I'm trying to find NET_WM_NAME property for each of the window/client that X11 reports. Problem is that there's nothing returned - number of items is 0 and returned data results in empty string. I've looked at multiple code examples through out github and examples written in C and C++ , specifically Why is XGetWindowProperty returning null? as well as Xlib XGetWindowProperty Zero items returned , however I cannot find where is the problem with my code. Seemingly everything is fine, order of parameters passed to XGetWindowProperty function is in accordance with documentation, and the function returns success status, but results are empty. Where is the problem with my code ?
Code
Below is the code I am working with. The issue is xgetwindowproperty function. The other parts below it work fine, and are provided only for completeness.
#! /usr/bin/env python3
import sys
from ctypes import *
def xgetwindowproperty(display,w):
actual_type_return = c_ulong()
actual_format_return = c_int()
nitems_return = c_ulong()
bytes_after_return = c_ulong()
prop_return = POINTER(c_ubyte)()
wm_name = Xlib.XInternAtom(display,'_NET_WM_NAME',False)
utf8atom = Xlib.XInternAtom(display,'UTF8_STRING',False)
print('_NET_WM_NAME',wm_name, 'UTF8_STRING',utf8atom)
# AnyPropertyType = c_long(0)
status = Xlib.XGetWindowProperty(
display,
w,
wm_name,
0,
65536,
False,
utf8atom,
byref(actual_type_return),
byref(actual_format_return),
byref(nitems_return),
byref(bytes_after_return),
byref(prop_return)
)
print(nitems_return.value) # returns 0
# empty string as result
print( 'Prop', ''.join([ chr(c) for c in prop_return[:bytes_after_return.value] ]) )
Xlib.XFree(prop_return)
print('#'*10)
# -------
Xlib = CDLL("libX11.so.6")
display = Xlib.XOpenDisplay(None)
if display == 0:
sys.exit(2)
w = Xlib.XRootWindow(display, c_int(0))
root = c_ulong()
children = POINTER(c_ulong)()
parent = c_ulong()
nchildren = c_uint()
Xlib.XQueryTree(display, w, byref(root), byref(parent), byref(children), byref(nchildren))
for i in range(nchildren.value):
print("Child:",children[i])
xgetwindowproperty(display,children[i])

using as.ppp on data frame to create marked process

I am using a data frame to create a marked point process using as.ppp function. I get an error Error: is.numeric(x) is not TRUE. The data I am using is as follows:
dput(head(pointDataUTM[,1:2]))
structure(list(POINT_X = c(439845.0069, 450018.3603, 451873.2925,
446836.5498, 445040.8974, 442060.0477), POINT_Y = c(4624464.56,
4629024.646, 4624579.758, 4636291.222, 4614853.993, 4651264.579
)), .Names = c("POINT_X", "POINT_Y"), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
I can see that the first two columns are numeric, so I do not know why it is a problem.
> str(pointDataUTM)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 5028 obs. of 31 variables:
$ POINT_X : num 439845 450018 451873 446837 445041 ...
$ POINT_Y : num 4624465 4629025 4624580 4636291 4614854 ...
Then I also checked for NA, which shows no NA
> sum(is.na(pointDataUTM$POINT_X))
[1] 0
> sum(is.na(pointDataUTM$POINT_Y))
[1] 0
When I tried even only the first two columns of the data.frame, the error I get on using as.ppp is this:
Error: is.numeric(x) is not TRUE
5.stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"), ch), call. = FALSE, domain = NA)
4.stopifnot(is.numeric(x))
3.ppp(X[, 1], X[, 2], window = win, marks = marx, check = check)
2.as.ppp.data.frame(pointDataUTM[, 1:2], W = studyWindow)
1.as.ppp(pointDataUTM[, 1:2], W = studyWindow)
Could someone tell me what is the mistake here and why I get the not numeric error?
Thank you.
The critical check is whether PointDataUTM[,1] is numeric, rather than PointDataUTM$POINT_X.
Since PointDataUTM is a tbl object, and tbl is a function from the dplyr package, what is probably happening is that the subset operator for the tbl class is returning a data frame, and not a numeric vector, when a single column is extracted. Whereas the $ operator returns a numeric vector.
I suggest you convert your data to data.frame using as.data.frame() before calling as.ppp.
In the next version of spatstat we will make our code more robust against this kind of problem.
I'm on the phone, so can't check but I think it is happens because you have a tibble and not a data.frame. Please try to convert to a data.frame using as.data.frame first.

History of previously opened m-files in MATLAB

Is anyway to find history of previously opened m-files in MATLAB R2014b from 2 or 3 months ago? (a list of name of files and paths)
Matlab R2014b stores its recent files in:
%APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml
It's a .xml file so it's easy to load and parse with xmlread. I'm not very familiar with xml parsing syntax, but here is how to get information about files (to be adapted to your needs of course):
function [recentFiles] = GetRecentFiles()
%[
% Opens editor's state file
filepart = sprintf('MathWorks\\MATLAB\\R%s\\%s', version('-release'), 'MATLAB_Editor_State.xml');
filename = fullfile(getenv('APPDATA'), filepart);
document = xmlread(filename);
% Get information about 'File' nodes
recentFiles = struct([]);
fileNodes = document.getElementsByTagName('File');
for fni = 1:(fileNodes.getLength())
attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing !
for ai = 1:(attributes.getLength())
% Get node attribute
name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type
value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type
% Save in structure
name(1) = upper(name(1)); % Just because I prefer capital letter for field names ...
recentFiles(fni).(name) = value;
end
end
%]
end
This returns a structure like this:
recentFiles =
1x43 struct array with fields:
AbsPath
LastWrittenTime
Name
NB: I've tried to type in matlab command window matlab.desktop.editor.*, but seems there's nothing regarding recent files (anyway there are a lot of interesting things to manipulate the editor from the command line)
Last answer waIs really helpful. I've just modified it to read and open the recent tab files. This works on Matlab R2013a:
function [recentFiles] = recover_tabs()
%[
% Opens editor's state file
filepart = sprintf('MathWorks\\MATLAB\\R%s\\%s', version('-release'), 'MATLAB_Editor_State.xml');
filename = fullfile(getenv('APPDATA'), filepart);
document = xmlread(filename);
% Get information about 'File' nodes
recentFiles = struct([]);
fileNodes = document.getElementsByTagName('File');
for fni = 1:(fileNodes.getLength())
attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing !
for ai = 1:(attributes.getLength())
% Get node attribute
name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type
value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type
% Save in structure
name(1) = upper(name(1)); % Just because I prefer capital letter for field names ...
recentFiles(fni).(name) = value;
end
end
% loop to access files in the tab history
for j=1:length(recentFiles)
arquivo = [recentFiles(j).AbsPath '\' recentFiles(j).Name];
% if exists, then open
if exist(arquivo, 'file') == 2
open(arquivo);
end
end
%]
end
Base in the answer by CitizenInsane, but for any Matlab version.
To find the .xml file in any Matlab version, use prefdir:
>> prefdir
ans = '/Users/user/Library/Application Support/MathWorks/MATLAB/R2018a'
MATLAB_Editor_State.xml will be stored there. Therefore the fuction would be:
function [recentFiles] = GetRecentFiles()
% Opens editor's state file
filepart = sprintf([ prefdir '/MATLAB_Editor_State.xml']);
filename = fullfile(getenv('APPDATA'), filepart);
document = xmlread(filename);
% Get information about 'File' nodes
recentFiles = struct([]);
fileNodes = document.getElementsByTagName('File');
for fni = 1:(fileNodes.getLength())
attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing !
for ai = 1:(attributes.getLength())
% Get node attribute
name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type
value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type
% Save in structure
name(1) = upper(name(1)); % Just because I prefer capital letter for field names ...
recentFiles(fni).(name) = value;
end
end
In R2018b you can increase the Most recently used file list in Preferences > Editor/Debugger. I like the methods above, but they do not work if you're working across machines (e.g., using Github). I coded a solution that uses the modified file date from the machine, instead of relying on MATLAB itself.

Resources