Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Promote Wires works in VB.net but not in C#

2 REPLIES 2
Reply
Message 1 of 3
dmdixit
364 Views, 2 Replies

Promote Wires works in VB.net but not in C#

Hi

Through addin I am importing a SAT file which has wire entities then using promote wire command putting them into a 3dsketch. Below are the code blocks in VB.net and C#. While the VB.net code works the C# doesnt. Is there something I am missing or doing wrong here?

Thanks in advance
regards
Dhananjay

VB.net
{code}
public function PromoteWires(ByVal oInventorApp As Inventor.Application,byval oPartDoc As PartDocument) as Boolean

Try
' Get the top browser node of the model pane.
Dim oTopBrowserNode As BrowserNode
oTopBrowserNode = oPartDoc.BrowserPanes.ActivePane.TopNode

Dim oRequiredNode As BrowserNode

oRequiredNode = recurseNodes(oTopBrowserNode, "Wires")
oRequiredNode.DoSelect

Dim oCommandMgr As CommandManager
oCommandMgr = oInventorApp.CommandManager

' Get control definition for the line command.
Dim oControlDef As ControlDefinition

oControlDef = oCommandMgr.ControlDefinitions.Item( _
"PartConstructionPromoteWireCtxCmd")
oControlDef.Execute
return true
Catch Ex As Exception
return False
End Try

End function


private Function recurseNodes(oTopNode As BrowserNode, ByVal strWantedNode As String) As BrowserNode

Try

recurseNodes = Nothing

If InStr(1, oTopNode.FullPath, strWantedNode) > 0 Then
recurseNodes = oTopNode
Else
Dim oBN As BrowserNode
If oTopNode.BrowserNodes.Count <> 0 Then
For Each oBN In oTopNode.BrowserNodes
recurseNodes = recurseNodes(oBN, strWantedNode)
If Not recurseNodes Is Nothing Then
Exit For
End If
Next
Else
recurseNodes = Nothing
End If
End If
Catch Ex As Exception
recurseNodes = Nothing
End Try
End Function
{code}

C#
{code}
private void PromoteWires()
{
PartDocument oPartDoc = null;
foreach (Inventor.Document ODoc in m_inventorApplication.Documents)
{
if ((ODoc.DocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject) && (ODoc.DisplayName != oPartDocument.DisplayName))
{
oPartDoc = (Inventor.PartDocument)ODoc;
break;
}

}
oPartDoc.Activate();
//oPartDoc = m_inventorApplication.ActiveDocument;
// Get the top browser node of the model pane.
BrowserNode oTopBrowserNode;
oTopBrowserNode = oPartDoc.BrowserPanes.ActivePane.TopNode;
BrowserNode oRequiredNode;
oRequiredNode = recurseNodes(oTopBrowserNode, "Wires");
oRequiredNode.DoSelect();
CommandManager oCommandMgr;
oCommandMgr = m_inventorApplication.CommandManager;
// Get control definition for the line command.
ControlDefinition oControlDef;
oControlDef = oCommandMgr.ControlDefinitions["PartConstructionPromoteWireCtxCmd"];
oControlDef.Execute();
}

private BrowserNode recurseNodes(BrowserNode oTopNode, String strWantedNode)
{
BrowserNode tempnode = null;
if (oTopNode.FullPath.Contains(strWantedNode))
{
tempnode = oTopNode;
}

else
{
BrowserNode oBN = null;
if (oTopNode.BrowserNodes.Count != 0)
{
foreach (BrowserNode oBN1 in oTopNode.BrowserNodes)
{
oBN = oBN1;
tempnode = recurseNodes(oBN, strWantedNode);

if (!(tempnode == null))
{
break;
}

}
}

else
{
tempnode = null;
}

}
return tempnode;

}
{code}
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: dmdixit

When I reduced your C# code to be the same as the VB.Net code it worked
fine. It appears the problem is the section of code in the C# example
that's getting the part document. You need to double-check your logic
there. Here's my modified version that works fine.

private void PromoteWires(Inventor.Application invApp,
Inventor.PartDocument partDoc)
{
// Get the top browser node of the model pane.
BrowserNode oTopBrowserNode;
oTopBrowserNode = partDoc.BrowserPanes.ActivePane.TopNode;

BrowserNode oRequiredNode;

oRequiredNode = recurseNodes(oTopBrowserNode, "Wires");
oRequiredNode.DoSelect();

CommandManager oCommandMgr;
oCommandMgr = invApp.CommandManager;

// Get control definition for the line command.
ControlDefinition oControlDef;

oControlDef =
oCommandMgr.ControlDefinitions["PartConstructionPromoteWireCtxCmd"];
oControlDef.Execute();
}


--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 3 of 3
ajinkya.shivarkar
in reply to: dmdixit

Hi Brian,

Thank you for your reply!
Please find the attached AddIn project where I have modified the code as per your suggestion, but it is still not working.

Could you please let me know id I'm missing something.

Thanks & Regards,
Ajinkya

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report