What's new

Issue with GetArea()

kyleborot

Member
Hi all,

I've come across a peculiar issue with GetArea that I was hoping to get feedback on. I noticed when a cut is made on a face, the area that GetArea() outputs will vary based on the position of the cut. The areas outputted are also wrong. Expected 92.931 in^2. Box dimensions are 10x10x5 inches. See photo and code.

Python:
import sys
import AlibreScript

if AlibreScriptVersion < 1110:
    sys.exit('Please upgrade your copy of Alibre Design to use this script')

Units.Current = UnitTypes.Inches
Part = CurrentPart()

faces = []
areas = []
faces = Part.GetFaces()
for face in faces:
    areas.append(face.GetArea())
for i in range(len(faces)):
    print(faces[i], areas[i])
1717675644986.png
1717675681450.png
 

DavidJ

Administrator
Staff member
Well the zero value can't be correct.

Is there some mismatch of the indices?

I'd expect 4 faces at 50 sq.in which you have - 2 faces at same area (assuming hole is perpendicular to the square face, and the part is indeed dimensioned as you say), and one face (the inside of the hole) at some other value.

You didn't mention hole size - hope you are not expecting us to back calculate it.

Have you compared to the values shown by manually selecting each face?

Other can comment better than me on potential issues with the code - I'm only a cobbler together of such things and I hate Python if trying to follow the code.
 

kyleborot

Member
Well the zero value can't be correct.

Is there some mismatch of the indices?

I'd expect 4 faces at 50 sq.in which you have - 2 faces at same area (assuming hole is perpendicular to the square face, and the part is indeed dimensioned as you say), and one face (the inside of the hole) at some other value.

You didn't mention hole size - hope you are not expecting us to back calculate it.

Have you compared to the values shown by manually selecting each face?

Other can comment better than me on potential issues with the code - I'm only a cobbler together of such things and I hate Python if trying to follow the code.
Hole size is 3 inch diameter, through all. Face<1> turns out to be the face of the hole, so it's interesting that it's outputting 0. When manually selecting the faces Face<2> to Face<5> are all correct. But Face<6> and Face<7> both have a surface area of 92.931 in^2, rather than what the script outputs. Those values in the script don't exist anywhere in the model. When checking if the indices were mismatched, it didn't seem like it was. I changed the code to be more readable and it's outputting the same as shown above
Python:
import sys
import AlibreScript

if AlibreScriptVersion < 1110:
    sys.exit('Please upgrade your copy of Alibre Design to use this script')

Units.Current = UnitTypes.Inches
Part = CurrentPart()

faces = []
areas = []
faces = Part.GetFaces()
print(faces)
for i in range(len(faces)):
    areas.append(faces[i].GetArea())
    print(faces[i], areas[i])
 

DavidJ

Administrator
Staff member
I changed the code to be more readable
Wasn't a criticism of your coding - rather that because Python needs so little to be typed, (and I don't use it enough to be familiar) it takes me ages to work out what is going on - and with more complex stuff I just can't get the sense of what is intended.

It's much more obvious what is going on in more verbose languages.
 

kyleborot

Member
Wasn't a criticism of your coding - rather that because Python needs so little to be typed, (and I don't use it enough to be familiar) it takes me ages to work out what is going on - and with more complex stuff I just can't get the sense of what is intended.

It's much more obvious what is going on in more verbose languages.
No criticism taken! The code was difficult for me to come back to and analyze too. Python is notoriously easy to write, difficult to read.
 

DavidJ

Administrator
Staff member
Anyway - agreed the values look wrong and do appear to change if you move the hole.

Suggest opening a support ticket.
 

stepalibre

Alibre Super User
Hi all,

I've come across a peculiar issue with GetArea that I was hoping to get feedback on. I noticed when a cut is made on a face, the area that GetArea() outputs will vary based on the position of the cut. The areas outputted are also wrong. Expected 92.931 in^2. Box dimensions are 10x10x5 inches. See photo and code.

Python:
import sys
import AlibreScript

if AlibreScriptVersion < 1110:
    sys.exit('Please upgrade your copy of Alibre Design to use this script')

Units.Current = UnitTypes.Inches
Part = CurrentPart()

faces = []
areas = []
faces = Part.GetFaces()
for face in faces:
    areas.append(face.GetArea())
for i in range(len(faces)):
    print(faces[i], areas[i])
View attachment 41911
View attachment 41912
Using AlibreX directly works as expected:

Python:
import sys
import clr
clr.AddReference('System.Runtime.InteropServices')
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Runtime.InteropServices import Marshal
alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
objADPartSession = session
print(objADPartSession.Bodies.Item(0).Faces.Item(6).Face.Area / 100)
 

kyleborot

Member
Using AlibreX directly works as expected:

