Forum

Author Topic: may not be a bug but simply a change  (Read 3882 times)

JMR

  • Hero Member
  • *****
  • Posts: 502
    • View Profile
may not be a bug but simply a change
« on: November 03, 2014, 12:06:28 PM »
well I was happy using a python script Alexey published for leveling the bounding box but now it is not working any more with 1.1
Can you tell me what should I change in order to make it right?

Console: Traceback (most recent call last):
  File "C:/temp/reset_bound.py", line 4, in <module>
    chunk = doc.activeChunk
AttributeError: 'PhotoScan.Document' object has no attribute 'activeChunk'

******************************************************Python script********************
import PhotoScan, math

doc = PhotoScan.app.document
chunk = doc.activeChunk

if chunk.transform:
       T = chunk.transform
else:
       T = PhotoScan.Matrix().diag([1,1,1,1])

v = PhotoScan.Vector( [0,0,0,1] )
v_t = T * v
v_t.size = 3

if chunk.crs:
   m = chunk.crs.localframe(v_t)
else:
   m = PhotoScan.Matrix().diag([1,1,1,1])
m = m * T

s = math.sqrt(m[0,0]*m[0,0] + m[0,1]*m[0,1] + m[0,2]*m[0,2]) #scale factor
R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])
R = R * (1. / s)

reg = chunk.region
reg.rot = R.t()
chunk.region = reg
**********************************************************end*****************************

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: may not be a bug but simply a change
« Reply #1 on: November 03, 2014, 01:21:32 PM »
Hello José,

There were some major changes in Python API. So here's code for the version 1.1:

Code: [Select]
#compatibility: Agisoft PhotoScan Professional 1.1.0

import PhotoScan
import math

doc = PhotoScan.app.document
chunk = doc.chunk

T = chunk.transform.matrix

v = PhotoScan.Vector( [0,0,0,1] )
v_t = T * v
v_t.size = 3

if chunk.crs:
m = chunk.crs.localframe(v_t)
else:
m = PhotoScan.Matrix().diag([1,1,1,1])

m = m * T

s = math.sqrt(m[0,0]*m[0,0] + m[0,1]*m[0,1] + m[0,2]*m[0,2]) #scale factor

R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])

R = R * (1. / s)

reg = chunk.region
reg.rot = R.t()
chunk.region = reg
Best regards,
Alexey Pasumansky,
Agisoft LLC