I have a very simple AutoCAD drawing with just two entities: an MText object and a Polyline object, as shown in the screenshot below.
I'd like to programmatically get the TextString property from the MText object (i.e. the string 'foo') through the following code:
import win32com.client
acad = win32com.client.gencache.EnsureDispatch('AutoCAD.Application')
dwg = acad.Documents.Open(r'C:\path\to\my\drawing\test.dwg')
ms = dwg.ModelSpace
for obj in ms:
if obj.EntityName == 'AcDbMText':
print(obj.TextString)
But I'm getting this error:
Traceback (most recent call last):
File "<ipython-input-299-e8bbc8ec7f92>", line 3, in <module>
print(obj.TextString)
File "D:\anaconda3\lib\site-packages\win32com\client\__init__.py", line 473, in __getattr__
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.AutoCAD 2021 Type Library.IAcadEntity instance at 0x2562970331648>' object has no attribute 'TextString'
This is pretty weird because one year ago this code was working nicely. What am I missing here?
I don't know much about programming AutoCAD with Python. From what I know, with the COM/ActiveX API, MText object does have a TextString property but there's none EntityName property, you should use ObjectName.
Related
I'm new in C++. So, I'm trying to use python-pcl, but I got an error:
AttributeError: 'pcl._pcl.Segmentation_PointXYZI' object has no attribute 'set_MaxIterations'
I'm trying to create the segmentation object for the planar model and set the parameters with the PointXYZI type. I have to use PointXYZI. How can I solve this problem?
My code:
def cluster_extraction(self,data):
print("Type1: ", type(data))
cloud_filtered = self.downsampling(data,0.3)
print("Type2: ", type(cloud_filtered))
seg = cloud_filtered.make_segmenter()
seg.set_optimize_coefficients (True)
seg.set_model_type (pcl.SACMODEL_PLANE)
seg.set_method_type (pcl.SAC_RANSAC)
seg.set_MaxIterations (100)
seg.set_distance_threshold (0.02)
Output:
('Type1: ', <type 'pcl._pcl.PointCloud_PointXYZI'>)
('Type2: ', <type 'pcl._pcl.PointCloud_PointXYZI'>)
[ERROR] [1596926303.890116]: bad callback: <bound method sub_pub_node.callback of <__main__.sub_pub_node object at 0x7f154be44ad0>>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "node.py", line 154, in callback
downsampled_data = self.processing(pcl2_data)
File "node.py", line 103, in processing
processing.cluster_extraction(pcl2_data)
File "node.py", line 43, in cluster_extraction
seg.set_MaxIterations (100)
AttributeError: 'pcl._pcl.Segmentation_PointXYZI' object has no attribute 'set_MaxIterations'
I am not sure from where you got your python-pcl package, but I will assume that you used this one, therefore, and because there is no method called set_MaxIterations(int ) in the Segmentation_PointXYZI class (Sample Consensus), you can try to replace it with setMaxIterations(int ).
Inside the definition of the PointCloud_PointXYZI class, you can find that the Segmentation method used for this type of point clouds is an instance from pcl_seg.SACSegmentation_PointXYZI_t which defines the method for setting the max number of iterations as setMaxIterations(int ).
Please check the documentation provided here and check the functions that you are using and how are they defined. (I know that can be tedious but it is necessary).
I hope this helped in solving the issue.
According to strawlab's official example the correct call is:
seg.set_max_iterations(100)
I am using sightengine API to detect child sexual abuse in images. In order to do that I am trying to detect the nudity level in an image using sightengine API. The following example is provided in the documentation itself.
from sightengine.client import SightengineClient
client = SightengineClient('api_user', 'api_key')
output = client.check('nudity').image('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
Apart from copying the same code I am getting the following error.
Traceback (most recent call last):
File "driver.py", line 3, in <module>
output = client.check('nudity').image('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
AttributeError: 'Check' object has no attribute 'image'
I have used both Python 2 and Python 3 for the same code but both raise the same error.
Try This:
from sightengine.client import SightengineClient
client = SightengineClient('API user', 'API secret')
checkNudity = client.check('nudity')
output1 = checkNudity.set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
print(output1)
I'm hitting this exception with jsonpickle, when trying to pickle a rather complex object that unfortunately I'm not sure how to describe here. I know that makes it tough to say much, but for what it's worth:
>>> frozen = jsonpickle.encode(my_complex_object_instance)
>>> thawed = jsonpickle.decode(frozen)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/jsonpickle/__init__.py",
line 152, in decode
return unpickler.decode(string, backend=backend, keys=keys)
:
:
File "/Library/Python/2.7/site-packages/jsonpickle/unpickler.py",
line 336, in _restore_from_dict
instance[k] = value
File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/packages/ordered_dict.py",
line 49, in __setitem__
root = self.__root
AttributeError: 'OrderedDict' object has no attribute '_OrderedDict__root'
I don't find much of assistance when googling the error. I do see what looks like the same issue was resolved at some time past for simpler objects:
https://github.com/jsonpickle/jsonpickle/issues/33
The cited example in that report works for me:
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict()))
OrderedDict()
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict(a=1)))
OrderedDict([(u'a', 1)])
Has anyone ever run into this themselves and found a solution? I ask with the understanding that my case may be "differently idiosynchratic" than another known example.
The requests module for me seems to be running into problems when I .decode(). After looking at the jsonpickle code a bit, I decided to fork it and change the following lines to see what was going on (and I ended up keeping a private copy of jsonpickle with the changes so I can move forward).
In jsonpickle/unpickler.py (in my version it's line 368), search for the if statement section in the method _restore_from_dict():
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
instance[k] = value
else:
setattr(instance, k, value)
and change it to this (it will logERROR the ones that are failing and then you can either keep the code in place or change your OrderedDict's version that have __root)
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
# Currently requests.adapters.HTTPAdapter is using a non-standard
# version of OrderedDict which doesn't have a _OrderedDict__root
# attribute
try:
instance[k] = value
except AttributeError as e:
import logging
import pprint
warnmsg = 'Unable to unpickle {}[{}]={}'.format(pprint.pformat(instance), pprint.pformat(k), pprint.pformat(value))
logging.error(warnmsg)
else:
setattr(instance, k, value)
I am using the pysdl2 library. self.velocity will print, but self.forward_tick with throw a key error.
What is causing only part of the self attributes from being assigned. I am thinking it has something to do with the inheritance.
class Robot(sdl2.ext.Entity):
def __init__(self, world, sprite, posx=0, posy=0):
self.sprite = sprite
self.sprite.position = posx, posy
self.velocity = Velocity()
self.forward_tick = 0
self.go_forward = 0
self.unit_forward = (1,0)
print(self.velocity)
print(self.forward_tick)
Here is the output:
Collins-MacBook-Air:soccer_bots collinbell$ python test_simulation_world.py
<simulation_world.Velocity object at 0x108ecb5c0>
Traceback (most recent call last):
File "/Users/collinbell/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sdl2/ext/ebs.py", line 53, in __getattr__
ctype = self._world._componenttypes[name]
KeyError: 'forward_tick'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_simulation_world.py", line 3, in <module>
world = Simulation_World("Test Simulation", 1080, 720)
File "/Users/collinbell/Programs/soccer_bots/simulation_world.py", line 100, in __init__
self.player1 = Robot(self.world, sp_paddle1, 0, 250)
File "/Users/collinbell/Programs/soccer_bots/simulation_world.py", line 22, in __init__
print(self.forward_tick)
File "/Users/collinbell/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sdl2/ext/ebs.py", line 56, in __getattr__
(self.__class__.__name__, name))
AttributeError: object ''Robot'' has no attribute ''forward_tick''
From the docs on component-based design with sdl2.ext, the Entity type is special, and doesn't follow normal Python idioms. In particular, you can't just create arbitrary attributes; you can only create attributes whose value is a component type, and whose name is a lowercased version of that type:
Entity objects define the in-application objects and only consist of component-based attributes.
…
The Entity also requries its attributes to be named exactly as their component class name, but in lowercase letters.
So, when you try to add an attribute named forward_tick, that causes Entity.__setattr__ to go looking for a class named Forward_Tick in the world's component types. Which it apparently does by looking up self._world._componentypes[name], which is the line that's actually raising the exception, as you can see in the tracebacks.
Without knowing anything more about your code and your design than the tiny fragment you showed us, I can't tell you how to fix this. But most likely, it's one of the following:
You actually wanted to create a Component, not an Entity,
You wanted to wrap up forward_tick in a Component type that this Entity can contain, or
You didn't want a Component-oriented design in the first place.
At any rate, as the docs say:
If you are just starting with such a [component-oriented] design, it is recommended to read through the The Pong Game tutorial.
I was following an animation example with Python in Blender 2.69, by typing a line by line.
obj = bpy.context.object
obj.location[2] = 0.0
obj.keyframe_insert(data_path="location", frame=10.0, index=2)
obj.location[2] = 1.0
obj.keyframe_insert(data_path="location", frame=20.0, index=2)
But I have encountered an error on the 3rd line, which is saying
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'location'
I am confused because I just followed a simple example.
Why is it saying the object has no attribute 'location'?
I'll be appreciated for your help, thanks.
You'll find that the error would be reported after the second line because the variable obj has not been set. Most likely this would be from a small typo.
You can verify this by looking at the type of the variable in the python console. When getting the error you will see -
>>> type(obj)
<class 'NoneType'>
While if it had been set correctly you will get -
>>> type(obj)
<class 'bpy_types.Object'>