Python:
import sys
import clr
clr.AddReference('System.Runtime.InteropServices')
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Runtime.InteropServices import Marshal
alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
objADPartSession = session
print(objADPartSession.Bodies.Item(0).Faces.Item(6).Face.Area / 100)
This outputs 599.556326881. What units is this meant to be in?
 

kyleborot

Member
Using AlibreX directly works as expected:

Python:
import sys
import clr
clr.AddReference('System.Runtime.InteropServices')
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Runtime.InteropServices import Marshal
alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
objADPartSession = session
print(objADPartSession.Bodies.Item(0).Faces.Item(6).Face.Area / 100)
After fiddling with your implementation and trying to get it to work in Assembly context, I can't seem to get from AssemblySession to Part session. I am new to using AlibreX and don't really understand the API help documentation in the Program Files. Could you help me with this program and if you have it, point me to more resources for the syntax of the API?
Python:
import sys
import clr

if AlibreScriptVersion < 1110:
    sys.exit('Please upgrade your copy of Alibre Design to use this script')


clr.AddReference('System.Runtime.InteropServices')
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Runtime.InteropServices import Marshal

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
objADPartSession = session
faces = []
areas = []
Assem = CurrentAssembly()
for P in Assem.Parts:
    for i in range(len(P.Faces)):
        print((objADPartSession.Bodies.Item(0).Faces.Item(i).Face.Area))
 

stepalibre

Alibre Super User
You have to check types and match them correctly in order to use Alibre Script and AlibreX together.

This line won't work as you have it, you're mixing types/objects:
print((objADPartSession.Bodies.Item(0).Faces.Item(i).Face.Area))

Review these examples:

Try to get them working and then let me help from there.

Those examples were made for V27.
 

kyleborot

Member
You have to check types and match them correctly in order to use Alibre Script and AlibreX together.

This line won't work as you have it, you're mixing types/objects:
print((objADPartSession.Bodies.Item(0).Faces.Item(i).Face.Area))

Review these examples:

Try to get them working and then let me help from there.

Those examples were made for V27.
I took the code from the thread you had and tried to modify it. This is the closest I could get:
Python:
import sys
import clr
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program\\Addons\\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib\\site-packages")
import AlibreScript
from AlibreScript.API import *
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root

# Find the current assembly session
assemblySession = None
for i in range(root.Sessions.Count):
    session = root.Sessions.Item(i)
    if session.SessionType == AlibreX.SessionType.Assembly:
        assemblySession = session
        break

if assemblySession is None:
    print("No assembly session found.")
    sys.exit()

print(assemblySession.FilePath)
print("Number of components in the assembly:", assemblySession.Parts.Count)

# Iterate through all parts in the assembly and print vertices
for i in range(assemblySession.Parts.Count):
    part = assemblySession.Parts.Item(i)
    print("Part:", part.DisplayName)
    b = part.Bodies
    print("Number of bodies in the part:", b.Count)
    if b.Count > 0:
        verts = b.Item(0).Vertices
        print("Number of vertices in the first body:", verts.Count)
        def printpoint(x, y, z):
            print("{0} , {1} , {2}".format(x, y, z))
        for j in range(verts.Count):
            vert = verts.Item(j)
            point = vert.Point
            printpoint(point.X, point.Y, point.Z)

Win = Windows()
Win.InfoDialog('This code is from Alibre Script.', assemblySession.FilePath)
Win.ErrorDialog('This code is from Alibre Script!', assemblySession.Author)
print(Win.QuestionDialog('This code is from Alibre Script?', assemblySession.Author))
I get an error saying AlibreX has no SessionType attribute...which is confusing because the Alibre Automation Type Library inside the program files says it has a Session interface, with a SessionType attribute. The documentation isn't very clear.
 

stepalibre

Alibre Super User
Take a look at what assemblySession returns from print(dir(assemblySession)), you can't access Parts, you need to traverse occurrences.
Python:
import sys
import clr
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program\\Addons\\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib\\site-packages")
import AlibreScript
from AlibreScript.API import *
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root

# Find the current assembly session
assemblySession = None
session = root.Sessions.Item(i)
assemblySession = session
print(dir(assemblySession))

if assemblySession is None:
    print("No assembly session found.")
    sys.exit()

print(assemblySession.FilePath)
print(assemblySession.Name)
print(assemblySession.SessionType)
 

kyleborot

Member
Take a look at what assemblySession returns from print(dir(assemblySession)), you can't access Parts, you need to traverse occurrences.
Python:
import sys
import clr
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program\\Addons\\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib\\site-packages")
import AlibreScript
from AlibreScript.API import *
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root

# Find the current assembly session
assemblySession = None
session = root.Sessions.Item(i)
assemblySession = session
print(dir(assemblySession))

if assemblySession is None:
    print("No assembly session found.")
    sys.exit()

