Conversion between iLogic and VBA

Conversion between iLogic and VBA

Anonymous
Not applicable
3,892 Views
10 Replies
Message 1 of 11

Conversion between iLogic and VBA

Anonymous
Not applicable

Hi all, 

I got a problem. I already study about iLogic for a peroid of time.

So now, my boss want me to do small project in Macro using VBA.

 

Personally, an iLogic function is an abbreviation of VBA codes.

 

Therefore, something I can do in iLogic, but I don't know how to do in VBA?????????????????

How to declare, how to set, what function I need to use???????

 

Could anywhere have the conversion between iLogic and VBA codes?????

Please show me!!!!!!!

 

Thank you a lot!

0 Likes
Accepted solutions (1)
3,893 Views
10 Replies
Replies (10)
Message 2 of 11

MjDeck
Autodesk
Autodesk

Have you looked at the API documentation?  You can get to it from the Help menu:

Help -> Additional Resources -> Programming Help

It has many VBA samples.

If you can post a sample rule, I might be able to suggest how it could be converted to VBA.

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 11

Anonymous
Not applicable

For instance,

Today, I write an iLogic code for get the value in Excel worksheet,

i = GoExcel.FindRow("CONFIGURATION.xlsx", oMount, "BORE", "=",DIM_BORE, "MM", "=", DIM_MM)
Select Case oMount
Case "MP5"
A = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "D"&i)
XO = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "L"&i)
SC = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "P"&i)
TL = A + XO + SC + UP_STROKE
Case "MF3"
A = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "D"&i)
ZB = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "L"&i)
TL = A + ZB + UP_STROKE
Case "MF4"
A = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "D"&i)
ZP = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "L"&i)
TL = A + ZP + UP_STROKE
Case "MT4"
A = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "E"&i)
ZB = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "M"&i)
TL = A + ZB + UP_STROKE
Case "MS2"
A = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "E"&i)
ZJ = GoExcel.CellValue("CONFIGURATION.xlsx", oMount, "M"&i)
TL = A + ZJ + UP_STROKE
End Select
messagebox.Show("Total Length = " & TL, "Total Length of Part")

What I need to do to write a code that has the same function as upper in VBA

How to connect to Excel? How to find value like in iLogic?????

I wish Autodesk will give a conversion between iLogic functions and VBA codes...........

 

 

0 Likes
Message 4 of 11

MjDeck
Autodesk
Autodesk

That rule will require a significant amount of work to convert to VBA.  Autodesk doesn't have an automated converter.

Why do you want to convert it to VBA?

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 11

Anonymous
Not applicable

My college has create an macro in User Form that can change the Size and Shape of Part in model.

My job now is continue the process that create the drawing for this part (an kind of iPart but more complex).

My college use Access database in VBA to get the value for model, but I don't know how ( I just self study in Macro and have very little knowledge in programming).

So I type all tables into Excel file. Now every parameter in the table, about 10 sheet with hundreds cells.........

 

So I want to get the cell of Excel worksheet in some rules for example:

 

 

First, find the column for the value "M4" in the row 1; the result is Column E

then, find the row for the value "N10" in the column A; the result is Row 11

Then the cell value will be E11; value = 6

 

What I need to do? What material I need to study??????

 

I think maybe it can have a similiar structure as Inventor API:

Excel Application>>>>>>ExcelDocument>>>>>>>Sheet>>>>>>>CellValue(row,column)

 

However, I try a lot, but nothing happens.

 

Many thanks in advance!

0 Likes
Message 6 of 11

Anonymous
Not applicable

The biggest difference between VBA and VB.NET is that in VB.NET (or iLogic) everything is an obect.

VBA has objects also in addition to built in datatypes that are not objects.  Because of this VBA requires you to use

"Set" when setting objects.  For instance.

 

--- VBA ---

Dim oDoc as Inventor.Document

Set oDoc = ThisApplication.ActiveDocument.

 

---VB.NET---

Dim oDoc as Inventor.Document = ThisApplication.ActiveDocument

 

Note also that above in VB.Net you can declare and set a variablle all on the same line.  Not so in VBA.

 

In the VBA IDE (Code Editor) Main Menu select "Help"
Then "Microsoft Visual Basic Help"
Then the "Contents" tab.
Click "Visual Basic Language Reference" for listings of functions and statements.

 

You use these instead of the meithods found under VB.NET objects.

 

The API is pretty much the same in Both.  iLogic appears to be a subset of the full Inventor API.

The only difference using it is that you may have to use the Variant data type for some parameters  in VBA versus Objects in VB.NET.

 

There are a lot of tutorials and forums out there for VB6 / VBA.  XtremeVBTalk.com comes to mind.

 

[Edit]  Yikes!  Looks like a lot of water went under the bridge while I was composing this message. [/Edit]

 

 

As MjDeck says there is a lot to know to automate Excel from VB6 / VBA / VB.NET.

The web forum I mentioned above has areas specifically dedicated to helping you wrap you head around exactly that topic.

 

0 Likes
Message 7 of 11

Anonymous
Not applicable

I agree with what you said.

