Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I have a python script used as a source code for a ScriptTool in ArcGIS that is supposed to select road segments from a selection by location with a mask (polygon feature class).Everything worked fine until I modified the code to generate a different mask for the selection tool.
It seems that since that modification, the modified code as well as the original code both give me the same executing error for the SelectByLocation tool with the INTERSECT condition.
Here is the specific part of the original code :
import arcpy, os, datetime
from arcpy.sa import *
if __name__ == "__main__":
inRas = r'path\Raster_for_mask'
inRR = r'path\roads'
arcpy.env.overwriteOutput = True
# Mask creation based on the raster file
arcpy.CheckOutExtension('Spatial')
maskZIr = arcpy.Raster(inRas)>-10000
maskZIs = 'Zone_inondee'
arcpy.RasterToPolygon_conversion(maskZIr,maskZIs)
# Road features selections by the mask ############################
inRRLayer = 'inRRLayer'
arcpy.MakeFeatureLayer_management(inRR, inRRLayer)
arcpy.SelectLayerByLocation_management(inRRLayer,"INTERSECT",maskZIs)
And here is the modified code :
import arcpy, os, datetime
from arcpy.sa import *
if __name__ == "__main__":
inRas = r'path\Raster_for_mask'
inRR = r'path\roads'
arcpy.env.overwriteOutput = True
## Real mask to select road features that I want
maskZIr = arcpy.Raster(inRas)
maskZIr2 = SetNull(maskZIr,maskZIr,"VALUE = 0") # Erase the error zones of the raster before conversion to polygon
maskZIr3 = Int(maskZIr2)
maskZIr4 = 'Zone_inondee_multipart'
arcpy.RasterToPolygon_conversion(maskZIr3,maskZIr4)
maskZIs = 'Zone_inondee'
arcpy.Dissolve_management(maskZIr4,maskZIs) # Singlepart polygon mask
##################################
# Road features selections by the mask ############################
inRRLayer = 'inRRLayer'
arcpy.MakeFeatureLayer_management(inRR, inRRLayer)
arcpy.SelectLayerByLocation_management(inRRLayer,"INTERSECT",maskZIs)
(The paths for the files are fake ones just for demonstration purposes)
Concerning the error, a small window named "AddList" appears with only "FetchGeometries" written in it, along with an OK button. When clicked, I get an function execution error for the SelectByLocation_management tool (unknown 999999 Error). This happens too if I run my unmodified code, that worked fine before.
I verified both files used to run the selection tool but they are both in the right format (shapefile, polygon type for the mask and lines for the roads) and populated right. I looked up everywhere on the internet and it appears that nobody had that problem before...
Check a screen shot of the issue : http://imgur.com/jltD0zl.
The problem isn't that much the code itself because it worked fine before but I just can't trace back the source of that error. The code blocks just indicate the context in which the error occured. My guts suggest that something went wrong at some point with the MakeFeatureLayer_management tool. Also, using the source file for the roads without making a feature layer gives an error for non valid parameters for the selection tool.
So my question here is : have you ever seen this error ? And if so, was it with the same geoprocessing tool and how do you get rid of it ?
Thank you guys.
For info I just started learning python and arcpy two months ago for an internship. This is my first ever post here so I apologize in advance if my problem is unclear to some of you.
I am also relatively new to the ArcPy environment, and had the exact same problem on Arc 10.3.
The issue seems to be that ArcMap loses permission to access the personal geodatabase (MDB) that I was working with and could no longer read from or write to it. I do not have this problem with file geodatabases (GDB) or a folder full of shapefiles on the Windows filesystem.
Until this is resolved by Esri, it seems the best bet is to avoid personal geodatabases if you can.
Related
If I run
python -m manimlib scene.py ket_bra
My scene renders fine into the interactive viewer, but I don't get any output file, the terminal prints the following
ManimGL v1.6.1
[13:55:48] INFO Using the default configuration file, which you can modify in `c:\users\miika\manim\manimlib\default_config.yml` config.py:323
INFO If you want to create a local configuration file, you can create a file named `custom_config.yml`, or run `manimgl --config` config.py:324
WARNING You may be using Windows platform and have not specified the path of `temporary_storage`, which may cause OSError. So it is recommended to specify the `temporary_storage` in the config file config.py:290
(.yml)
(process:3548): GLib-GIO-WARNING **: 13:55:49.613: Unexpectedly, UWP app `Clipchamp.Clipchamp_2.3.0.0_neutral__yxz26nhyzhsrt' (AUMId `Clipchamp.Clipchamp_yxz26nhyzhsrt!App') supports 46 extensions but has no verbs
If I add the parameter -p to the command then the interactive window remains blank and doesn't render the scene and in no case do I get an output file which is what I'm looking for and the terminal output is the same as before. Also if it's of note the background is grey, even tho it appears to be black in all samples that I can find. I have absolutely no idea what's going on as I can't find anybody else with a similar issue. I'm using windows 10 and v1.6.1 of 3b1b manim. The scene in this case is as follows (though this issue appears regardless of what the scene is)
from manimlib import *
class ket_bra(Scene):
def construct(self):
ket_q0 = Tex(r"|q_0\rangle")
ket_0 = Tex(r"|0\rangle")
ket_1 = Tex(r"|1\rangle")
ket_0_v2 = Tex(r"|0\rangle")
ket_1_v2 = Tex(r"|1\rangle")
ket_0_v3 = Tex(r"""|0\rangle=\begin{pmatrix}
1\\
0
\end{pmatrix}""")
ket_1_v3 = Tex(r"""|1\rangle=\begin{pmatrix}
0\\
1
\end{pmatrix}""")
bra_kets = VGroup(ket_q0, ket_0, ket_1).arrange(RIGHT, buff=1)
v_bra_kets = VGroup(ket_0_v2, ket_1_v2).arrange(RIGHT, buff=1.5)
bra_kets_def = VGroup(ket_0_v3, ket_1_v3).arrange(RIGHT, buff=1.5)
self.play(Write(ket_q0), Write(ket_0), Write(ket_1))
self.wait(0.5)
self.play(FadeOut(ket_q0))
self.play(Transform(ket_0, ket_0_v2), Transform(ket_1, ket_1_v2))
self.wait(1)
self.play(Transform(ket_0, ket_0_v3), Transform(ket_1, ket_1_v3))
Well I fixed the problem, without fixing the problem, I just switched to the community edition of manim and it works exactly as intended, so if you encounter the same problem and you're using 3b1b manim version, I reccomend just switching to the community version of manim, they are mostly functionally equivalent, but the community edition appears to be less buggy at least for me. Here's a super easy installation guide for it https://docs.manim.community/en/stable/installation/windows.html
However, I won't mark this as the best answer, because I didn't really solve the problem, and I still get the following warning and have no idea what it is. However, it appears to not affect functionality so it's fine, lol.
Windows Solution
Create TempLatex directory in C drive
Find manimlib/default_config.yml in the manim (manimgl version) directory and open it with a text editor
Modify line 18: before: temporary_storage: "" after: temporary_storage: "C:/TempLatex "
Save
From:
https://github.com/3b1b/manim/issues/1661#issuecomment-996575974
I can't seem to find a simple answer to the question. I have this successfully working in Libreoffice Basic:
NamedRange = ThisComponent.NamedRanges.getByName("transactions_detail")
RefCells = NamedRange.getReferredCells()
Set MainRange = RefCells.getDataArray()
Then I iterate over MainRange and pull out the rows I am interested in.
Can I do something similar in a python macro? Can I assign a 2d named range to a python variable or do I have to iterate over the range to assign the individual cells?
I am new to python but hope to convert my iteration intensive macro function to python in hopes of making it faster.
Any help would be much appreciated.
Thanks.
LibreOffice can be manipulated from Python with the library pyuno. The documentation of pyuno is unfortunately incomplete but going through this tutorial may help.
To get started:
Python-Uno, the library to communicate via Uno, is already in the LibreOffice Python’s path. To initialize your context, type the following lines in your python shell :
import socket # only needed on win32-OOo3.0.0
import uno
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
# get the central desktop object
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
# access the current writer document
model = desktop.getCurrentComponent()
Then to get a named range and access the data as an array, you can use the following methods:
NamedRange = model.NamedRanges.getByName(“Test Name”)
MainRange = NamedRange.getDataArray()
However I am unsure that this will result in a noticeable preformance gain.
I have the next setup: I have a sphere which has a morpher modifier. This morpher modifier has a certain amount of channels filled with morph targets aka sub animations. Now I want to add a controller to each of these subanimations, more specifically a controller with a float script. I have the code snippet that should work but when I go to the curve editor, the morph channels/ sub animations did not change controller, nor is the value of their controller changed.
import MaxPlus
target = MaxPlus.INode.GetINodeByName('Sphere001')
#Retrieve the morpher modifier
mod = target.GetModifier(0)
#ID of a float script controller
id = MaxPlus.Class_ID(1233584870,1911625032)
#Create float controller
float_co = MaxPlus.Factory.CreateFloatController(id)
#Retrieve the first morph channel / sub animation
sub = mod.GetSubAnim(1)
#Controller is assigned to the sub animation
sub.AssignController(float_co,1)
#Basic test which assigns 20 to the sub animation
float_co.ParameterBlock.Script.Value = '20'
When I add a wrong value to the script, for example:
float_co.ParameterBlock.Script.Value = '=20'
I receive an error and the usual window when you manually add a controller to an object or node. However the strange thing is that at the top of the window: the name of the object to which it is connected, does not show. See figure for clarification:
Can someone tell me what I'm doing wrong? Thank you!
I solved it by using the ugly way:
import MaxPlus
test = MaxPlus.FPValue()
success = MaxPlus.Core.EvalMAXScript(string_with_command,test)
This is used twice: first to create the float script controller and a second time to add the script to the controller. Be careful if anyone wants to try this, the script for the controller needs to be a string. Do not use
x as string
with the expressing you want to use as script for the float script controller since maxscript will evaluate x on the timeframe you are currently in 3ds max and will convert this value to a string. This value will be used as script for all time frames which clearly is not what you want. A small hack I used was:
script_value_example = '"amax #(0, ($sphere.position.x - cube.position.y))"'
This is still a string for python and maxscript will see the " " and will interpret it as a string. The other way around doesn't work, maxscript does not interpret ' ' as string.
Maybe this will help someone in the future. Also if someone knows the proper way to do it using the code in the question, please leave a reply, I'm interested to know.
I'm starting work on an app that will need to create sound from lots of pre-loaded ".mid" files.
I'm using Python and Kivy to create an app, as I have made an app already with these tools and they are the only code I know. The other app I made uses no sound whatsoever.
Naturally, I want to make sure that the code I write will work cross-platform.
Right now, I'm simply trying to prove that I can create any real sound from a midi note.
I took this code suggested from another answer to a similar question using FluidSynth and Mingus:
from mingus.midi import fluidsynth
fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")
fluidsynth.play_Note(64,0,100)
But I hear nothing and get this error:
fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.
Why do I get this error, how do I fix it, and is this the simplest way or even right way?
I could be wrong but I don't think there is a "0" channel which is what you are passing as your second argument to .play_Note(). Try this:
fluidsynth.play_Note(64,1,100)
or (from some documentation)
from mingus.containers.note import Note
n = Note("C", 4)
n.channel = 1
n.velocity = 50
fluidSynth.play_Note(n)
UPDATE:
There are references to only channels 1-16 in the source code for that method with the default channel set to 1:
def play_Note(self, note, channel = 1, velocity = 100):
"""Plays a Note object on a channel[1-16] with a \
velocity[0-127]. You can either specify the velocity and channel \
here as arguments or you can set the Note.velocity and Note.channel \
attributes, which will take presedence over the function arguments."""
if hasattr(note, 'velocity'):
velocity = note.velocity
if hasattr(note, 'channel'):
channel = note.channel
self.fs.noteon(int(channel), int(note) + 12, int(velocity))
return True
I want to try to add all the step details - Expected, Actual, Status,
etc. to a QC Run for a testcase of a TestSet from a Python Script
living outside the Quality Center.
I have come till here (code given below) and I don't know how to add
Step Expected and Step Actual Result. If anyone knows how do it,
please help me out!! Please, I don't want any QTP solutions.
Thanks,
Code-
# Script name - add_tsrun.py
# C:\Python27\python.exe
# This script lives locally on a Windows machine that has - Python 2.7, Win32 installed, IE8
# Dependencies on Windows Machine - Python 2.7, PythonWin32 installed, IE8, a QC Account, connectivity to QCServer
import win32com.client, os
tdc = win32com.client.Dispatch("TDApiOle80.TDConnection")
tdc.InitConnection('http://QCSERVER:8080/qcbin')
tdc.Login('USERNAME', 'PASSWORD')
tdc.Connect('DOMAIN_NAME', 'PROJECT')
tsFolder = tdc.TestSetTreeManager.NodeByPath('Root\\test_me\\sub_folder')
tsList = tsFolder.FindTestSets('testset1')
ts_object = tsList.Item(1)
ts_dir = os.path.dirname('testset1')
ts_name = os.path.basename('testset1')
tsFolder = tdc.TestSetTreeManager.NodeByPath(ts_dir)
tsList = tsFolder.FindTestSets(ts_name)
ts_object = tsList.Item(1)
TSTestFact = ts_object.TSTestFactory
TestSetTestsList = TSTestFact.NewList("")
ts_instance = TestSetTestsList.Item(1)
newItem = ts_instance.RunFactory.AddItem(None) # newItem == Run Object
newItem.Status = 'No Run'
newItem.Name = 'Run 03'
newItem.Post()
newItem.CopyDesignSteps() # Copy Design Steps
newItem.Post()
steps = newItem.StepFactory.NewList("")
step1 = steps[0]
step1.Status = "Not Completed"
step1.post()
## How do I change the Actual Result??
## I can access the Actual, Expected Result by doing this, but not change it
step1.Field('ST_ACTUAL') = 'My actual result' # This works in VB, not python as its a Syntax error!!
Traceback ( File "<interactive input>", line 1
SyntaxError: can't assign to function call
Hope this helps you guys out there. If you know the answer to set the
Actual Result, please help me out and let me know. Thanks,
Amit
As Ethan Furman answered in your previous question:
In Python () represent calls to functions, while [] represent indexing and mapping.
So in other words, you probably want to do step1.Field['ST_ACTUAL'] = 'My actual result'
Found the answer after a lot of Google Search :)
Simple -> Just do this:
step1.SetField("ST_ACTUAL", "my actual result") # Wohhooooo!!!!
If the above code fails to work, try to do the following:-
(OPTIONAL) Set your win32 com as follows- (Making ''Late Binding'')
# http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
a. Start PythonWin, and from the Tools menu, select the item COM Makepy utility.
b. Using Windows Explorer, locate the client subdirectory (OTA COM Type Library)
under the main win32com directory and double-click the file makepy.py.
Thank you all...