print(assemblySession.FilePath)
print(assemblySession.Name)
print(assemblySession.SessionType)
This is what I received:
Bash:
['ActiveConfiguration', 'AutoBrepImportSummary', 'AutoRegenerate', 'BindKeyToItem', 'Bodies', 'CameraPosition', 'CheckPrintability', 'CircularFacets', 'Close', 'Color', 'Configurations', 'ConstituentFilePaths', 'CreateObjRef', 'CreatePackage', 'DesignAxes', 'DesignMeshes', 'DesignPlanes', 'DesignPoints', 'DesignProperties', 'DesignSurfaces', 'DesignType', 'EdgeColor', 'Equals', 'ExportAP203', 'ExportAP214', 'ExportAP242', 'ExportBIP', 'ExportBOM', 'ExportIGES', 'ExportOBJ', 'ExportParasolid', 'ExportSAT', 'ExportSAT2', 'ExportSTEP', 'ExportSTL', 'ExportSTL2', 'FacetData', 'FacetDataForConfiguration', 'FeatureCount', 'Features', 'FilePath', 'GeometryFactory', 'GetBodiesForConfiguration', 'GetHashCode', 'GetLifetimeService', 'GetMeshData', 'GetMeshDataEx', 'GetMeshDefinition', 'GetMeshDefinitionEx', 'GetType', 'HasErrors', 'Highlight', 'IGESOptions', 'Identifier', 'InitializeLifetimeService', 'IsGUIVisible', 'IsPerspective', 'IsSectioning', 'MemberwiseClone', 'ModelTolerance', 'Name', 'NewTargetProxy', 'Parameters', 'PhysicalProperties', 'PreviewSnapshot', 'PrintabilityCheckResults', 'ReferenceEquals', 'Reflectivity', 'RegenerateAll', 'RegenerateDesign', 'Root', 'Save', 'SaveAll', 'SaveAllToSafe', 'SaveAs', 'SaveCurrentViewSnapshot', 'SaveNew', 'SavedViews', 'SectionBody', 'Select', 'SelectedObjects', 'SelectedObjectsEx', 'SelectionFilter', 'SessionType', 'SetActive', 'SetViewTransform', 'SheetMetalSession', 'ShowFeatureColor', 'Sketches', 'Sketches3D', 'Source', 'StartChanges', 'StopChanges', 'Suppress', 'Text', 'TimeStamp', 'ToString', 'Transparency', 'Type', 'UnSuppressAll', 'Unsuppress', 'UpdatePreviewSnaphot', 'ViewExtents', 'ViewTransform', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'getAllTriangularFacets', 'getAutomationWrapper', 'getColorRef', 'getGetBodyTimeStamp', 'getSelectionWrapper', 'implementSaveSnapshot', 'postProcessPrintabilityChecking', 'preparePrintabilityChecking', 'root', 'session', 'setObservation', 'update', 'updateAutomationWrappers']
None
New Part (1)
AD_PART
I see that bodies is something accessible. Can't you also access part through the body interface? Could I traverse that interface, go to PartSession, get faces from there, and then get area?
 

stepalibre

Alibre Super User
This is what I received:
Bash:
['ActiveConfiguration', 'AutoBrepImportSummary', 'AutoRegenerate', 'BindKeyToItem', 'Bodies', 'CameraPosition', 'CheckPrintability', 'CircularFacets', 'Close', 'Color', 'Configurations', 'ConstituentFilePaths', 'CreateObjRef', 'CreatePackage', 'DesignAxes', 'DesignMeshes', 'DesignPlanes', 'DesignPoints', 'DesignProperties', 'DesignSurfaces', 'DesignType', 'EdgeColor', 'Equals', 'ExportAP203', 'ExportAP214', 'ExportAP242', 'ExportBIP', 'ExportBOM', 'ExportIGES', 'ExportOBJ', 'ExportParasolid', 'ExportSAT', 'ExportSAT2', 'ExportSTEP', 'ExportSTL', 'ExportSTL2', 'FacetData', 'FacetDataForConfiguration', 'FeatureCount', 'Features', 'FilePath', 'GeometryFactory', 'GetBodiesForConfiguration', 'GetHashCode', 'GetLifetimeService', 'GetMeshData', 'GetMeshDataEx', 'GetMeshDefinition', 'GetMeshDefinitionEx', 'GetType', 'HasErrors', 'Highlight', 'IGESOptions', 'Identifier', 'InitializeLifetimeService', 'IsGUIVisible', 'IsPerspective', 'IsSectioning', 'MemberwiseClone', 'ModelTolerance', 'Name', 'NewTargetProxy', 'Parameters', 'PhysicalProperties', 'PreviewSnapshot', 'PrintabilityCheckResults', 'ReferenceEquals', 'Reflectivity', 'RegenerateAll', 'RegenerateDesign', 'Root', 'Save', 'SaveAll', 'SaveAllToSafe', 'SaveAs', 'SaveCurrentViewSnapshot', 'SaveNew', 'SavedViews', 'SectionBody', 'Select', 'SelectedObjects', 'SelectedObjectsEx', 'SelectionFilter', 'SessionType', 'SetActive', 'SetViewTransform', 'SheetMetalSession', 'ShowFeatureColor', 'Sketches', 'Sketches3D', 'Source', 'StartChanges', 'StopChanges', 'Suppress', 'Text', 'TimeStamp', 'ToString', 'Transparency', 'Type', 'UnSuppressAll', 'Unsuppress', 'UpdatePreviewSnaphot', 'ViewExtents', 'ViewTransform', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'getAllTriangularFacets', 'getAutomationWrapper', 'getColorRef', 'getGetBodyTimeStamp', 'getSelectionWrapper', 'implementSaveSnapshot', 'postProcessPrintabilityChecking', 'preparePrintabilityChecking', 'root', 'session', 'setObservation', 'update', 'updateAutomationWrappers']
None
New Part (1)
AD_PART
I see that bodies is something accessible. Can't you also access part through the body interface? Could I traverse that interface, go to PartSession, get faces from there, and then get area?
That doesn't look like the assembly session.
 

