- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello.
First of all, Big Tx to all of you from this forum.
I'm new to ILogic. but i have to do a automation for a project a have and need you help.
I manage to get bits and pieces from this forum to write a ILogic rule for my need.
Let me describe what i need:
I have an assembly with sheet metal parts. I need to fill a Excel *.xls template with 3 things: Length and With (from sheet metal fp) + Part Description form all the parts in the assembly. So for this i made :
Sub Main()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition
' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
' Iterate through all part occurrences in assembly.
For Each oOcc In oLeafOccs
Dim odoc As PartDocument
Try
odoc=oOcc.definition.document
Catch
End Try
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = odoc.ComponentDefinition
'Determines if there is a flat pattern
If odoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
' If oSMDef.FlatPattern Is Nothing Then
' 'No Flat Pattern Exists
' iProperties.Value(oOcc.Name,"Custom", "Width") = "N/A"
' iProperties.Value(oOcc.Name,"Custom", "Length") = "N/A"
' Else
oSMDef.Unfold()
odoc.Update2(True)
Dim fp As FlatPattern = oSMDef.FlatPattern
Lungime = fp.Length*10
Latime = fp.Width*10
iProperties.Value(oOcc.Name,"Custom", "Lungime")= Lungime
iProperties.Value(oOcc.Name, "Custom", "Latime") = Latime
End If
Dim sourceFileName As String = ThisDoc.Path + "\2.xls"
If (Not IO.File.Exists(sourceFileName)) Then
MessageBox.Show("The source file " & sourceFileName & " does not exist", "Parameter Export")
Return
End If
Dim fileName As String
Using dialog As New SaveFileDialog()
dialog.Title = "Export Parameters to Excel"
dialog.Filter = "Excel Files (*.xls)|*.xls"
If (dialog.ShowDialog() <> vbOK) Then
Return ' exit out of the rule
End If
fileName = dialog.FileName
End Using
If (String.Equals(sourceFileName, fileName, StringComparison.OrdinalIgnoreCase)) Then
MessageBox.Show("You cannot overwrite the original file: " & sourceFileName, "Parameter Export")
Return
End If
IO.File.Copy(sourceFileName, fileName, True)
GoExcel.CellValue(fileName, "Sheet1", "A19") = d0
'GoExcel.CellValue("A19") = iProperties.Value("Project", "Description")
GoExcel.CellValue("B19") = iProperties.Value(oOcc.Name,"Custom", "Lungime")
GoExcel.CellValue("C19") = iProperties.Value(oOcc.Name, "Custom", "Latime")
GoExcel.CellValue("E19") = iProperties.Value(oOcc.Name,"Project", "Part Number")
GoExcel.Save
next
End Sub
I have some problems with this code, first i tried this code so many time, my custom ipropertis are a mess, so i would like to be able to delete all custom ipropertis prier to write the new ones.
next problem is this code is generating a new Excel sheet for every part. I would lie to generate only one copy and populate next row for every part.
Sry for my bad English and y tipo...... Tx
Solved! Go to Solution.