What's new

How to Identify Selected Objects from IObjectCollector?

Hello,

i am currently developing a just for fun External Forms Application to do some Stuff with Alibre Design via API.
(creating default Shapes for L, T, S, U-Profile, Involute Gears and with the new Release i tried a CAM based on 3D-Sketches)
This works really nice if you do it from the application side. For improvement of UX i thought it would be easy to use Alibre Design direct to Pick Items but this doesn't work like expected.

Has anyone some advice, hints or tips?


More detailed explanation:

I used the Example from "SelectionAddOnSample" and transfered it to C#. Only for the first 2 cases, Vertices and Edges.
Then i do a auto selection of some edges.

After that i used
C#:
void exampleMethod()
{
SelectionHelper selectionHelper = new SelectionHelper();    // This is the example implementation from SelectionAddOnSample --> CSelectObjectCommand::OnSelect(...)
                    selectionHelper.OnSelect(session, 1);

                    IObjectCollector collector = session.SelectedObjects;       // From the active part session get the selected objects (i think this could be a picker)
                    if (collector != null)
                    {
                        logbuch.print("Currently Selected Objects = " + collector.Count.ToString());
                        logbuch.print("Object Type? ==> " + collector.ObjectType.ToString());
                        for (int i = 0; i < collector.Count; i++)
                        {
                            string typeName = "Unknown";
                            object test = null;

                            try
                            {
                                IObjectCollector testCollector = session.Root.NewObjectCollector(); // Additional Collector to get the First Edge Element of the whole selection
                                if (i == 0)
                                {
                                    testCollector.Add(collector.Item(i));
                                    session.Select(testCollector);
                                }

                                test = collector.Item(i) as IADEdge;
                                if (collector.Item(i) is IADEdge edge)
                                {
                                    typeName = "IADEdge";
                                }
                            }
                            catch (Exception ex)
                            {
                                logbuch.print("Error: " + ex.Message);
                            }

                            logbuch.print("Selected Object (" + i.ToString() + "): " + (collector.ObjectType.ToString()) + ", of Type: " + typeName);
                        }
                    }
}

As Result i get:

1672316182912.png

What can i do to readback selected Elements?

Selection of testCollector works, but i can't do anything with the Data inside IObjectCollector.
Need Help.

Greetings.
 
Update:

When i try to do a cast like this:

C#:
var test2 = (IADEdge)collector.Item(i);

then i get:

Interface not Supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
 
The items in the SelectedObjects collection are target proxies (IADTargetProxy). The actual selections and their type are found under IADTargetProxy.Target
Ah thanks, this helps a lot.
This simple information would be nice in the api documentation under IObjectCollector Interface ;) and as return value ObjectType in IObjectCollector.

BUT:

With IADTargetProxy.Target i get a Object "System.Object" ... why?
Wouldn't it be possible to return IADTargetProxy directly and give IADTargetProxy a property with the IADObjectType to identify what i get?

Because Bruteforce testing is not the best solution i think.

I know, that IADTargetProxy.Target has this Type information but only if a cast to a concrete type is already done.
Or is there a Baseclass for all geometric objects available?

The way described in the official API documentation is not possible:

1672399245058.png
 
Last edited:
For all new in this Topic here a possible workaround for a specified alibre object type (for a general method this is not the best way and api improvements are needed):

