What's new

Another script failure in v27

HaroldL

Alibre Super User
I tried running the script AutoFillet_02 by IDSLK and it doesn't run in v27.
Here's the result of the output window. no idea why if needs to repeat itself.
Is it a easy fix to make it run? Does it have anything to do with Alibre allowing multiple versions to be installed?

Code:
Traceback (most recent call last):
  File "<string>", line 30, in <module>
  File "<string>", line 27, in getalibrepath
WindowsError: [Errno 2] The system cannot find the file specified
>>>
Traceback (most recent call last):
  File "<string>", line 30, in <module>
  File "<string>", line 27, in getalibrepath
WindowsError: [Errno 2] The system cannot find the file specified
>>>

Here's the script
 

Attachments

  • AutoFillet_02.zip
    1.4 KB · Views: 11

idslk

Alibre Super User
long time ago i've planned to add more functionality into the script...never took the time...
here a reduced Version:
Python:
#standard header
author = 'IDSLK '
scriptname = 'AutoFillet '
#script_version = 0.1 # initial
#script_version = 0.2 # adepted to V23
script_version = 0.3 # adepted to V23 SP1  and corrected "win not defined"
script_version = 0.4 # adepted to V27
minor = 'a'
build_date = 20211005
made_with = 347013
made_with_Alibreversion = 'PRODUCTVERSION 27,0,0,27038'

try:
  enviroment = CurrentAssembly()
  enviroment_obj = enviroment._Assembly
except:
  enviroment = CurrentPart()
  enviroment_obj = enviroment._Part

def scriptversion(made_with):
  if AlibreScriptVersion <> made_with:
    infotext='Sorry, your AlibreScriptVersion '+str(AlibreScriptVersion)+'\ndoes not match the installed Version '+str(made_with)+'\nThe script function might be influenced!!!'
    win.InfoDialog(infotext,'error')
  else:
    print 'The installed AlibreScriptVersion equals '+str(AlibreScriptVersion)+' as expected!'

def alibreversion(made_with_Alibreversion):
  if Vers <> made_with_Alibreversion:
    infotext='Sorry, your AlibreVersion '+str(Vers)+'\ndoes not match the needed Version! '+str(made_with_Alibreversion)+'\nThe script function might be influenced!!!'
    win.InfoDialog(infotext,'error')
    #sys.exit()
  else:
    print 'The installed AlibreVersion equals '+str(Vers)+' as expected!'

from System import Enum
Root = Global.Root
ThisSession = Root.TopmostSession
Vers = Root.Version
win = Windows()
options = []
values = []
scriptversion(made_with)
alibreversion(made_with_Alibreversion)

choose = 0
chosen = 0
chosen = enviroment.Selections.Count
while choose == 0:
  shure = win.QuestionDialog('You have selected '+str(chosen)+' faces.\n\nPlease select three meaningful faces for the fillet\n(using SHIFT + LMB) and then press Yes',author + scriptname + 'V'+str(script_version)+minor)
  if shure == False:
    sys.exit()
  if enviroment.Selections.Count == 3:
    choose = 1
  chosen = enviroment.Selections.Count

#start of individual
three_faces = []
for i in enviroment.Selections:
  temp_face = i
  three_faces.append(temp_face)

fillet_dia = 0
parallel_faces =[]

if three_faces[0].DistanceTo(three_faces[1]) > 0:
  fillet_dia = three_faces[0].DistanceTo(three_faces[1])
  parallel_faces = [0,1]
  fillet_face = 2
elif three_faces[1].DistanceTo(three_faces[2]) > 0:
  fillet_dia = three_faces[1].DistanceTo(three_faces[2])
  parallel_faces = [1,2]
  fillet_face = 0
elif three_faces[0].DistanceTo(three_faces[2]) > 0:
  fillet_dia = three_faces[0].DistanceTo(three_faces[2])
  parallel_faces = [0,2]
  fillet_face = 1
elif fillet_dia == 0:
  print 'Sorry, no parallel faces...'
  sys.exit()

fillet_radius = fillet_dia/2

a=[]
for n in three_faces[0].Edges:
  a.append(n.Name)
b=[]
for m in three_faces[1].Edges:
  b.append(m.Name)
c=[]
for o in three_faces[2].Edges:
  c.append(o.Name)

edgelist = []
edgelist.append(set(a).intersection(b))
edgelist.append(set(b).intersection(c))
edgelist.append(set(a).intersection(c))

fillet_edges = []
for e in edgelist:
  try:
     fillet_edges.append(enviroment.GetEdge(list(e)[0]))
  except:
    pass#print 'end of set'

enviroment.AddFillet('AutoFillet',fillet_edges,fillet_radius,0)

Regards
Stefan
 

NateLiquidGravity

Alibre Super User
That AutoFillet is a cool function. Could be useful to people making slots using thin line extrusions cuts.

In case you do need to access the dll I had made this function (hopefully) future-proof.
Python:
import _winreg
def getalibrepath():
    try:
        hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'Software\\Alibre, Inc.\\Alibre Design')
        result = _winreg.QueryValueEx(hKey, 'HomeDirectory')
        return result[0]
    except Exception, e:
        try:
            keystring = r'SOFTWARE\Alibre, Inc.\Alibre Design' + '\\' + str(Global.Root.Version).split(' ')[1].replace(',','.')
            hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keystring)
            result = _winreg.QueryValueEx(hKey, 'HomeDirectory')
            return result[0]
        except Exception, e:
            print('Failed to get HomeDirectory')
            return ''
    return ''
  
print(getalibrepath())
 

HaroldL

Alibre Super User
long time ago i've planned to add more functionality into the script...never took the time...
here a reduced Version:
What functionality are you adding?

