Geometry Primitive returns multiple objects

Geometry Primitive returns multiple objects

Anonymous
Not applicable
3,257 Views
8 Replies
Message 1 of 9

Geometry Primitive returns multiple objects

Anonymous
Not applicable

Hi,

 

I am extracting primitives of the clicked modelitem to get points, edges, faces.

This works most of the time, but for some items the collection of fragments is not for the clicked item only, it is for multiple independant items in the tree. Is there a way to check the fragments are from the same object?

 

I am using this very simple code:

 

        Dim Itm As ModelItem = Autodesk.Navisworks.Api.Application.
            ActiveDocument.CurrentSelection.SelectedItems(0)

        Dim ItmPath As InwOaPath =
            ComApi.ComApiBridge.ToInwOaPath(Itm)

        For Each frag As InwOaFragment3 In ItmPath.Fragments 'this collection contains fragments from multiple items
            frag.GenerateSimplePrimitives(nwEVertexProperty.eNORMAL, Me)
            'Me is a class that implements InwSimplePrimitivesCB
        Next

 

In the picture below, if I try to extract the geometry for any of the selected item (in blue), it returns the fragments for all of them.

If I click any other item, it returns the fragments for the clicked object only...

 

 

Picture1.png

 

Cheers,

Nic

0 Likes
Accepted solutions (1)
3,258 Views
8 Replies
Replies (8)
Message 2 of 9

xiaodong_liang
Autodesk Support
Autodesk Support
Accepted solution
Hi Nic,

I found this is actually an issue I have logged in the previous release: NW #14187. However it looks to me this is as designed.

behind the behavior: because the Fragments() function is getting hold of the node at the tail of the path, and then asking for the fragments for the node. This actually returns all the fragments for all instances of that node, so you get multi-fragments, not one.

I have not a good way to solve, but you could try to get parent of the selected item (assume it is the geometry node), and dump the fragments.

I will also check with our engineer team about #14187
0 Likes
Message 3 of 9

Anonymous
Not applicable

Sweet that fixed it. I suspected it had to do with instances.

I actually had to go higher in the tree, the first parent was still returning multiple instances.

so the very simple solution:

 

        While _Item.Instances.Count > 1
            _Item = _Item.Parent
        End While

        Dim Path As InwOaPath =
            ComApi.ComApiBridge.ToInwOaPath(_Item)

        For Each frag As InwOaFragment3 In Path.Fragments
            ...
        Next

thanks again,

 

Nic

 

0 Likes
Message 4 of 9

xiaodong_liang
Autodesk Support
Autodesk Support
Hi Nic,

I was trying to look at if it is necessary to check with our engineer team about that issue, though it is more as designed to me. I suddenly found I have figured out a better solution and wrote a blog in 2012:
http://adndevblog.typepad.com/aec/2012/08/geometry-fragment-returns-all-instances-when-a-multiply-in...
how bad my memory is! I even forgot it 🙂
could you take a look if it can help you?
Message 5 of 9

Anonymous
Not applicable

Interesting, I can see how your solution would be more robust if a multi instance node has more than one child. In this case the code I posted would return the fragments for all children.

Never ran into such a case before though, so I'll stick with my lazy approach for now (less lines of codes), but will keep yours in mind, thanks.

 

I'd also be interested to see which option is more performant, because in your case if there is a large number of instances, you potentially check all their paths... again probably an edge scenario.

0 Likes
Message 6 of 9

xiaodong_liang
Autodesk Support
Autodesk Support
I did not compare the performance, but I think the latter solution simply also checks the fragments that are selected only. those ArrayData information are stored with these fragments. So it is not to recurs the whole model, so it would not be affected by model size.

or course, the algorithm of checking ArrayData might not be so nice. there should be better way.

if you find any tremendous performance difference, please share with us. Thank you.
0 Likes
Message 7 of 9

Anonymous
Not applicable

Dear support,

 

Thank you for this workaround, I've integrated additional lines of code in my plugin and that fixes the problem : I can now parse only the fragments attached to a single instance of one ModelItem and no more all the fragments of all other instances, as it was the case before.

 

But is there now (NW API 2018) a proper way to access only the fragments attached to a single instance of one ModelItem ? Because this test is not optimal (i.e. systematically checking the path of each fragment with the path of current instance of ModelItem).

 

Thank you for your answer,

 

Christophe Montandon.

Message 8 of 9

pkramesh
Contributor
Contributor

Is this discussion still on?

I could not resolve this " 

'Me is a class that implements InwSimplePrimitivesCB"
Can anyone help.
0 Likes
Message 9 of 9

gokulprasath
Participant
Participant

 

Great, Could you please share more details on the updated code, if possible?

 

Best regards

0 Likes