Manufacturing DevBlog: April 2013

Manufacturing DevBlog: April 2013 Manufacturing DevBlog The resource for software developers working with Design, Lifecycle and Simulation technologies from Autodesk. Home Subscribe Follow Useful Links Autodesk About this Blog « March 2013 | Main | May 2013 » April 2013 04/30/2013 Check Geometry type in C++ By Adam Nagy In case of Geometry objects you do not have the Type/ObjectType properties that you could check the type with. Instead you can use Windows API functionality to find information about that. In this sample we'll use the QueryInterface function (could use CComQIPtr<> as well) and ITypeInfo to get the type name of the object. // Check type using QueryInterface // In VB this would be "TypeOf x Is y" static void CheckType(CComPtr<IDispatch> geom) {   void * ptr;     if (SUCCEEDED(     geom->QueryInterface(__uuidof(LineSegment), &ptr)))     MessageBox(NULL, _T("LineSegment"), _T("Type Info"), MB_OK);   else if (     SUCCEEDED(geom->QueryInterface(__uuidof(Circle), &ptr)))     MessageBox(NULL, _T("Circle"), _T("Type Info"), MB_OK);   else     MessageBox(NULL, _T("Unknown type"), _T("Type Info"), MB_OK); }   // Get the type name // In VB this would be "TypeName" static void ShowTypeName(CComPtr<IDispatch> geom) {   ITypeInfo * info;   geom->GetTypeInfo(0, 0, &info);     BSTR name, doc, help;   DWORD context = -1;   info->GetDocumentation(-1, &name, &doc, &context, &help);      MessageBox(NULL, name, _T("Type Name"), MB_OK); }   static void TypeCheckTest(CComPtr<Application> app) {   CComQIPtr<PartDocument> doc = app->ActiveDocument;     CComPtr<IDispatch> geom =     doc->ComponentDefinition->SurfaceBodies->     Item[1]->Edges->Item[1]->Geometry;     ShowTypeName(geom);     CheckType(geom); }  Posted at 05:13 AM in Adam Nagy , Inventor | Permalink | Comments (0) | | | 04/26/2013 Get BrowserNode of an occurrence By Adam Nagy There is a function for exactly this purpose called GetBrowserNodeFromObject, but unfortunately, it seems that it does not always return the correct BrowserNode object. E.g. in case of an occurrence which is part of a pattern feature, it would return a BrowserNode object which seems like some internal object. And so if you try to call EnsureVisible() on it, then Inventor will throw an error.  If you run into such a situation then you could find the correct node using the following code:  public BrowserNode findNode(   BrowserNode node, ComponentOccurrence occ) {   // Use try/catch because the node may not have a NativeObject   // and would throw an exception here   try   {     if (node.NativeObject == occ)       return node;   }   catch { }     foreach (BrowserNode subNode in node.BrowserNodes)   {     BrowserNode returned = findNode(subNode, occ);     if (returned != null)       return returned;   }     return null; }   private void SelectNode(   AssemblyDocument oDoc, ComponentOccurrence occ) {   // Get The Browser Pane by BrowserInternalName   BrowserPane browserPane =     oDoc.BrowserPanes["AmBrowserArrangement"];     BrowserNode occNode = findNode(browserPane.TopNode, occ);       // Select node   occNode.EnsureVisible();     // EnsureVisible seems to highlight it   // so this is probably not needed   occNode.DoSelect(); }   Posted at 08:42 AM in Adam Nagy , Inventor | Permalink | Comments (0) | | | 04/23/2013 Call iLogic from .NET By Xiaodong Liang iLogic has been widely used nowadays. Sometimes, to achieve some requirements, we need to combine Inventor API and iLogic, e.g. call a rule from an addin. The interfaces for iLogic exists with <Inventor Installation Path>\bin\Autodesk.iLogic.Automation.dll and Autodesk.iLogic.Interfaces.dll. The iLogicAutomation is the entrance of iLogic. The following is a small demo on how to dump all rules of the current document and execute one rule. void _buttonDef1_OnExecute(NameValueMap Context) {     //iLogic is also an addin which has its guid     string iLogicAddinGuid = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}";       Inventor.ApplicationAddIn addin = null;     try     {         // try to get iLogic addin         addin =                 m_inventorApplication.ApplicationAddIns.get_ItemById(iLogicAddinGuid);     }     catch     {         // any error...     }       if (addin != null)     {         // activate the addin         if (!addin.Activated)             addin.Activate();           // entrance of iLogic         Autodesk.iLogic.Automation.iLogicAutomation _iLogicAutomation =             (Autodesk.iLogic.Automation.iLogicAutomation)addin.Automation;           Document oCurrentDoc = m_inventorApplication.ActiveDocument;           Autodesk.iLogic.Interfaces.iLogicRule myRule = null;         //dump all rules         foreach (Autodesk.iLogic.Interfaces.iLogicRule eachRule in _iLogicAutomation.get_Rules(oCurrentDoc))         {             if (eachRule.Name == "MyRule")             {                 myRule = eachRule;                 //list the code of rule to the list box                 MessageBox.Show( myRule.Text);                 break;