Run Sheet Metal rule from Assembly Document

Run Sheet Metal rule from Assembly Document

Anonymous
Not applicable
1,409 Views
3 Replies
Message 1 of 4

Run Sheet Metal rule from Assembly Document

Anonymous
Not applicable

Hi All,

 

I have created a small iLogic rule within a sheet metal template which allows me to create a flat pattern upon save (with a trigger):

 

SyntaxEditor Code Snippet

    Dim oDoc As PartDocument
    oDoc = ThisDoc.Document
    Dim oCompDef As SheetMetalComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    If oCompDef.HasFlatPattern = False Then
    oCompDef.Unfold
    Else
    oCompDef.FlatPattern.ExitEdit
    End If

This works fine when within the single sheet metal part itself. I am wondering if within my assembly level it would be possible to have a rule which goes into each Sheet Metal part only and runs this rule in the background.

 

Or, in fact, if there is any easier/better way of acheiving this outcome.

 

Thanks 

0 Likes
Accepted solutions (1)
1,410 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Just to add a bit more information as the inital post was a little vague - the kind of work flow I am hoping to acheive would be something along the lines of:

 

Part File - On Save

If Standard Part - Do Nothing

If Sheet Metal Part:

  -  If Flat Pattern exists - Do Nothing

  -  If Flat Pattern does not exist - Creat Flat Pattern

 

Assembly File - On Save

Look at all parts within assembly

If Standard PArt - Do Nothing

If Sheet Metal Part - Run Flat Pattern Rule

 

I would like all functions to run silently so as not to appear 'on screen'.

 

Thanks.

0 Likes
Message 3 of 4

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Hi,

 

This code does the trick, it traverses all the parts and if needed it creates a flat patteren, it's written in vba, slight modifications may be needed

Public Sub GetPartOccurrences()
   On Error GoTo Err
    ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument

    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc.ComponentDefinition

    ' Get all of the leaf occurrences of the assembly.
    Dim oLeafOccs As ComponentOccurrencesEnumerator
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

    ThisApplication.SilentOperation = True
    
    ' Iterate through the occurrences and print the name.
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oLeafOccs
        
        Dim oDoc As PartDocument
        Set oDoc = ThisApplication.Documents.Open(oOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName, False)
        
        If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        Dim oCompDef As SheetMetalComponentDefinition
        Set oCompDef = oDoc.ComponentDefinition
        
        If oCompDef.HasFlatPattern = False Then
        oCompDef.Unfold
        oCompDef.FlatPattern.ExitEdit
        End If
        Call oDoc.Close(False)
        Else
        Call oDoc.Close(True)
        End If
    Next oOcc

ThisApplication.SilentOperation = False
Exit Sub
Err:
Call MsgBox(Err.Description)
ThisApplication.SilentOperation = False
    
End Sub

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 4 of 4

Anonymous
Not applicable

I've now modified my code to the below:

 

SyntaxEditor Code Snippet

Sub Main
auto = iLogicVb.Automation
' Set Rule name
Dim ruleName As String
ruleName = "Flat_Pattern"
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
' Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim rule As Object
rule = auto.GetRule(oRefDoc, ruleName)
'If (rule Is Nothing) Then'Call MsgBox("No rule named " & ruleName & " was found in the document.")'Else'MessageBox.Show(rule.Name, oRefdoc.displayname)

Dim i As Integer
i = auto.RunRuleDirect(rule)

End If
Next
End Sub

 I would say I am now 99% of the way there - it is currently set to activate on a form which runs the rule and is opening only the sheet metal parts within my assembly and is running the rule and creating the flat pattern. My only sticking point now is that it is only opening one sheet metal ipt from the assembly file and is generating an error message on all the others. Any ideas?

 

Thanks 

0 Likes