Autodesk iLogic

fachrl

Newbie
Registriert
Aug. 2022
Beiträge
5
Hallo zusammen,

ich programmiere in C# und versuche damit eine iLogic Regel in Autodesk Inventor anzusteuern. Leider erzeugt die Regelsuche einen Fehler und läuft direkt in den catch. Kennt sich jemand damit aus und kann mir behilflich sein?

Vielen Dank im Voraus

try
{
Inventor.Application invApplication = ThisApplication;
Document targetDocument = ThisApplication.ActiveDocument;

// iLogic-Modul in Inventor instanzieren
Inventor.ApplicationAddIn iLogicAddIn = invApplication.ApplicationAddIns.get_ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}");
iLogicAddIn.Activate();
dynamic iLogicAutomation = iLogicAddIn.Automation;

// Name der Regel
string ruleName = "Varianten";

// Existiert die Regel?
bool ruleExists = false;
try
{
foreach (Autodesk.iLogic.Interfaces.iLogicRule iLogicRule in iLogicAutomation.get_Rules(targetDocument))
{

if (iLogicRule.Name == ruleName)
{
ruleExists = true;
}
}
}
catch
{
//file does not contain rule
}
 
fachrl schrieb:
läuft direkt in den catch
Vorab ich hab keine Ahnung von Autodesk iLogic, aber:

Mit welcher Exception bricht dein Code ab?
Dein Catch ist im Moment so mehr oder weniger nutzlos. Es verhindert nur, dass dein Programm abstürzt.
Du weisst aber nicht, warum deine Funktion in's Catch läuft. Deswegen fängt man normalerweise die Exception ab.
Hier mal als ganz vereinfachtes Beispiel:
C#:
try
{
    //Dein Code
}
catch (Exception ex)
{
    //Was auch immer du mit der Excception anfangen willst.
    //z.B. für anwenugen mit GUI
    Messagebox.show(ex);
    //oder Console:
    Console.WriteLine(ex);
}

Ausserdem kann dein Code, so wie du ihn hier gepostest hast nicht funktionieren.
Du hast nur eine Catch für 2 Try.

Und Schreib deinen Code hier im Forum am Besten in Code Tags, damit der besser lesbar ist.
 
Zuletzt bearbeitet:
Ja gut. Das ist ja schonmal ein Anfang.
Der Fehler gibt an, dass es kein get_Rules in iLogicAutomation gibt.
Siehe auch:
https://docs.microsoft.com/de-de/dotnet/csharp/language-reference/compiler-messages/cs1061
Wie geschrieben, ich kenn mich iLogic nicht aus. Aber beim Googlen nach "iLogicAutomation.get_Rules" bin ich da drauf gestoßen (War das 3. Suchergebnis...)
In den Beitrag hat jemand genau den gleichen Fehler:
Autodesk Forum

Und nur ein paar Beiträge (Beitrag 7) später steht, dass man statt
C#:
iLogicAutomation.get_Rules(targetDocument)
C#:
iLogicAutomation.Rules(inventorApp.ActiveDocument))
benutzen soll.
Sogar mit Beispiel.
 
  • Gefällt mir
Reaktionen: proserpinus und Drexel
danke für die Hilfe, Das hat auf jeden Fall geholfen. Nun habe ich allerdings eine weitere Fehlermeldung, wo ich nicht ganz weiter komme

1659692936530.png
 
try
{
Inventor.Application invApplication = ThisApplication;
AssemblyDocument targetDocument = (AssemblyDocument)ThisApplication.ActiveDocument;

// iLogic-Modul in Inventor instanzieren
Inventor.ApplicationAddIn iLogicAddIn = invApplication.ApplicationAddIns.get_ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}");
iLogicAddIn.Activate();
dynamic iLogicAutomation = iLogicAddIn.Automation;

// Name der Regel
string ruleName = "Varianten";

// Existiert die Regel?
bool ruleExists = false;
try
{
foreach (Autodesk.iLogic.Interfaces.iLogicRule iLogicRule in iLogicAutomation.Rules(invApplication.ActiveDocument))
{
if (iLogicRule.Name == ruleName)
{
ruleExists = true;
}
}
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
 
Bitte in Code Tags...

C#:
try
{
    Inventor.Application invApplication = ThisApplication;
    AssemblyDocument targetDocument = (AssemblyDocument)ThisApplication.ActiveDocument;

    // iLogic-Modul in Inventor instanzieren
    Inventor.ApplicationAddIn iLogicAddIn = invApplication.ApplicationAddIns.get_ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}");
    iLogicAddIn.Activate();
    dynamic iLogicAutomation = iLogicAddIn.Automation;

    // Name der Regel
    string ruleName = "Varianten";

    // Existiert die Regel?
    bool ruleExists = false;
    try
    {
        foreach (object iLogicRule in iLogicAutomation.Rules(invApplication.ActiveDocument))
        {
            MessageBox.Show(typeof(iLogicRule));
        }

    }
    catch(Exception e)
    {
        MessageBox.Show(e.Message);
    }
}

Wäre Mal ein erster Ansatz. Gibt es keine Dokumentation zu der API?
 
Zuletzt bearbeitet:
Ne leider nicht, aber vielen Dank für das Beispiel. So funktionierts!
 
So funktioniert was? So sollte wer erstmal ne Typ Info ausgeben, anhand der man schauen kommt was da wirklich kommt und was man evtl damit machen kann...
 
Zurück
Oben