Unknown exception for TransformBy method

Unknown exception for TransformBy method

tanmayms3009
Participant Participant
401 Views
2 Replies
Message 1 of 3

Unknown exception for TransformBy method

tanmayms3009
Participant
Participant

I am trying to use the TransformBy method for a solid object using Python in AutoCAD. But the code throws an unknown exception. I also tried to use aDouble data structure but no luck. The code is as below:

 

''

import time
from pyautocad import Autocad, APoint, aDouble
acad = Autocad()
 
loft_3D = acad.model.AddBox(APoint(0, 0, 0), 4, 6, 2)
line = acad.model.AddLine(APoint(0, 0, 0), APoint(100, 500, 0))
p0 = APoint(0,0,0
px = APoint(100,0,0)
py = APoint(0,100,0)

MiUCS = acad.doc.UserCoordinateSystems.Add(p0, px, py, "UCS_NEW_1")
VarMatrix = MiUCS.GetUCSMatrix()
print(VarMatrix)
VarMatrix_1=((0.7071, -0.7071, 0.0, 5.0), (0.7071, 0.7071, 0.0, -2.07), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0))
time.sleep(5)
loft_3D.TransformBy(VarMatrix_1
 
Error:
Traceback (most recent call last):
File "D:\Tanmay\Knowledgebase\Civil\Automation\pyautocad\Test\test4.py", line 34, in <module>
loft_3D.TransformBy(VarMatrix_1) # Here the error occurs
File "C:\Users\91998\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\comtypes\client\lazybind.py", line 182, in caller
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
File "C:\Users\91998\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\comtypes\automation.py", line 728, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147352567, 'Exception occurred.', (None, None, None, 0, None))
0 Likes
Replies (2)
Message 2 of 3

marko_ribar
Advisor
Advisor

What would you need Python for in terms of compatibility with CAD software...

What would you need to do with line entity...

Why do you specified UCS with origin 0,0,0 ; ucsxdir 100,0,0 ; ucsydir 0,100,0 ... Wasn't it better 0,0,0 ; 1,0,0 ; 0,1,0...

Why you needed approximation for rotation around Z for approximately 45 degree... You should have specified exactly (sin (/ pi 4)) or (cos (/ pi 4))...

What do you actually accomplish with simultaneously rotating and moving... If it won't work, you could do it in 2 steps...

Why are you using (sleep) syntax when it's not necessity...

Are you in averse with simple programming technique very common for CAD facility such as ALisp/Vlisp...

If you are experimenting why are you doing it in a way that very much pollute simplicity and elegance of other, just maybe more adequate API language approaches, such as C#, C++, F#, or even VBA, Scripting for CAD or Object ARX...

Finally, what method are you really suggesting to others to make assumption that you are on right path and that you can influence to benefit to some kind of better practice and widening overall knowledge...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 3

tanmayms3009
Participant
Participant

Hi Marko, 

 

I am sorry if this thing made any offense to you in any way. 

I was just trying this using Python, I understand there are other ways in which we can do these things like vba, lisp, c#.

I don't think there's any problem in trying new ways. 

The sleep method is used here because requests sent to AutoCAD were faster than it could handle, and sleep is the solutions that worked for me continuing the process. 

Also, I am not trying to rotate the line for any specific reason, I am trying to find answer to help one of my acquaintance using TransformBy method. The code is just for the reference and not to perform any particular activity.

If you can help, I am happy to accept your solution.

 

Kind regards. 

0 Likes