Replies: 5 comments 2 replies
-
viewCenter is in DCS, so you will have to translate the coordinates from pyrx_imp import Ap, Db, Ed, Ge, Gi, Gs, Rx
import traceback
#function test
def PyRxCmd_doit():
try:
status, ent_id, *_ = Ed.Editor.entSel("Select viewport: ")
if not status == Ed.PromptStatus.eOk:
return
vp = Db.Viewport(ent_id)
coords = (*vp.viewCenter().toTuple(), 0.0)
print(coords)
for ele in Db.Core.entGetX(ent_id):
if ele[0] == 1040:
if ele[1] in coords and ele[1] > 0.0:
print(ele)
except Exception as err:
print(err)
def PyRxCmd_doit2():
try:
status, ent_id, *_ = Ed.Editor.entSel("Select viewport: ")
if not status == Ed.PromptStatus.eOk:
return
vp = Db.Viewport(ent_id)
cenDCS = Ge.Point3d(vp.viewCenter().toTuple()) #adds the zero for you
rbfrom = [(Rx.LispType.kInt16, 2)] #DCS
rbto = [(Rx.LispType.kInt16, 3)] #PSDCS
cenPDCS = Ed.Core.trans(cenDCS,rbfrom,rbto,False)
print(cenPDCS)
except Exception as err:
print(err) |
Beta Was this translation helpful? Give feedback.
-
As a side note, Db.Core has ucs2Wcs, wcs2Ecs, wcs2Ucs, and ecs2Wcs. You must use acadtrans for DCS. It’s a handy function, for example, if you want the mouse position in WCS |
Beta Was this translation helpful? Give feedback.
-
Your solution didn't work, but maybe because I didn't have this viewport active. The key seems to be import traceback
from pyrx_imp import Db, Ed, Ge
def PyRxCmd_doit():
try:
status, ent_id, *_ = Ed.Editor.entSel("Select viewport: ")
if not status == Ed.PromptStatus.eOk:
return
vp = Db.Viewport(ent_id)
cenDCS = Ge.Point3d(vp.viewCenter().toTuple())
cenWCS = cenDCS + Ge.Vector3d(*vp.viewTarget().toTuple()) # !!!
print(cenWCS)
except Exception:
traceback.print_exc() |
Beta Was this translation helpful? Give feedback.
-
fixing py_list_to_vector3d, missed that |
Beta Was this translation helpful? Give feedback.
-
Another thing to think about is the viewport with a rotated Z axis. You probably want to convert this into a discussion :) |
Beta Was this translation helpful? Give feedback.
-
The code below sometimes returns an incorrect
.viewCenter()
point. As I understand it, these should be the same values as in the View section in the properties palette.I am attaching a file where this problem occurs.
viewport_bug.zip
Beta Was this translation helpful? Give feedback.
All reactions