What's new

Problems reading a GLP from Alibrescript. Help!

srjacob

Senior Member
I am having problems reading from a GLP using Alibrescript. I thought I was reading a specific parameter, but I get the wrong values.

Please Help!

TIA.

Steve
 

Attachments

  • PenHolder.AD_GLP
    531 KB · Views: 2

NateLiquidGravity

Alibre Super User
Without your assembly and AlibreScript code it is impossible to see what if anything you are doing wrong. I have never used the global parameters with AlibreScript. If I'm using AlibreScript I usually just change the parameters directly in the assembly/parts with the script.
 

srjacob

Senior Member
# open global parameters,path is D:\SJ Library\Projects\Pen holder, file is PenHolder
Params = GlobalParameters('D:\SJ Library\Projects\Pen holder', 'PenHolder')
# get access to a parameter and display the current value
TCFH = Params.GetParameter('TopCenterOfFirstHole')
print TCFH.Value

And the console value:

cls : Clears the screen
help : Shows the list of console commands
run : Executes the current script
run arg1 arg2 : Executes the current script, pass arguments
run "scriptname" : Executes a specific script
run "scriptname" arg1 arg2 : Executes a specific script, pass arguments

>>>
15.6845
>>>
 

srjacob

Senior Member
# open global parameters,path is D:\SJ Library\Projects\Pen holder, file is PenHolder
Params = GlobalParameters('D:\SJ Library\Projects\Pen holder', 'PenHolder')
# get access to a parameter and display the current value
TCFH = Params.GetParameter('TopCenterOfFirstHole')
print TCFH.Value

And the console value:

cls : Clears the screen
help : Shows the list of console commands
run : Executes the current script
run arg1 arg2 : Executes the current script, pass arguments
run "scriptname" : Executes a specific script
run "scriptname" arg1 arg2 : Executes a specific script, pass arguments

>>>
15.6845
>>>
 

NateLiquidGravity

Alibre Super User
That value is correct but in millimeters since you didn't specify Units.Current in your script.
Use these at the top of your script if you plan to do any math and to set the units to Inches.
Python:
from __future__ import division  # This fixes division with integers. For example the 1 / 2 = 0.5 instead of 0
Units.Current = UnitTypes.Inches
 

srjacob

Senior Member
That value is correct but in millimeters since you didn't specify Units.Current in your script.
Use these at the top of your script if you plan to do any math and to set the units to Inches.
Python:
from __future__ import division  # This fixes division with integers. For example the 1 / 2 = 0.5 instead of 0
Units.Current = UnitTypes.Inches
Thank you. That fixes the issue. I did not know the default units were in mm. I normally use mm, but in this case, I needed inches.
 

stepalibre

Alibre Super User
Thank you. That fixes the issue. I did not know the default units were in mm. I normally use mm, but in this case, I needed inches.

I shared this for that exact reason in your other forum post:



Python:
#https://help.alibre.com/articles/#!alibre-help-v23/parameters-with-units

# this script uses inches for it's units
Units.Current = UnitTypes.Inches
 
MyPart = Part('Foo')
 
# create parameter using current script units
LengthParam = MyPart.AddParameter('Length', ParameterTypes.Distance, 123.4)
# parameter value reads back in current script units
print 'Value in script units =', LengthParam.Value
 
# cteate parameter in degrees
RotationParam = MyPart.AddParameter('Rotation', ParameterTypes.Angle, 34.2)
# parameter reads back in degrees
print 'Value in degrees = ', RotationParam.Value
 
# create parameter with specific units
WidthParam = MyPart.AddParameter('Width', ParameterTypes.Distance, ParameterUnits.Centimeters, 7.32)
# reads back in current script units
print 'Value in script units = ', WidthParam.Value
# reads back the actual value we wrote
print 'Value we wrote = ', WidthParam.RawValue
 
# create parameter with specific units
WidthParam2 = MyPart.AddParameter('Width2', ParameterTypes.Distance, ParameterUnits.Inches, 1.0)
# reads back in current script units
print 'Value in script units = ', WidthParam2.Value
# reads back the actual value we wrote
print 'Value we wrote = ', WidthParam2.RawValue
 
# create parameter with no units
Count = MyPart.AddParameter('Count', ParameterTypes.Count, ParameterUnits.Unitless, 45)
# reads back value
print 'Count value = ', Count.Value
 
Last edited:
Top