OberonRex opened this issue on Oct 15, 2023 ยท 8 posts
OberonRex posted Sun, 15 October 2023 at 3:52 PM
In poser I see xTran on my piller as 9. My script shows 1.0465115308761597.
piller = scene.Actor("basepiller")
DX = piller.Parameter("xTran")
print(DX.Value())
If I set the Value to 9, the piller zooms far to the right. It seems to be scaling it up by a factor of a little under 9 and I haven't a clue as to why.
I'm trying to create and position a matrix of pillers, so I'm calculating xTran and friends in the obvious way -- and getting really strange results.
Any clues?
Also, typing here seems to double space. Don't think it used to. Any ideas about that?
Bastep posted Sun, 15 October 2023 at 4:04 PM
What is your units setting in the General Preferences?
Bastep posted Sun, 15 October 2023 at 4:20 PM
The value output by your script is in poser units. I guess you are using feet.
1.0465115308761597*8.600000131252514=8.999999302892244
The conversion factor for feet is 8.600000131252514
OberonRex posted Sun, 15 October 2023 at 4:38 PM
Aha! I was not aware of poser units. Thanks!
Bastep posted Sun, 15 October 2023 at 5:20 PM
OberonRex posted Sun, 15 October 2023 at 5:55 PM
Thanks guys! I have script now to duplicate a piller and arrange them all into an evenly spaced matrix. Very cool, but needs a little work, like a dialog box to set matrix spacing. But so much fun learning all this...
Bastep posted Mon, 16 October 2023 at 2:36 AM
Hello and good morning
I dug out an old script for conversion. It reads the Poser.ini file and searches for the set unit. It provides two methods for the conversion. The whole thing is quite easy to handle.
Have a nice day
#----------------------------------------------------------------------------------
# ConvertUnitsClass.py
#
#
# Date: 07.11.2020 08:13:22
# Last Change: 25.12.2020 00:13:26
# Version: 1.0
# Author: Bastep
# Contact: via Renderocity
#
# The code is free
#----------------------------------------------------------------------------------
import poser
from pathlib import Path
#-- Mode Codes for cvFromPU
PU_FROM_PU = 0
INCH_FROM_PU = 1
FEET_FROM_PU = 2
MM_FROM_PU = 3
CM_FROM_PU = 4
M_FROM_PU = 5
#-- Mode Codes for cvToPU
PU_TO_PU = 0
INCH_TO_PU = 1
FEET_TO_PU = 2
MM_TO_PU = 3
CM_TO_PU = 4
M_TO_PU = 5
#----------------------------------------------------------------------------------
# Definition UnitsClass
#----------------------------------------------------------------------------------
class ConvertUnitsClass:
def __init__(self):
self.__UnitData = (
('pu', 1.0), ('inch', 103.2000016), ('feet', 8.600000131252514),
('mm', 2621.2802657335), ('cm', 262.1280265733), ('m', 2.6212802657335)
)
self.__Unit = 0
self.__UnitName = ''
self.__UnitValue = 0.0
self.SetUnit()
#----------------------------------------------------------------------------------
# By default, the method gets its conversion factor from the Poser.ini file.
# But if you use one of the above codes you can convert as you like.
#----------------------------------------------------------------------------------
def cvFromPU(self, value, mode=None):
if mode:
return (value * self.__UnitData[mode][1])
else:
return (value * self.__UnitData[self.__Unit][1])
#----------------------------------------------------------------------------------
# By default, the method gets its conversion factor from the Poser.ini file.
# But if you use one of the above codes you can convert as you like.
#----------------------------------------------------------------------------------
def cvToPU(self, value, mode=None):
if mode:
return (value / self.__UnitData[mode][1])
else:
return (value / self.__UnitData[self.__Unit][1])
#----------------------------------------------------------------------------------
# Get
#----------------------------------------------------------------------------------
def GetUnitName(self):
return self.__UnitData[self.__Unit][0]
def GetUnitValue(self):
return self.__UnitData
#----------------------------------------------------------------------------------
# Initalizes the whole
#----------------------------------------------------------------------------------
def SetUnit(self):
self.__Unit = self.UnitFromPoser()
if self.__Unit < 0:
if self.__Unit == -1:
print('Path not exist.')
elif self.__Unit == -2:
print('Error reading the file.')
elif self.__Unit == -3:
print('unit_scale_type not found.')
self.__Unit = 4
self.__UnitName = self.__UnitData[self.__Unit][0]
self.__UnitValue = self.__UnitData[self.__Unit][1]
#----------------------------------------------------------------------------------
# Loads the Poser.ini file and gets the data for
# the units
#----------------------------------------------------------------------------------
def UnitFromPoser(self):
poserini=Path(poser.PrefsLocation(),'poser.ini')
if poserini.exists():
try:
inifile=open(poserini,'r').readlines()
for line in inifile:
if 'unit_scale_type' in line.lower():
line = line.split(' ')
return int(line[1])
return -3
except:
return -2
return -1
_______________________________________________________
And here is the program for testing:
import poser
import ConvertUnitsClass as cuc
import importlib
importlib.reload(cuc)
converter = cuc.ConvertUnitsClass()
scene = poser.Scene()
#-- Take the internalname of any actor in the scene.
actor = scene.ActorByInternalName('Morphable Column')
print(actor.InternalName())
pX = actor.ParameterByCode(poser.kParmCodeXTRAN)
pY = actor.ParameterByCode(poser.kParmCodeYTRAN)
pZ = actor.ParameterByCode(poser.kParmCodeZTRAN)
#-- default
print ('Default from Poser.ini')
print (converter.cvFromPU(pX.Value()))
print (converter.cvFromPU(pY.Value()))
print (converter.cvFromPU(pZ.Value()))
#-- with codes
print ('With Codes')
print (converter.cvFromPU(pX.Value(), cuc.FEET_FROM_PU))
print (converter.cvFromPU(pY.Value(), cuc.FEET_FROM_PU))
print (converter.cvFromPU(pZ.Value(), cuc.FEET_FROM_PU))
OberonRex posted Tue, 17 October 2023 at 8:04 AM
That is amazing! As a retired "programmer/systems engineer/whatever title they came up with" (I wrote code, ya ken?), I'm quite impressed, most especially with the organizaion and layout of your code, and -- that it's a complete, all-in-one-place solution. After the earlier explanation about Poser Units, I was thinking about an invisible object, placed at height of "1" in the current units. The height to be measured in script will yield the conversion ratio directly. But it requires a cooperating "known" object. If I placed the object in the my library, loaded it from script, measured the height, then deleted the object, all in script, then it would be ALMOST an all-in-one-place solution, but I like yours better because it IS an all-in-one-solution...
Thank you!