stepalibre

Alibre Super User
This is how to get the area of a face in a part inside an assembly:

assemblySession.RootOccurrence.Occurrences.Item(0).DesignSession.Bodies.Item(0).Faces.Item(5).Face.Area

Loop through the occurrences (parts), get the design session of the part
 

stepalibre

Alibre Super User
This is how to get the area of a face in a part inside an assembly:

assemblySession.RootOccurrence.Occurrences.Item(0).DesignSession.Bodies.Item(0).Faces.Item(5).Face.Area

Loop through the occurrences (parts), get the design session of the part
1717779563906.png
 

stepalibre

Alibre Super User
Get the area of faces in parts inside an assembly:
Python:
import sys
import clr
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program\\Addons\\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib\\site-packages")
import AlibreScript
from AlibreScript.API import *
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
assemblySession = session

for i in range(assemblySession.RootOccurrence.Occurrences.Count):
   part = assemblySession.RootOccurrence.Occurrences.Item(i)
   for j in range(part.DesignSession.Bodies.Item(0).Faces.Count):
       print(part.DesignSession.Bodies.Item(0).Faces.Item(j).Face.Area/100)
Output
Code:
>>>
3.04024487458
3.2258
3.2258
3.2258
3.2258
5.99556326881
5.99556326881
>>>
1717782419111.png
The TopMostSession must be an assembly, I removed the session type checking code, for this example.
 

kyleborot

Member
Get the area of faces in parts inside an assembly:
Python:
import sys
import clr
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program\\Addons\\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib\\site-packages")
import AlibreScript
from AlibreScript.API import *
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
assemblySession = session

for i in range(assemblySession.RootOccurrence.Occurrences.Count):
   part = assemblySession.RootOccurrence.Occurrences.Item(i)
   for j in range(part.DesignSession.Bodies.Item(0).Faces.Count):
       print(part.DesignSession.Bodies.Item(0).Faces.Item(j).Face.Area/100)
Output
Code:
>>>
3.04024487458
3.2258
3.2258
3.2258
3.2258
5.99556326881
5.99556326881
>>>
View attachment 41925
The TopMostSession must be an assembly, I removed the session type checking code, for this example.
I was able to use this and get the area of parts in subassemblies too.
Python:
import sys
import clr
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.0.28094\\Program\\Addons\\AlibreScript")
clr.AddReference("AlibreX")
clr.AddReference("AlibreScriptAddOn")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import AlibreX
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT")
sys.path.append("C:\\PROGRAM FILES\\Alibre Design 28.0.0.28094\\PROGRAM\\ADDONS\\ALIBRESCRIPT\\PythonLib\\site-packages")
import AlibreScript
from AlibreScript.API import *
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal

def iterate_occurrences(occurrences):
    for i in range(occurrences.Count):
        occurrence = occurrences.Item(i)
        design_session = occurrence.DesignSession
        if design_session is not None:
            design_session_type = type(design_session).__name__
            if design_session_type == "AlibreAssemblySession":
              print("assembly")
              iterate_occurrences(occurrence.Occurrences)
            elif design_session_type == "AlibrePartSession":
              print("part")
              for j in range(design_session.Bodies.Item(0).Faces.Count):
                print(design_session.Bodies.Item(0).Faces.Item(j).Face.Area/100)
              

alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root
session = root.TopmostSession
assemblySession = session

root_occurrence = assemblySession.RootOccurrence
iterate_occurrences(root_occurrence.Occurrences)

Question: Can you force the TopmostSession to be the assembly you're targeting?
 
Top