Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Get mesh surface data

#1
Is there a way to get the mesh geometry for a surface using the C# API? I want to use it to bound a path I generate. GetPoints seems to work with a solid using HoverObjectMesh, but if I try it on a surface it fails to recognise it. Also, I don't really want what is under the cursor, I want to specify the IItem. 

I have attached example step files - sorry, not a full station at this time.


Attached Files
.step   1000x1000x100_convex.step (Size: 9.09 KB / Downloads: 22)
.step   curvedSurface.step (Size: 8.43 KB / Downloads: 22)
#2
You can get the mesh of the selected object or item under the mouse cursor as shown in this example:
https://robodk.com/doc/en/PythonAPI/robo....GetPoints

You may need to implement this example in C# if you prefer using C#.
#3
Thanks, with that approach I can get the surface coordinates from the step file surface I was failing on before, but it is a bit indirect - I'm confused why GetPoints works under this condition:

Code:
        IItem? testObject;
        Mat? pointList;
        ObjectSelectionType type;
        int featureId;

        while (true)
        {
            var result = RdkService.Rdk.GetPoints(ObjectSelectionType.HoverObjectMesh);
            testObject = result.Object;

            if (testObject is null || !testObject.Valid())
                continue;
               
            _ = testObject.SelectedFeature(out type, out featureId);

            if (type is ObjectSelectionType.Surface)
            {
                testObject.GetPoints(ObjectSelectionType.Mesh, featureId, out pointList);
                break;
            }
        }

...but this doesn't work:

Code:
        IItem testObject = RdkService.Rdk.GetItemByName("curvedSurface");
        if (!testObject.Valid())
            return;

        Mat pointList = new Mat(0, 0);
        ObjectSelectionType type;
        int featureId;

        _ = testObject.SelectedFeature(out type, out featureId);

        if (type is ObjectSelectionType.Surface)
        {
            testObject.GetPoints(ObjectSelectionType.Mesh, featureId, out pointList);
        }

Is the IItem in GetPointsResult somehow not the same as getting the IItem directly? The ItemId is the same, and I'm using the same FeatureId and ObjectSelectionType. I would like to avoid the user selecting through the 3D view.
#4
Just to add, I sort of understand now this is related to the selection engine. I've not managed to make selecting the part/feature through the API directly work, but for my isolated surfaces a brute force featureId search on the IItem yielded by ItemUserPick/etc. does work...albeit a lot of API calls, and therefore slow.
#5
If you need the full mesh of the object, one option is to save the object and perform your operations using the 3D model separately.

What are you trying to accomplish? Maybe we can help you better.
#6
I'm generating paths that are a bit fussy, like covering an area with sealant in a clever way to avoid trapping air, so typical canned cycles are problematic.

My path generation is currently fairly efficient, so I can somewhat tolerate looping over the hover selection input and give the user a nice preview of the provisional path as the selection changes under the cursor, but it won't always be the case, and capturing keystrokes to exit the loop can be a bit hit and miss. Having to get the cursor to the desired selection is a bit fraught in a busy station, and it's often not the first incident valid selection that is desired - a more positive selection such as by mouse click or from a list of objects is better. I know there are rdk events, but this again seems over-complicated for what should be a simple item/feature selection.

It's nice to be able to grab the geometry through the API, but I take your point about saving the object out of the station.
#7
I recommend you to import 3D models in STEP or IGES format (parametric). This way you can obtain clean shapes of what you are selecting.

You can also customize the quality of imported parametric 3D files in the menu Tools-Options-CAM. I recommend you to set the linear accurac of the mesh to 0.2 mm for better accuracy (default is 1 mm).

What do you mean by capturing keystrokes to exit the loop?
#8
Thanks - I'm importing as parametric STEP, but is it possible to use the API save to save as STEP? It seems to only want to output STLs. To be honest, the STLs are probably adequate, and what I'm currently using. I've bumped up my CAD accuracy settings 👍

I was alluding to how to get out of the sort of selection loop needed with hover selection, but I'm not using hover select any more. Picking up on keystrokes from the C#/.NET mostly works, but when it isn't 100% it quickly gets frustrating for the user (using the threadpool and cancellation tokens/etc. is a bit of a faff and still not 100% robust I find - and lots of code for a simple task). Selecting tree items from a combobox in my form is much more forgiving of performance-related issues, though limited to items and not faces.
  




Users browsing this thread:
1 Guest(s)