I just go to Thailand to work in a few months, and my computer haven't been installed VB.NET yet. With VB.NET and MSDN, I can self study better than only VBA............of course.......

I hope that I could find out the solution from your website.

 

I hope that tomorow I can find out the solution........

Then tomorrow we can have some more discussions. (12PM now---->sleeping)

0 Likes
Message 8 of 11

MjDeck
Autodesk
Autodesk

 It should be possible to add drawing-creation code to the existing VBA code (which use an Access database).  That might be easier than converting the iLogic rule to VBA.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 9 of 11

Anonymous
Not applicable
Accepted solution

I got the solution.........I write this in VBA

    
    'open Excel
    Dim oExcel As Excel.Application
    Set oExcel = New Excel.Application
   
    'Open the OLE excel file
    Dim oWorkbook As Excel.Workbook
    Set oWorkbook = oExcel.Workbooks.Open(ThisApplication.FileLocations.Workspace & "\" & "CONFIGURATION.xlsx")
   
    'Get the sheet oMount
    Dim oWorkSheet As WorkSheet
    Set oWorkSheet = oWorkbook.Sheets.Item(i)
   
    oExcel.Visible = False

    For x = 2 To 19 Step 1
        For y = 2 To 19 Step 1
            If (oWorkSheet.Cells(x, 1) = BORE) And (oWorkSheet.Cells(y, 2) = MM) Then
                If x = y Then
                    z = x
                End If
            End If
        Next
    Next

    Select Case oMount
        Case "MP5"
            A = oWorkSheet.Cells(z, 4)
            XO = oWorkSheet.Cells(z, 12)
            SC = oWorkSheet.Cells(z, 16)
            TotalL = A + XO + SC + UPSTROKE
           
            D = oWorkSheet.Cells(z, 6)
            TotalW = D
        Case "MF3"
            A = oWorkSheet.Cells(z, 4)
            ZB = oWorkSheet.Cells(z, 12)
            TotalL = A + ZB + UPSTROKE
           
            UC = oWorkSheet.Cells(z, 16)
            TotalW = UC
        Case "MF4"
            A = oWorkSheet.Cells(z, 4)
            ZP = oWorkSheet.Cells(z, 12)
            TotalL = A + ZP + UPSTROKE
           
            UC = oWorkSheet.Cells(z, 16)
            TotalW = UC
        Case "MT4"
            A = oWorkSheet.Cells(z, 5)
            ZB = oWorkSheet.Cells(z, 13)
            TotalL = A + ZB + UPSTROKE
           
            TM = oWorkSheet.Cells(z, 20)
            TL = oWorkSheet.Cells(z, 19)
            TotalW = TM + TL * 2
        Case "MS2"
            A = oWorkSheet.Cells(z, 5)
            ZJ = oWorkSheet.Cells(z, 13)
            TotalL = A + ZJ + UPSTROKE
           
            FW = oWorkSheet.Cells(z, 17)
            TotalW = FW
    End Select
    oParams.Item("TotalL").Value = TotalL / 10
    oParams.Item("TotalW").Value = TotalW / 10
    MsgBox (TotalL)
    MsgBox (TotalW)
   
   
    oWorkbook.Close
    oExcel.DisplayAlerts = False
    oExcel.Quit

   

 

However, I got a small problems yesterday.

A window appears and say that my worksheet can be Read&Write now, and two button Read&Write button - Cancel button.

I think the end code needs some more lines.................

My brother wrote an ReleaseObject() code for me in VB.NET but I don't understand what it means. He said that it could release the memory, etc..........

Moreover, I can not translate it to VBA language.

Could the ReleaseObject() help in this situtation and for my problem?

 

        releaseObject(oExcel)
        releaseObject(oWorkbook)
        releaseObject(oWorkSheet)

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

 

Could you tranfer it to VBA???

Many thanks in advance!

 

 

 

 

0 Likes
Message 10 of 11

MjDeck
Autodesk
Autodesk

Can you post a screenshot of the Excel message?

You could try opening the spreadsheet with the ReadOnly option:

Set oWorkbook = oExcel.Workbooks.Open(ThisApplication.FileLocation​s.Workspace & "\" & "CONFIGURATION.xlsx", 0, ReadOnly := True)

Also, try putting the line:

 oExcel.DisplayAlerts = False
before the line that opens the workbook.

 

The Sub releaseObject is not required in VBA.   It's only needed in .NET.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 11 of 11

Anonymous
Not applicable

Thank you,

I already put as you said.

 

About the screenshot, yesterday it appeared, but today it doesn't although I try alot.

 

Next, making the drawing with dimensioning is a big problem for me.

 

Now I must think how to put the view for fitness. When I need to create the Break.Add method (or not), the length and position of edge on drawing will change.

Then using Break View and Section View with a this changed length (or not changed if not Break).........

 

"How to put the view suitably as a person do??????"---> This code for VBA doesn't seem to be simply.....

 

I think that maybe I need to use MS Visio to draw the diagram for this situation.

 

After I finished this issue, the next issue is how to dimension with a changeable part (a kind of complex iPart)

God bless me!!!!!!!!!!!!!!!!!!

0 Likes