ILogic / VB Frame Generator equivalent

ILogic / VB Frame Generator equivalent

NachoShaw
Advisor Advisor
1,360 Views
15 Replies
Message 1 of 16

ILogic / VB Frame Generator equivalent

NachoShaw
Advisor
Advisor

hey

 

I don't want to use the actual FG because its not vb friendly so is there an equivalent method to successfully switch a profile in an extrusion without it causing a bunch of issues? ILogic or vb is good.

 

Thanks

Thanks

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
1,361 Views
15 Replies
Replies (15)
Message 2 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@NachoShaw,

 

Please provide some more information on requirement.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 16

JhoelForshav
Mentor
Mentor

Hi @NachoShaw 

I was working on the same problem a time back. I don't remember much from it but I just tried to convert it to iLogic and it seems to work fine. Hopefully you can get some ideas from it at least.

This code lets you pick a frame member. you're then prompted to select the row from content center you want to change it to.

My thread: https://forums.autodesk.com/t5/inventor-customization/how-does-frame-generator-identify-members/td-p...

The code as an iLogic rule:

Sub Main
CustomMember_ChangeRow()
End Sub

Sub CustomMember_ChangeRow()
        Dim i As Integer
        Dim oAsmDoc As AssemblyDocument
        oAsmDoc = ThisApplication.ActiveDocument
        Dim oAsmDef As AssemblyComponentDefinition
        oAsmDef = oAsmDoc.ComponentDefinition
        Dim oOcc As ComponentOccurrence
        oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "välj balk")
        Dim oDef As PartComponentDefinition
        oDef = oOcc.Definition
        If oDef.IsContentMember Then
            MsgBox("this sample works with the custom CC member only")
            Exit Sub
        Else
            Debug.Print("It's a Custom CC member")
        End If
        Dim oDoc As PartDocument
        oDoc = oDef.Document
        Dim oProps As PropertySet
        oProps = oDoc.PropertySets.Item("Content Library Component Properties")
        Dim oProp As Inventor.Property
        oProp = oProps.Item("FamilyId")
        Dim FamilyId As String
        FamilyId = oProp.Value
        Dim oContentCenter As ContentCenter
        oContentCenter = ThisApplication.ContentCenter
        Dim oFamily As ContentFamily
        oFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#")
        oProp = oProps.Item("MemberId")
        Dim MemberId As String
        MemberId = oProp.Value
        Dim newRow As Integer
        newRow = InputBox("Current Family row is " & MemberId _
            & vbNewLine & vbNewLine & "New Family row:",
            "New Family Row:", MemberId)
        Dim oRow As ContentTableRow
        oRow = oFamily.TableRows.Item(newRow)
        Dim nCol As Integer
        Dim oColumn As ContentTableColumn
        Dim oPar As UserParameter
        Dim oCustomProps As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
        For Each oPar In oDef.Parameters.UserParameters
            If oPar.DrivenBy.Count = 0 Then
                nCol = -1
                For i = 1 To oFamily.TableColumns.Count
                    If oFamily.TableColumns.Item(i).InternalName = oPar.Name Then
                        nCol = i
                        Exit For
                    End If
                Next
                If nCol <> -1 Then
                    oColumn = oFamily.TableColumns.Item(nCol)
                    If oColumn.KeyColumnOrder > 0 Then
                    Else
                        Dim units As String
                        units = oColumn.Units
                        Dim oCell As ContentTableCell
                        oCell = oRow.Item(nCol)
                        Dim value As String
                        value = oCell.Value & " " & units
                        oPar.Expression = value
                        Try
                            oCustomProps.Item(oPar.Name).Value = value
                        Catch ex As Exception
                        End Try
                    End If
                End If
            End If
        Next
        oProp = oProps.Item("MemberId")
        oProp.Value = newRow
        oProp = oProps.Item("Member Revision")
        oProp.Value = CreateGuid()
        For i = 1 To oFamily.TableColumns.Count
            oColumn = oFamily.TableColumns.Item(i)
            If oColumn.HasPropertyMap = True Then
                Dim setid As String = String.Empty
                Dim propid As String = String.Empty
                Dim units As String
                units = oColumn.Units
                Try
                    If oColumn.InternalName <> "PARTNUMBER" Then
                        oColumn.GetPropertyMap(setid, propid)
                        Dim oExpression As String = oColumn.Expression
                        oExpression = Replace(Replace(oExpression, "&", ""), Chr(34), "")
                        Dim inS As String = oExpression
                        Dim oColl As New Collection
                        Dim s As String
                        Dim j As Integer, k As Integer
                        Do
                            j = InStr(1, inS, "{")
                            k = InStr(1, inS, "}")
                            If (j = 0) Or (k = 0) Then Exit Do
                            s = Mid$(inS, j + 1, k - j - 1)
                            If s <> "" Then
                                Call oColl.Add(s)
                                inS = Mid$(inS, k + 1, Len(inS))
                            End If
                        Loop Until s = ""
                        Dim ss As Object
                        For Each ss In oColl
                            Try
                                Dim oParam As UserParameter
                                Try
                                    oParam = oDef.Parameters.UserParameters.Item(ss)
                                    s = oParam.Expression
                                    Debug.Print(s)
                                    s = Microsoft.VisualBasic.Left$(s, InStr(s, " ") - 1)
                                    Debug.Print(s)
                                Catch
                                    s = ""
                                    For colIndex = 1 To oFamily.TableColumns.Count
                                        If oFamily.TableColumns.Item(colIndex).InternalName = ss Then
                                            s = oRow.Item(colIndex).Value
                                            Exit For
                                        End If
                                    Next

                                    Debug.Print(s)
                                End Try
                            Catch
                            End Try
                            oExpression = Replace$(oExpression, "{" & ss & "}", s)
                        Next
                        Try
                            oDoc.PropertySets.Item(setid).ItemByPropId(propid).Value = oExpression &
                                If(units IsNot Nothing, " " & units, Nothing)
                        Catch
                            oDoc.PropertySets.Item(setid).Item(propid).Value = oExpression &
                                If(units IsNot Nothing, " " & units, Nothing)
                        End Try
                    End If
                Catch
                    Debug.Print("Failed to update: " & oColumn.InternalName)
                End Try
            End If
        Next
        ChangeAttributes(oOcc, newRow, FamilyId, GetPathID(oOcc))
        oDoc.Update()
        oDoc.Save()
        oAsmDoc.Update()
        oAsmDoc.Rebuild2()
        Beep()
    End Sub

    Function GetPathID(oOcc As ComponentOccurrence) As String
        Dim oDef As PartComponentDefinition = oOcc.Definition
        Dim oDoc As PartDocument = oDef.Document

        Dim FGPaths As String = oDoc.AttributeManager.FindAttributes("com.autodesk.FG*", "Paths", "*").Item(1).Value
        Return FGPaths.Split("""")(1)
    End Function
    Sub ChangeAttributes(oOcc As ComponentOccurrence, newRow As Integer, FamilyID As String, oPath As String)
        Dim oParent = oOcc.ContainingOccurrence
        While True

            Dim AttributesEnum As AttributesEnumerator = oParent.Definition.Document.AttributeManager.FindAttributes("com.autodesk.FG*", "Frame.Skeletons", "*")

            If AttributesEnum.Count > 0 Then
                Dim oS As String = AttributesEnum.Item(1).Value
                Dim StartIndex As Integer = oS.IndexOf(oPath)
                Dim oNewContent As Integer = oS.IndexOf("MonikerForNewContent", StartIndex)
                Dim oNumber As Integer = oS.IndexOf(FamilyID, oNewContent)
                Dim oMember As Integer = oS.IndexOf("#", oNumber) + 1
                Dim oIntegers As Integer = 1
                While True
                    If IsNumeric(oS(oMember + oIntegers)) Then
                        oIntegers += 1
                    Else
                        Exit While
                    End If
                End While
                oS = oS.Substring(0, oMember) & newRow & oS.Substring(oMember + oIntegers)
                oNewContent = oS.IndexOf("MonikerForCC", StartIndex)
                oNumber = oS.IndexOf(FamilyID, oNewContent)
                oMember = oS.IndexOf("#", oNumber) + 1
                oIntegers = 1

                While True
                    If IsNumeric(oS(oMember + oIntegers)) Then
                        oIntegers += 1
                    Else
                        Exit While
                    End If
                End While
                oS = oS.Substring(0, oMember) & newRow & oS.Substring(oMember + oIntegers)

                AttributesEnum.Item(1).Value = oS
                Exit While
            Else
                Try
                    oParent = oParent.ContainingOccurrence
                Catch
                    MsgBox("Error")
                    Exit While
                End Try
            End If
        End While
    End Sub
	Private Function CreateGuid()
        CreateGuid = Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36)
    End Function
0 Likes
Message 4 of 16

NachoShaw
Advisor
Advisor

Hey

 

Thats excellent thanks. Im looking to avoid the Content Center and have something that works in a similar way to FG but not FG or CC. Think there is enough info in the thread to get on the right track for sure.

 

i'll update the post with results when i get to that stage

 

 

Thanks

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 5 of 16

Eide.N
Advocate
Advocate

Yes, please report back!

0 Likes
Message 6 of 16

hayattangercekler2
Advocate
Advocate

Did you get any results on this topic?

0 Likes
Message 7 of 16

NachoShaw
Advisor
Advisor

My project demands changed and I had to shelve this however, your reply has refreshed me so I'll set out a plan

 

Thanks

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 8 of 16

hayattangercekler2
Advocate
Advocate
Do I have a chance to access the lines of the ipt file in an assembly file, capture the desired line and assign a profile with the design/insert frame?

So I want to create a profile with an fg from 0.
0 Likes
Message 9 of 16

Eide.N
Advocate
Advocate

Hi guys, I just watched this class from AU and one part of it (16:21) may be of interest:

https://events-platform.autodesk.com/event/au-2022-digital-experience/planning/UGxhbm5pbmdfOTg5MjE0

 

At (16:21) they talk about using iFeatures as sketches for extrusions. I recommend digging into it, it may give some ideas for implementation. I have tested this manually and it is the new way I will be doing multibodies. 

0 Likes
Message 10 of 16

Eide.N
Advocate
Advocate

Wanted to tag @Ben-Cornelius here (one of the authors of the video).

Message 11 of 16

Ben-Cornelius
Collaborator
Collaborator

Please go through this class. This will go through the methodology in detail. As well as the automation we have surrounding this

All the skeletons in the closet- Skeletal Modeling Master Class | Autodesk University

Message 12 of 16

Eide.N
Advocate
Advocate

Nice! Thanks Ben!

Message 13 of 16

fadamsQDHQS
Observer
Observer

fadamsQDHQS_0-1670273817560.png

 

0 Likes
Message 14 of 16

NachoShaw
Advisor
Advisor

Hey

 

newrow = InputBox("current Family row is " & MemberId & _
vbNewLine & vbNewLine & "new Family roww:" & _
"New Family Row:", MemberId)

 

Dim ocustomProps As PropertySet
Set oCustomProps = odoc.PropertySets.Item("Inventor User Defind Properties")

 

VBA is different to iLogic & VB.Net

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 15 of 16

fadamsQDHQS
Observer
Observer

THANK YOU SO MUCH FOR THE REPLY! HOWEVER, I DON'T UNDERSTAND PROGRAMMING, NO KNOWLEDGE! COULD YOU PLEASE EXPLAIN YOUR POST AND HOW IT CORRECTS MY ERROR?

0 Likes
Message 16 of 16

NachoShaw
Advisor
Advisor

Hey

 

If you intend to use code either in VBA or iLogic, it would be best for you to read up / watch some youtube videos about it to get a better understanding. To explain my code:

 

In your image you have 2 red highlighted portions of code. this indicates an error on those lines. My code fixes each section. to explain what the differences are:

 

iLogic code can be constructed in a single line in the same way vb.net can. The object is created and instantiated like this

Dim oDoc As document = ThisApplication.ActiveDocument

This line of code in simple terms is taking the active document (the one you can see) from the currently open instance of Inventor, creating a code version of the document (oDoc) and setting as the active document.

In VBA, you cannot construct and instantiate an object like you can in iLogic or vb.Net, it must be done in 2 separate lines:

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

or

Dim oDoc As Document: Set oDoc = ThisApplication.ActiveDocument

Using the colon as a separator to allow the 2 commands on the same line.

 

For the message box, code in general requires you fully qualify the code line. you can return the code down to a new line but only if you tell the code what you are doing. for example:

 

Valid messagebox

MsgBox ("here is some text"), vbOKCancel, "My title"

 

Valid messagebox

MsgBox ("here is some text"), _
         vbOKCancel, _
         "My title"

 

Invalid messagebox

MsgBox ("here is some text"), 
vbOKCancel, 
"My title"

 

The underscore is telling the code line that it continues below. without it, the code line is unfinished and unaware there is more code underneath to complete the method.

 

In your case, the inputbox was missing the underscore

 

Hope that helps, i would strongly advise looking into some coding help files if you're going to be looking at code solutions.

 

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.