Moving a suppressed part feature node always fails

Moving a suppressed part feature node always fails

dylanTEV9W
Advocate Advocate
372 Views
2 Replies
Message 1 of 3

Moving a suppressed part feature node always fails

dylanTEV9W
Advocate
Advocate

Hello all I'm getting an error when ever I try to run code that moves a suppressed part features node above the End of part node. I've created some simplified C# code of what I'm doing that reproduces the error on the attached test part. 

 

void Test()
{
//For this to run "correctly" a part document must be open with a supressed extrude feature named "Extrusion1"
//placed below the End of Part node.

 

try //Try to access and move the extrude feature node above the end of part node.
{
PartDocument part_doc = (PartDocument)inventor_application.ActiveDocument; //Access the part doc

 

BrowserPane model_pane = part_doc.BrowserPanes["Model"];//Access the model pane via the part part document.

 

BrowserNode EndNode = model_pane.TopNode.BrowserNodes["End of Part"]; //Access the end of part node.

 

BrowserNode feature_node = model_pane.TopNode.BrowserNodes["Extrusion1"]; //Access the extrude feature node.

 

model_pane.Reorder(EndNode, true, feature_node); //Move the extrude features node.

 

Debug.Print("Succeeded in moving the extrude feature");
}


catch
{
Debug.Print("Failed to move extrude feature");
}

//Run this again with the part unsupressed but below the End of Part node.
}

 

Any help or insites you can offer would be greatly appreciated!

0 Likes
Accepted solutions (1)
373 Views
2 Replies
Replies (2)
Message 2 of 3

HideoYamada
Advisor
Advisor
Accepted solution

Hello dylanTEV9W,

 

This problem is due to the node name change.

 

Change the line follows

// BrowserNode feature_node = model_pane.TopNode.BrowserNodes["Extrusion1"];
BrowserNode feature_node = model_pane.TopNode.BrowserNodes["Extrusion1 (Suppressed)"];

Node name will be changed unexpectedly.

For example, "Display extended information" option causes change of the node names.

AppOption.PNG

In fact, I usually turn this option on, so it took me a while to determine why the code didn't work anyway.

 

It is better to see BrowserNode.NativeObject, but note that accessing BrowserNode.NativeObject may throw an exception.

 

You must guard from an exception as follows :

BrowserNode node;

...

object nativeObject = null;
try {
    nativeObject = node.NativeObject;
} catch {}
if (nativeObject != null) {
    ....

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 3

dylanTEV9W
Advocate
Advocate

Thanks for the help!

 

 

P.S. Just a note to any Autodesk devs out there. Seems to me like suppressing a feature shouldn't have the side effect of changing its associated nodes name. It forces those of use writing customizations to add extra logic to our programs to check and account for suppressed features when moving nodes around. 

0 Likes