I just tried this on a rib with draft and it failed with this:
If it is limited to parallel faces then its usefulness is a bit restricted. Any way it can be made to work with draft faces?
Code:
The installed AlibreScriptVersion equals 347013 as expected!
The installed AlibreVersion equals PRODUCTVERSION 27,0,0,27038 as expected!
Sorry, no parallel faces...
>>>
 

HaroldL

Alibre Super User
can you post your part?
Here it is...as you can see on the example fillet, just adding a fillet to 1/2 the width of the top of the rib leaves a bit of the flat. It would be better if it was full round after the fillets were applied.
 

Attachments

  • 04-11B ORG TRAY.AD_PRT
    968.5 KB · Views: 2

idslk

Alibre Super User
Hello Harold,

Initially this was not the "intended" function, but it will make sense...
I will take a look at it on the weekend...

Regards
Stefan
 

idslk

Alibre Super User
Hello Harold,

i've taken a look... it's not perfect...
i've tested it with your file.
after you run the script you will see this requester:
1693096829778.png
Then you should select the edge which will be used for the diameter for the fillet. Confirm with ok. If you have confirmed without an chosen edge, the script will wait as long as long as you coose an edge...
after an Edge is chosen you will be automatically asked for the face to be filleted.
1693097067138.png
if you have the two faces of the "wall" standing under an angle, you have to enter this angle (in your example 12°). If the faces are parallel you have to enter 0.
1693097198569.png
after confirming with ok the feature "Autofillet" will be added...
1693097270870.png

It works only with symetrical faces and will have other weaknesses...
If someone reports fails or wishes...

Regards
Stefan
 

Attachments

  • AutoFillet_05.py
    2.3 KB · Views: 3

HaroldL

Alibre Super User
Thanks Stefan, this works as I thought it would - even with its limitations. I'm sure others may find it beneficial too.
It would be nice if it worked on unsymmetric faces but there are other workflows to deal with that.

It would be a nice addition to Alibre if this functionality would be added natively.
 

HaroldL

Alibre Super User
What you essentially are wanting is fillets made tangent to the three faces right?
That's correct.

Potentially then they could be variable fillets?
Yes, if the two opposite faces were not parallel along the adjoining face. Example: a tapered rib with draft applied to one or both of its sides.

Edit: Thought I'd post a couple of images as illustration of the potential using two variable fillets (which were a PITA to get close to a full face radius).

Before:
two variable fillet blend - before.jpg

And after:
two variable fillet blend.jpg

BTW, I have an enhancement request in for the variable fillet to add more points along an edge and assign multiple radii along it. I'm going to send this in to add to the request.
 
Last edited:

stepalibre

Alibre Super User
That AutoFillet is a cool function. Could be useful to people making slots using thin line extrusions cuts.

In case you do need to access the dll I had made this function (hopefully) future-proof.
Python:
import _winreg
def getalibrepath():
    try:
        hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'Software\\Alibre, Inc.\\Alibre Design')
        result = _winreg.QueryValueEx(hKey, 'HomeDirectory')
        return result[0]
    except Exception, e:
        try:
            keystring = r'SOFTWARE\Alibre, Inc.\Alibre Design' + '\\' + str(Global.Root.Version).split(' ')[1].replace(',','.')
            hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keystring)
            result = _winreg.QueryValueEx(hKey, 'HomeDirectory')
            return result[0]
        except Exception, e:
            print('Failed to get HomeDirectory')
            return ''
    return ''
 
print(getalibrepath())
Is this future proof? Otherwise a search for AlibreX.dll will suffice?

What if a machine includes multiple Alibre installs side by side?

1707859933343.png

My current approach is to link to the standard install locations but I will include a registry check as well.
 

NateLiquidGravity

Alibre Super User
Nothing is ever totally future proof, but I did my best. It gets the Alibre version number from the currently running Alibre Design AlibreScript Global.Root.Version and then gets the path that the Alibre installer set in the registry for that version.

I rearranged it recently since it is more likely than not that the newer method will be required than the older method.
Python:
import _winreg
def getalibrepath():
    try:
        keystring = r'SOFTWARE\Alibre, Inc.\Alibre Design' + '\\' + str(Global.Root.Version).split(' ')[1].replace(',','.')
        hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keystring)
        result = _winreg.QueryValueEx(hKey, 'HomeDirectory')
        return result[0]
    except Exception, e:
        try:
            hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'Software\\Alibre, Inc.\\Alibre Design')
            result = _winreg.QueryValueEx(hKey, 'HomeDirectory')
            return result[0]
        except Exception, e:
            print('Failed to get HomeDirectory')
            return ''
    return ''
 

print(getalibrepath())
 

stepalibre

Alibre Super User
If you're already running inside of Alibre in order to get the Global.Root.Version then it makes more sense to me to use reflection to get the assembly (AlibreX). You don't need AlibreX reference if running inside of Alibre. This function is more useful if you're running outside of Alibre and need to dynamically load AlibreX without specifying a hard path. My Python console scripts require similar code which is why I'm asking.
 
Last edited:

stepalibre

Alibre Super User
Thanks for clarifying It's use is for convenience It doesn't hurt to include it. I was focused on separating AlibreX and AlibreScript code because my console code needs to run outside of Alibre where AlibreScript and AlibreX is not available. Mixing the two can create issues if not careful.

I make dlls to access .Net types from IronPython python files for a similar reason:
Python:
import clr
clr.AddReference("testbed-test-code.dll")
from testbed import tools
test = tools()
run = test.test1()

My example code here is also an approach - the COM code:

 
Last edited:
Top