What's new

C# Add on Development - Long Loading Time Accessing Part Properties (V26)

engineer@anago

New Member
Hi there Alibre users,

I've just finished creating an Excel Add-on that creates a Bill of Materials from the currently opened Alibre Assembly built in C#.
(We needed a customized solution, and the built-in Alibre BoM generator didn't have what we needed).
The Add-on itself works just fine with only one issue: it takes quite a while to load part properties from a part in an assembly on first time use.

Basically, my Add-on walks down the entire tree along all branches of the whole parent assembly and spits out a Bill of Materials in the currently opened Excel document.
On generating a BoM for the first time of opening an Alibre Assembly session, it can take several seconds just to retrieve the part properties of one part file - this can make BoM generation on large assemblies take several minutes to finish. More specifically, accessing the IADOccurrence.DesignSession.DesignProperties property is what takes so long. I believe this might be due to Alibre performing some sort of caching; since it doesn't need to hold this property in memory all the time, it will only cache it in memory when it is needed, making it take a long-time to access if it's never been accessed before in the current session.
I have a sliver of hope telling me it might be something to do with the fact that my project is an Office VSTO development project, and perhaps something about that and the Excel COM Interop could be interfering with things, but I doubt it.

What I'd like to know, is if anyone else has ran into this and has found a work-around or not.

(Will provide the files if absolutely necessary. Withholding for now as I'd like to release it only if fixing this problem is possible)
Appreciate the feedback.
 

simonb65

Alibre Super User
The problem with doing anything inside Alibre, especially adding entities or loading, is that every time something changes there is a massive delay as the UI and constraints mechanism updates.

I've found the best for performance is to write an external application (C#) that connects using the AlibreX.dll in 'Headless' mode, i.e. no UI just the geometry engine. That way loading, traversing the session and creating entities is way, way much quicker!

This approach may be quicker for just generating a BOM, if you only want to walk the assembly and add data to an excel document.
 

bolsover

Senior Member
@engineer@anago

So pleased to lean about another user working with the API and C#. I think you have the makings of a very useful add-on there. I suspect it might be faster to write xlsx directly rather wite to an existing spreadsheet using COM interop. I know there are a couple of open source xlsx libraries. Might be worth trying - it sounds like you've already done the hard part!

David
 

idslk

Alibre Super User
(We needed a customized solution, and the built-in Alibre BoM generator didn't have what we needed).
What is your additional need for the BOM?
Do you write an Excel Add on or an Alibre Add on? As an VSTO it sounds like an Ecxel Add on...

Regards
Stefan
 

NateLiquidGravity

Alibre Super User
I attempted to make my own BOM like export using AlibreScript but I ran into a different problem: I couldn't figure out how to find what configuration was selected for each occurrence. The only info I could find on configurations was the last one active - which was reporting the same for all occurrences of that same part/assembly.
 

engineer@anago

New Member
The problem with doing anything inside Alibre, especially adding entities or loading, is that every time something changes there is a massive delay as the UI and constraints mechanism updates.

I've found the best for performance is to write an external application (C#) that connects using the AlibreX.dll in 'Headless' mode, i.e. no UI just the geometry engine. That way loading, traversing the session and creating entities is way, way much quicker!

This approach may be quicker for just generating a BOM, if you only want to walk the assembly and add data to an excel document.
@simonb65 Thank you for your suggestion, I'd forgotten there were different 'modes' for operating an Add-on in. Will try it out.

What is your additional need for the BOM?
Do you write an Excel Add on or an Alibre Add on? As an VSTO it sounds like an Ecxel Add on...

Regards
Stefan
@idslk Yup it is an Excel Add-on. VSTO is correct.

@engineer@anago

So pleased to lean about another user working with the API and C#. I think you have the makings of a very useful add-on there. I suspect it might be faster to write xlsx directly rather wite to an existing spreadsheet using COM interop. I know there are a couple of open source xlsx libraries. Might be worth trying - it sounds like you've already done the hard part!

David
@bolsover Not sure what you mean by writing to xlsx directly. I'd imagined I am writing directly given that I'm using the COM interop. Regardless, it is great to see another C# developer too. Also, I do need to use the COM interop because I need access to sheet manipulation and other Excel features that I think only the COM interop provides. Though, it would be very nice if there was a performance upgrade anyway ha.

I attempted to make my own BOM like export using AlibreScript but I ran into a different problem: I couldn't figure out how to find what configuration was selected for each occurrence. The only info I could find on configurations was the last one active - which was reporting the same for all occurrences of that same part/assembly.
@NateLiqGrav Definitely have a look at working in a C# Add-on environment. It's pretty neat, opens up a lot of functionality. I haven't had much experience with AlibreScript though so my comparison might be wrong.

Cheers
Engineer
 

NateLiquidGravity

Alibre Super User
@NateLiqGrav Definitely have a look at working in a C# Add-on environment. It's pretty neat, opens up a lot of functionality. I haven't had much experience with AlibreScript though so my comparison might be wrong.
There's hardly a spot in the AlibreX API I can't access from AlibreScript - it's Iron Python stuck in an add-on. Try testing what I said about selected configuration of parts/sub assemblies as-set in the assemblies. Especially if you use or plan to use configurations. If the API can do it then please share how as support could not give me an answer of how to get that correctly.
 

bolsover

Senior Member
Not sure what you mean by writing to xlsx directly

I had thought you were writing an Alibre Add-on rather than an Excel add-on. Coming from the Excel side, I guess using the COM interop makes sense but if you go from the Alibre side, I would have used something like SpreadSheetLight to create and write the Excel data.

As @NateLiqGrav observed there is hardly (if any) part of the AlibreX API you can't get to from AlireScript. That said, my personal preference is to use C# and the AlibreX API and to generate Alibre Add-ons. There are just a few 'set-up' steps needed but once you have the Add-On basics working, developing with C# using a 'proper' IDE rather than the AlibreScript interface is so much easier.
David
 
Top