hi all i have this problem when i try to export object through WBlock what is wrong there i'm try to do simple python work (note: i'm beginners :D) .. any help
from pyautocad import Autocad, APoint,utils
import win32com.client
AutoCAD = win32com.client.dynamic.Dispatch("AutoCAD.Application")
acad = Autocad(create_if_not_exists = False)
acad.Visible=True
doc = AutoCAD.ActiveDocument
layersList = doc.Layers
for l in layersList:
object = acad.iter_objects()
if l.name == "0":
pass
else:
for o in object:
if o.ObjectName == "AcDbText":
SelectionSet = doc.SelectionSets.Item(o.ObjectName).Name
directoryN = "C:\\Temp\\{}_{}.dwg".format(l.name,o.TextString)
doc.WBlock(directoryN,SelectionSet)
here what i Get
AcDbText
Traceback (most recent call last):
File "C:/Temp/Exporter.py", line 23, in <module>
doc.WBlock(directoryN,SelectionSet)
File "<COMObject <unknown>>", line 2, in WBlock
pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2)
thanks
i'm try to export every text as WBlock
Related
I really don't understand what causes the problem, could someone point it out for me please?
with shelve.open(obj_path) as obj:
for as_num in obj['as_number_list']: # ignore warning, obj['as_number_list'] is a list
temp = charge_as(obj['as_' + str(as_num)]) # temp is an object
as_test = temp # doing like this is ok
print(type(as_test))
exec("as_{}_obj = {}".format(as_num, temp)) # **error here**
And it gives syntax error like this:
<class 'instruments.AS'>
Traceback (most recent call last):
File "...", line 45, in <module>
exec("as_{}_obj = {}".format(as_num, temp))
File "<string>", line 1
as_1_obj = <instruments.AS object at 0x000002A86732E290>
^
SyntaxError: invalid syntax
I tried
exec("as_{}_obj = {}".format(as_num, temp.__dict__))
no error is shown but now as_{}_obj is of class 'dict' instead of class 'instruments.AS'
line 45:
exec("as_{}_obj = temp".format(as_num))
I am running one code in python2.7.9 so code is working fine but the same code i am running in python2.7.5 it is giving me value error.
Can you please help to to resolve this?
code:
import os
import sys
table = sys.argv[1] #CALL_KEY
column_nm = sys.argv[2] #ID
file_loc = '/medaff/eureka/RawLayer/AMPIL/'
lkp_file_path ='/medaff/eureka/AMPIL_INCREMENT/'
tgt_file_path ='/medaff/eureka/AMPIL_UNMATCHED/'
def get_col_index(file,col):
header=open(file).readline().strip()
header_list = header.split('|')
return str(header_list.index(col)+1)
src_file_nm = file_loc+table+'/'+table+'.txt'
lkp_file = lkp_file_path+table+'/'+table+'.txt'
trgt_file_nm = tgt_file_path+table+'/'+table+'_Unmatched.txt'
print(lkp_file)
rm_str = 'rm -f '+trgt_file_nm
print(rm_str)
matcher_str = 'awk -F \'|\' \'NR==FNR && NR>1{id[toupper($' + get_col_index(lkp_file,column_nm) + ')]; next} !(toupper(' + get_col_index(src_file_nm,column_nm) + ') in id)\' '+lkp_file+' '+src_file_nm+'|tail -n +2 >> '+trgt_file_nm
os.system(matcher_str)
error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in get_col_index
ValueError: 'ID' is not in list
Found similar questions to this, but the solutions proposed didn't seem to work for me.
I'm struggling to make the findNotesMetadata call. My getUser() from the userStore works, and my createNote from the notestore works as well. It is only the call to findNotesMetaData that is failing currently.
from evernote.api.client import EvernoteClient
import evernote.edam.type.ttypes as Types
dev_token = "blah blah blah"
client = EvernoteClient(token=dev_token, sandbox=True)
userStore = client.get_user_store()
user = userStore.getUser()
print user.username
notestore = client.get_note_store()
notebooks = notestore.listNotebooks()
note = Types.Note()
note.title = "I'm a test note!"
note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
note.content += '<en-note><en-todo/>Hello, world!</en-note>'
note = noteStore.createNote(note)
tags = notestore.listTags()
CheckedTags = set()
for tag in tags:
if tag.name[0:4] == "CheckThisTag":
print tag
CheckedTags.add(tag.guid)
print CheckedTags
myfilter = notestore.NoteFilter()
spec = notestore.NotesMetadataResultSpec()
spec.includeTitle = True
notes = notestore.findNotesMetadata(dev_token, myfilter, 0, 100, spec)
print notes
Running this code gets me the following error on the findNotesMetaData line
Traceback (most recent call last):
File "main.py", line 27, in <module>
notes = notestore.findNotesMetadata(dev_token, filter, 0, 100, spec)
File "build/bdist.macosx-10.13-x86_64/egg/evernote/api/client.py", line 145, in delegate_method
File "build/bdist.macosx-10.13-x86_64/egg/evernote/edam/notestore/NoteStore.py", line 3981, in findNotesMetadata
File "build/bdist.macosx-10.13-x86_64/egg/evernote/edam/notestore/NoteStore.py", line 3992, in send_findNotesMetadata
File "build/bdist.macosx-10.13-x86_64/egg/evernote/edam/notestore/NoteStore.py", line 12996, in write
AttributeError: 'function' object has no attribute 'write'
I am using the win32Com module to write data to an excel sheet on a Windows 7 machine with Python 3.5. While it is running I get thrown an error. I tried making a "try/except" block but the error type I attempted is apparently not an actual error type. Here is my code :
import win32com.client as win32
import sqlite3
def writeWords(storage):
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible = True
wb = excel.Workbooks.Add()
ws = wb.Worksheets('Sheet1')
i = 0
storLen = len(storage)
while i < storLen:
varX = storage[i]
lenVar = len(varX)
q = 0
while q < lenVar:
tarf = str(storage[i][q].encode('ascii', errors='ignore')).lstrip("b\'").rstrip("\'")
try :
ws.Cells(q+1,i+1).Value = (tarf)
except pywintypes.com_error:
print("Error")
q +=1
q += 1
i += 1
The traceback I get is this :
Traceback (most recent call last):
File "C:\Users\LewTo002\Google Drive\Todd's Stuff\python\mailWords\current\mailWords2.py", line 65, in writeWords
ws.Cells(q+1,i+1).Value = (tarf)
File "C:\Users\LewTo002\AppData\Local\Programs\Python\Python35\lib\site-packages\win32com\client\__init__.py", line 474, in __setattr__
self._oleobj_.Invoke(*(args + (value,) + defArgs))
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146777998), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\LewTo002\AppData\Local\Programs\Python\Python35\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec(codeObject, __main__.__dict__)
File "C:\Users\LewTo002\Google Drive\Todd's Stuff\python\mailWords\current\mailWords2.py", line 100, in <module>
writeWords(storage)
File "C:\Users\LewTo002\Google Drive\Todd's Stuff\python\mailWords\current\mailWords2.py", line 66, in writeWords
except pywintypes.com_error:
NameError: name 'pywintypes' is not defined
I am used to seeing things like here ( https://docs.python.org/2/library/exceptions.html#exception-hierarchy ) and have been basing my method of writing the try/except off of here ( https://docs.python.org/3/tutorial/errors.html )
My question is how do I determine the error type that I am trying to catch based on the top portion of the traceback?
You need to add an import, more specifically
from pywintypes import com_error
then use the following
except com_error as e:
By importing "pywintypes" my error try/except functions properly.
Python open function does not return file descriptor. Why could this be? I am using python 3.3.
test_file_open.py
#!/usr/bin/env python
import sys
if __name__ == '__main__':
html = ""
hmtl_fd = open("ns_temp.html",'r')
for line in html_fd:
html += line
Output:
Traceback (most recent call last):
File "./test_file_open.py", line 7, in <module>
for line in html_fd:
NameError: name 'html_fd' is not defined
Permissions:
-rwxr-xr-x 1 michael michael 160 Mar 16 23:03 test_file_open.py
There is a typo in a variable name, see hmtl_fd and html_fd.
Replace:
hmtl_fd = open("ns_temp.html",'r')
with:
html_fd = open("ns_temp.html",'r')
Typo: hmtl_fd in place of html_fd