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: 

Reference key of same Entity Flat Pattern v.s. Folded Model

1 REPLY 1
SOLVED
Reply
Message 1 of 2
NL-Laurens
446 Views, 1 Reply

Reference key of same Entity Flat Pattern v.s. Folded Model

Hi Guys,

 

I have a question about Reference Keys in a sheet metal part.

 

What I'm trying to accomplish is making a program that calculates production times for sheet metal parts. Therefore I need to iterate the part to find all different features. I must iterate in the folded environment and also in the flat pattern environment.

 

For counting the time to drill all the holes I iterate the part to find all faces that have a SurfaceType = kCylinderSurface. While doing this in the folded and flat pattern environment, certain holes get counted twice. So I must look for a way to check if a hole is being processed before by either the folded-analysis-routine or the flatpattern-analysis-routine.

 

I tried to find my way with the use of reference keys. I store these reference keys inside an array to keep track of the holes I processed before. In that process I found that the reference key for a hole differ from the folded environment and the flat pattern environment. I searched for a solution to find either the folded-reference-key from the flat pattern environment or the other way around. That would solve my problems. Ok, so I found the function: .GetFlatPatternEntity. I thought I finally found the solution. But then I got stuck.

 

I would certainly expected that when I used the .GetFlatPattenEntity function together with the .GetRefenceKey function on a hole I would find the same reference key for a hole in the folded and flat pattern environment.

 

I did a little test to demonstrate what I mean. This sample code I tried on a sheet metal part with one hole selected. TestRefKeyFolded is started from the folded part environment. The TestRefKeyFlat is started from the flat pattern environment.

 

 

 

'This sub is tested in the folded part environment with one hole selected

Sub TestRefKeyFolded()

 

    Dim iLong As Long

    iLong = ThisApplication.ActiveDocument.ReferenceKeyManager.CreateKeyContext()

 

    Dim oFace As Inventor.Face

    Set oFace = ThisApplication.ActiveDocument.SelectSet.Item(1)

 

    Dim RefKey() As Byte

    Call oFace.GetReferenceKey(RefKey, iLong)

 

    Debug.Print ThisApplication.ActiveDocument.ReferenceKeyManager.KeyToString(RefKey)

 

    Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition

    Set oSheetMetalComp = ThisApplication.ActiveDocument.ComponentDefinition

 

    Dim oFlatPattern As FlatPattern

    Set oFlatPattern = oSheetMetalComp.FlatPattern

 

    Dim oFlatFace As Inventor.Face

    Set oFlatFace = oFlatPattern.GetFlatPatternEntity(oFace)

 

    Dim FlatRefKey() As Byte

    Call oFlatFace.GetReferenceKey(FlatRefKey, iLong)

 

    Debug.Print ThisApplication.ActiveDocument.ReferenceKeyManager.KeyToString(FlatRefKey)

 

End Sub

 

'This sub is tested in the flat pattern environment with the same one hole selected

Sub TestRefKeyFlat()

 

    Dim iLong As Long

    iLong = ThisApplication.ActiveDocument.ReferenceKeyManager.CreateKeyContext()

 

    Dim oFace As Inventor.Face

    Set oFace = ThisApplication.ActiveDocument.SelectSet.Item(1)

 

    Dim RefKey() As Byte

    Call oFace.GetReferenceKey(RefKey, iLong)

 

    Debug.Print ThisApplication.ActiveDocument.ReferenceKeyManager.KeyToString(RefKey)

 

End Sub

 

 

 

Can someone point me in the right direction for the best solution to this problem? And maybe more interesting for everyone here, can someone tell a little more about using reference keys for the same object in the folded and flat pattern environment?

 

Thanks in advance!

Laurens

1 REPLY 1
Message 2 of 2
NL-Laurens
in reply to: NL-Laurens

Hi Guys,

 

After experimenting with reference keys for what felled like ages, I decided to try it in a different way. First I tried to attach a attribute to all the face that identified them as processed. Looked like a nice way, also with the possibility to attach different attributes for different workshop actions. Also put some effort in this, but couldn’t get it to work.. must overlooked something..

 

Then I had a bright moment when experimenting with .InternalName function of entities. I found out that the internal names of entities are consistence during the session and for what I know now even from session to session. Perfect for my use.

 

Still my questions about the use of Reference Keys for the same entities in the Folded and Flat Pattern environment maybe interesting for other uses.

 

Here’s the routine to identify the same features in flat pattern and folded environment by use of the .InternalName function. The names get stored in an array called UsedHoleArray(). This function returns a string with "false" or "true". "true" means it has been used before and exits the calling sub.

 

Private Function CheckNotDoubleInternalName(oFace As Face)

Dim i As Integer

 

On Error Resume Next

For i = 0 To UBound(UsedHoleArray)

 

    If Err Then

        Err.Clear

        On Error GoTo 0

        ReDim Preserve UsedHoleArray(0) As String

        Exit For

    End If

 

    If UsedHoleArray(i) = oFace.InternalName Then

        CheckNotDoubleInternalName = "True"

        Exit Function

    End If

 

Next

 

CheckNotDoubleInternalName = "False"

 

ReDim Preserve UsedHoleArray(UBound(UsedHoleArray) + 1) As String

UsedHoleArray(UBound(UsedHoleArray)) = oFace.InternalName

 

' Debug.Print InvDoc.ComponentDefinition.FlatPattern.GetFlatPatternEntity(oFace).InternalName

 

On Error Resume Next

If InvDoc.ComponentDefinition.FlatPattern.GetFlatPatternEntity(oFace).InternalName <> "" Then

   

   

    If Err Then

        Err.Clear

        On Error GoTo 0

        Exit Function

    End If

 

    ReDim Preserve UsedHoleArray(UBound(UsedHoleArray) + 1) As String

    UsedHoleArray(UBound(UsedHoleArray)) = InvDoc.ComponentDefinition.FlatPattern.GetFlatPatternEntity(oFace).InternalName

 

End If

 

End Function

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

Post to forums  

Autodesk Design & Make Report