What's new

Python Help Please

albie0803

Alibre Super User
Code:
import time
ca=CurrentAssembly()
for i in range(len(ca.Parts)):
  print 'Part Nr.:',i, 'named',ca.Parts[i].Name
  for j in range(len(ca.Parts[i].Parameters)):
    print 'Part',i, 'Param:', j, 'Name:', ca.Parts[i].Parameters[j], 'Value:', ca.Parts[i].Parameters[j].Value
    ca.Parts[i].Parameters[j].Value = EParams[int(ca.Parts[i].Parameters[j].Name[1:3])]

I have this little block of code that writes the parameter value (kudos to one of you genius' who provided it for me). My parameters are named thus: G12_Bore and the code picks out the 12 amongst other things. The "12" becomes a variable number to read from a list in the last line. All well and good when I wanted every parameter.

I want to add more calculating parameters that I want ignored as the code goes through them. eg Teeth, which tries to evaluate ee and throws an error. I looked for and tried to use Try: Except but I can't get it right.

I want it to find the error and then skip to the next loop in the For statement, effectively ignoring any parameter that doesn't have a number in positions 2 and 3 of the name.

Hope that all makes sense.
 

idslk

Alibre Super User
Hello albie0803,
which tries to evaluate ee and throws an error
to get you right: You're reading out a parametervalue from EE, then you do a thing (eg. a calculation in Alibre Script) and write back a (different) value to a parameter in the EE. Inside EE are also calculations in the Equation Column (?) which lead EE to throw and error? What kind of Error message do you get?
Regards
Stefan
 

idslk

Alibre Super User
Hello @albie0803 ,

a few minutes ago i have taken a look if you have answered... and read your post again...
maybe the following lines help you doing want you want:
Code:
def numbertest(Eparam):
  print 'Checking Parametername:',Eparam
  if Eparam[1:3].isdigit():
    print 'Parametername has the number:',Eparam[1:3],' on place 2 and 3'
  else:
    print 'No needed number in Parametername on place 2 and 3!'

Eparam_a = 'G12_Bore'

numbertest(Eparam_a)

Eparam_b = 'Gxx_Bore'

numbertest(Eparam_b)
Beware: Your parameter name has to have 2 digits on the place 2 and 3 to be recognized as valid.
This means your name range is from "G00..." to "G99...".
If you use "G1_Bore" it will fail due to place 2 and 3 gives "1_".

It would be interesting for me to know what you are going to do.

Regards
Stefan
 
Last edited:

albie0803

Alibre Super User
I have a bevel crownwheel and pinion assembly that creates the turning blanks.
I have a spreadsheet that calculates the necessary parameter values.
I have a script that reads the values from the spreadsheet into list EParams.
The posted code reads the parameters from the parts, extracts the number and uses it to read the variable from EParams and write it back to the parameter in the part.
The assembly updates beautifully!
I only have the needed numbered parameters in each part.
I now want to add internally calculated parameters to generate a basic tooth.
eg Tooth_Depth, Tooth_Width etc

What I need is the correct coding so that when the parameters are read, Tooth_Depth is skipped because it doesn't have a number in position 2&3 like G12_Bore.

OK, so in answering your question I have come up with this. Will have to test it in a while

Code:
for i in range(len(ca.Parts)):
  print 'Part Nr.:',i, 'named',ca.Parts[i].Name
  for j in range(len(ca.Parts[i].Parameters)):
  if ca.Parts[i].Parameters[j].Name[1:3].isdigit():
   print 'Part',i, 'Param:', j, 'Name:', ca.Parts[i].Parameters[j], 'Value:', ca.Parts[i].Parameters[j].Value
   ca.Parts[i].Parameters[j].Value = EParams[int(ca.Parts[i].Parameters[j].Name[1:3])]

Will the for loop continue?
 
Last edited:
Top