C#:
void exampleMethod()
{
    // Prerequirements: a open PartSession with some Selected Edge Geometry.
    IObjectCollector objCollector = Root.TopmostSession.SelectedObjects;
    if (objCollector != null)
    {
        string orgAlibreType = objCollector.ObjectType.ToString();

        Console.WriteLine("Currently Selected Objects = " + objCollector.Count.ToString());
        Console.WriteLine("Object Type? ==> " + orgAlibreType);

        for (int i = 0; i < objCollector.Count; i++)
        {
            string customTypeName = "Unknown";

            try
            {
                IADTargetProxy proxy = objCollector.Item(i) as IADTargetProxy;
                if (proxy == null)
                {
                    Console.WriteLine("proxy is null!");
                    continue;
                }

                object testTarget = proxy.Target;
                if (testTarget is IADEdge edge) // This is brute force testing or guessing
                {
                    customTypeName = "Edge";
                    orgAlibreType = edge.Type.ToString();
                    string topologyType = edge.TopologyType.ToString();
                    orgAlibreType += ", " + topologyType;
                }
               else if (testTarget is IADFace face)
               {
                    customTypeName = "Face";
                    orgAlibreType = face.Type.ToString(); // Read Type only possible if you already have the correct instance :D
                    string topologyType = face.TopologyType.ToString();
                    orgAlibreType += ", " + topologyType;
                }
                Console.WriteLine("Selected Object (" + i.ToString() + "): " + (orgAlibreType) + ", of Type: " + customTypeName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
    }
}
 
Last edited:
I've worked up a few C# routines to work with Alibre API.
Have a look at my GitHub repository here.. https://github.com/bolsover/UtilitiesForAlibre

I've done a fair amount of work on Involute gears. I'm just about to start a new project building on existing work and cleaning up a good deal!

db
Sounds good, in my project it is always like, i have a current problem and i need a quick method to solve it, then i go into my ui and try to implement a piece of code which does it for me. therfore i decided not to use it as Alibre Plugin, so i can add buttons quicker and implement some code. I know this is not professional coding but helps a lot.

Example for CAM:

1672414191449.png

Example for GearWheel:

1672414273956.png
 

bolsover

Senior Member
Sounds good, in my project it is always like, i have a current problem and i need a quick method to solve it, then i go into my ui and try to implement a piece of code which does it for me. therfore i decided not to use it as Alibre Plugin, so i can add buttons quicker and implement some code. I know this is not professional coding but helps a lot.



Example for GearWheel:

View attachment 38190

I understand why you chose not to use the Alibre Add-on. It is not easy to use partly because the documentation is so poor. If you do decide to go down the Add-on route in the future, when using C# you MUST declare '<DLL type="Managed"' in the .adc file. this is not detailed in the documentation.

I'd be really interested to see your gear generation code. From the screenshot, I guess that your sketch is of the full gear and not just a single tooth. I originally sketched the full gear but found this inefficient when developing gears with more than about 50 teeth. I changed this to use a template file with a single tooth extruded and then using a circular pattern. The helical gear solution I used also uses a circular pattern but after a helical boss extrude.

I'm actually thinking about developing code for bevel gears now but want to do this in a reworked application.

Screenshot 2022-12-30 191450.png

David
 

albie0803

Alibre Super User
Hello David,
Referring to your screen above, what do you mean by Profile Shift? Can you please describe what it does? Also, backlash should be able to be assigned separately to both gears. Designers often have "reasons" to play with the backlash. We are currently producing new sun and planetary gears in a different ratio and the planetary gears have all the backlash and the sungear has none, as per the original set.
 
I understand why you chose not to use the Alibre Add-on. It is not easy to use partly because the documentation is so poor. If you do decide to go down the Add-on route in the future, when using C# you MUST declare '<DLL type="Managed"' in the .adc file. this is not detailed in the documentation.

I'd be really interested to see your gear generation code. From the screenshot, I guess that your sketch is of the full gear and not just a single tooth. I originally sketched the full gear but found this inefficient when developing gears with more than about 50 teeth. I changed this to use a template file with a single tooth extruded and then using a circular pattern. The helical gear solution I used also uses a circular pattern but after a helical boss extrude.

I'm actually thinking about developing code for bevel gears now but want to do this in a reworked application.

View attachment 38193

David

AddOn:
Thanks for the hint with managed flag. I think if i go the way with AddOn i will introduce a product to sell :-D
But also i think a good idea could be to create a new project on github or so where a AlibreAddOn Builder / Assistant / Wizard will be delivered. A nice Idea could be to have a tool which creates a new visual studio solution with all includes and also generates the adc file, a folder stucture and the UUID for the AddOn. Then base classes are included and finally an UserAddOn Class exist where you can start to implement your own code. This would be nice, but my deepdive in addons is much to less. With your knowledge about Alibre AddOn this should be possible to do in a easy way.

GearTooth:
I only sketch one tooth in the sketch, but Pattern tools didn't work when i developed this, so i build my own pattern tool for sketches and do the pattern direct in the sketch. So i must not draw every tooth by myself, only one. The features you introduced with the geartool seems amazing. I have a idea an want to test if some changes in code lead to the same result ;-)
Target was to create a tool for generation of planetary gearboxes. But i had respect on innergearwheels.

It also works for 200 Teeth, Modul 0,5 but performance is poor, and Linear Approx could be possible instead of Splines:
1672483999668.png

My next steps would be beltpulleys but, currently there is no need. And i think an nativ CAM Tool is so much more exciting to do. Because then 3D-Machining is possible and i love the topic.
Maybe a nice small product for a few bucks fells out and some makers on native 3-Axis-Mills will have some fun. But this is all future.
 
Last edited:

bolsover

Senior Member
Hello David,
Referring to your screen above, what do you mean by Profile Shift? Can you please describe what it does? Also, backlash should be able to be assigned separately to both gears. Designers often have "reasons" to play with the backlash. We are currently producing new sun and planetary gears in a different ratio and the planetary gears have all the backlash and the sungear has none, as per the original set.

Profile shift.
This is essentially the equivalent of moving the hobbing tool closer to or further from the gear centre. If there is a negative shift, gears with lower tooth counts are more liable to undercutting at the tooth root. A profile shift moves the pitch circle of the gear away form the 'normal' position. Profile shifting is usually used to counter the impact of changing the 'standard' centre distance.

Backlash
I need to do some more work on this; I'm not convinced my tool is working correctly in all cases.

General
I've been using this document as my primary source of information:
Elements of Metric Gear Technology.
 

albie0803

Alibre Super User
Profile Shift - We refer to this as over or undersizing a gear and measure it as a change to the gear OD.
I also think (but I will check when I go back to work next week) that the Pitch circle never changes, you are actually changing the addendum and dedendum values and working higher or lower on the involute curve. This is why oversized gears tend to get pointy.
 

bolsover

Senior Member
Profile Shift - We refer to this as over or undersizing a gear and measure it as a change to the gear OD.
I also think (but I will check when I go back to work next week) that the Pitch circle never changes, you are actually changing the addendum and dedendum values and working higher or lower on the involute curve. This is why oversized gears tend to get pointy.
Yes - you are quite correct about the pitch circle not changing.. Don't know why said that ... must have been having a 'senior moment'
When developing the add-on, I was in two minds about how to implement. Either: 1 calculate the standard centre distance of a gear pair and allow the user to override with a specified working centre distance and then calculate the profile shift needed. Or, 2 allow the user to enter over/undersize values (profile shift) and then calculate the working centre distance. It isn't really practical to do both as there are so many interdependent calculations. I opted for 1 because it seemed the more logical but it does leave the user to decide on how to distribute the profile shift between the two gears.
I've not looked the project for a few weeks, being too busy with the pagan rituals associated with this time of year.
I might ask for some assistance sometime - the thing I struggle with more than anything is obtaining known good calculations against which to validate my own numbers.
Things I'd like to do..
Generate correct trochoidal tooth root profiles.
Generate bevel gears,
Generate worm gears.

Have an excellent Year ahead.

David
 
Top