I've handeled somehow with the rule for laser cutting time calculation. Now I'd like to edit the rule to have one single rule working both for a single file and an assembly. Below You can find the rule Ive prepared. Works fine for a single sheet metal file. The problem is when it starts with the assembly. I looks like the rule is not able to read the the parameter thickness of a sheet metal part within the assembly. Mayby somebody will be able to repair it.
Sub Main Czas_Palenia_Laser ()
Dim oFile As Document
oFile = ThisDoc.Document
If oFile.DocumentType = kPartDocumentObject Then
Call Part(oFile)
End If
If oFile.DocumentType = kAssemblyDocumentObject Then
Call Assy(oFile)
End If
End Sub
Sub Assy (oDoc As Document)
'oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument 'Zmiany 12.07.2019
oCompDef = oAsmDoc.ComponentDefinition
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oDoc.AllReferencedDocuments
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
If oRefDoc.DocumentType = kPartDocumentObject Then
If oRefDoc.IsModifiable = True Then 'Wyklucza elementy należące do biblioteki części m.in. śruby, nakrętki itp.
If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'Sprawdza czy część wchodząca w skład złożenia została utworzona z wykorzystaniem szablonu konstrukcja blachowa.
ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
Call Part(oRefDoc)
oRefDoc.Close
Else
End If
Else
End If
End If
Next
End Sub
Sub Part (oDoc As Document)
'oDoc = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
If oSMDef.HasFlatPattern = False Then
oSMDef.Unfold
oSMDef.FlatPattern.ExitEdit
End If
Dim oFlatPattern As FlatPattern
oFlatPattern = oDoc.ComponentDefinition.FlatPattern
Dim oFace As Face
oFace = oSMDef.FlatPattern.TopFace
Dim oOuterLength As Integer
oOuterLength = 0
Dim oLoop As EdgeLoop
Dim dMax, dMin, dLength As Double
Dim oEdge As Edge
For Each oLoop In oFace.EdgeLoops
If oLoop.IsOuterEdgeLoop Then
For Each oEdge In oLoop.Edges
Call oEdge.Evaluator.GetParamExtents(dMin, dMax)
Call oEdge.Evaluator.GetLengthAtParam(dMin, dMax, dLength)
oOuterLength = oOuterLength + dLength
Next
Exit For
End If
Next
'--> MessageBox.Show(oOuterLength, "iLogic Test Value No1")
Dim iLoopCount As Long
iLoopCount = 0
Dim oInnerLength,oLoopLength As Double
For Each oLoop In oFace.EdgeLoops
oLoopLength = 0
If Not oLoop.IsOuterEdgeLoop Then
For Each oEdge In oLoop.Edges
Call oEdge.Evaluator.GetParamExtents(dMin, dMax)
Call oEdge.Evaluator.GetLengthAtParam(dMin, dMax, dLength)
oLoopLength = oLoopLength + dLength
Next
oInnerLength = oInnerLength + oLoopLength 'Oblicza całkowitą dł. pętli (sumę obowdów) wew. detalu.
End If
Next
'--> MessageBox.Show(oTotalLength, "iLogic Test Value No2")
Dim oTransaction As Transaction
oTransaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "FindArea ")
Dim oSketch As PlanarSketch
oSketch = oFlatPattern.Sketches.Add(oFlatPattern.TopFace)
Dim oEdgeLoop As EdgeLoop
numLoops = 1
For Each oEdgeLoop In oFlatPattern.TopFace.EdgeLoops
If oEdgeLoop.IsOuterEdgeLoop = False Then
numLoops = numLoops + 1
End If
Next
Dim NoPierces As Double
NoPierces = numLoops 'WPALENIA !!!!
'--> MessageBox.Show(NoPierces, "iLogic Test Value No3")
For Each oEdgeLoop In oFlatPattern.TopFace.EdgeLoops
If oEdgeLoop.IsOuterEdgeLoop Then
Exit For
End If
Next
For Each oEdge In oEdgeLoop.Edges
Call oSketch.AddByProjectingEntity(oEdge)
Next
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
oTransaction.Abort
'-------------------------------------------------------------------------------------------------------------
'Konwersja zmiennych tak by możliwe było zapisanie wartości parametrów jako niestandardowe wartości iLogic
Dim oUom As UnitsOfMeasure
Dim oLengthUnits As String
oUom = oDoc.UnitsOfMeasure
oLengthUnits = oUom.GetStringFromType(oUom.LengthUnits)
OuterCutLength = oUom.GetStringFromValue(oOuterLength, oLengthUnits)
InnerCutlength = oUom.GetStringFromValue(oInnerLength, oLengthUnits)
TotalCutLength = oUom.GetStringFromValue(oInnerLength + oOuterLength, oLengthUnits)
'--> MessageBox.Show(OuterCutLength & " " & InnerCutlength & " " & TotalCutLength , "iLogic Test Value No4")
'-------------------------------------------------------------------------------------------------------------
'Zapisywanie parametrów jako niestandardowe wartości iLogic
Dim oCustomPropSet As PropertySet
oCustomPropSet = oDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Try
oCustomPropSet.Add(OuterCutLength, "Dł. zew. krawędzi")
Catch
iProperties.Value ("Custom","Dł. zew. krawędzi") = OuterCutLength
End Try
Try
oCustomPropSet.Add(InnerCutLength, "Dł. wew. krawędzi")
Catch
iProperties.Value ("Custom","Dł. wew. krawędzi") = InnerCutLength
End Try
Try
oCustomPropSet.Add(TotalCutLength, "Całk. dł. krawędzi")
Catch
iProperties.Value ("Custom","Całk. dł. krawędzi") = TotalCutLength
End Try
Try
oCustomPropSet.Add(CStr(NoPierces), "Ilość wpaleń")
Catch
iProperties.Value ("Custom","Ilość wpaleń") = CStr(NoPierces)
End Try
'---------------------------------------------------------------------------------------------------------------------
'Wybór materiału
oMaterialArray = New String(){"STAL", "STAL NIERDZEWNA", "STAL GALWANIZOWANA", "ALUMINIUM"}
oMaterial = InputListBox("Z powyższej listy wybierz rodzaj materiału z którego wykonany jest detal",oMaterialArray, "Stal", "iLogic", "Wybierz rodzaj materiału")
'---------------------------------------------------------------------------------------------------------------------
'Dobór wartości posuwu głowicy
Dim FeedRate, Thickness As Double
Try
Thickness = oDoc.ComponentDefinition.Parameters("Grubość") 'Pobiera parametr grubość przypisany do konstrukcji blachowej
Catch
Thickness = oDoc.ComponentDefinition.Parameters("Thickness")
End Try
'If Thickness Is Nothing Then
'MessageBox.Show("Wystąpił problem z pobraniem parametru grubość z modelu", "iLogic")
'Exit Sub
'End If
Try
MaterialName = oDoc.ComponentDefinition.Material.Name 'Pobiera dane dot. materiału przypisanego do modelu.
Catch
MessageBox.Show("Wystąpił problem z pobraniem danych dot. materiału przypisanego do modelu", "iLogic")
End Try
If oMaterial = "STAL" Then
Select Case Thickness
Case 1
FeedRate = 5500 '8300
Case 1.4 To 1.6
FeedRate = 4500 '6500
Case 2.5
FeedRate = 4000
Case 2
FeedRate = 3500 '6000
Case 2.9 To 3.1
FeedRate = 2000 '3500
Case 4
FeedRate = 2500 '3500
Case 4.9 To 5.1
FeedRate = 2000 '2700
Case 5.9 To 6.1
FeedRate = 1900 '2400
Case 8
FeedRate = 1200 '1900
Case 10
FeedRate = 1100 '1400
Case 11.9 To 12.1
FeedRate = 1000 '1100
Case 15
FeedRate = 800 '950
Case 16
FeedRate = 700
Case 20
FeedRate = 650 '650
End Select
Else
End If
If oMaterial = "STAL NIERDZEWNA" Then
Select Case Thickness
Case 1: FeedRate = 5000 '9000
Case 1.4 To 1.6
FeedRate = 4200
Case 2: FeedRate = 2500 '6100
Case 2.9 To 3.1
FeedRate = 1800 '3800
Case 4: FeedRate = 1800 '2500
Case 5: FeedRate = 1600 '2000
Case 5.9 To 6.1
FeedRate = 1400
Case 8: FeedRate = 1000 '800
Case 10: FeedRate = 800 '650
Case 12: FeedRate = 800 '270
End Select
Else
End If
If oMaterial = "STAL GALWANIZOWANA" Then
Select Case Thickness
Case 1: FeedRate = 5500 '9000
Case 1.25: FeedRate = 5000 '6500
Case 1.4 To 1.55
FeedRate = 4500 '7500
Case 2: FeedRate = 3500 '6000
Case 2.9 To 3.1
FeedRate = 2000 '3000
End Select
Else
End If
If oMaterial = "ALUMINIUM" Then
Select Case Thickness
Case 1: FeedRate = 5500 '9000
Case 1.5: FeedRate = 4700 '7300
Case 2: FeedRate = 4000 '5800
Case 2.5: FeedRate = 3900 '4300
Case 2.9 To 3.1
FeedRate = 2300 '2900
Case 4: FeedRate = 1900 '2400
Case 5: FeedRate = 1600 '1800
Case 6: FeedRate = 1500 '1400
Case 8: FeedRate = 1000 '750
End Select
Else
End If
If FeedRate = 0 Then
MessageBox.Show("Wystąpił problem z doborem prędkości posuwu głowicy!" _
& vbLf _
& vbLf & "Materiał przypisany do modelu: " & MaterialName _
& vbLf _
& vbLf & "Grubość materiału: " & Thickness & " mm" _
& vbLf _
& vbLf & "Wybrana wartość posuwu: " & FeedRate & " [mm/min]" _
& vbLf _
& vbLf & "Sprawdź ustawienia materiału przypiasanego do modelu i uruchom regułę ponownie", "iLogic")
Exit Sub
End If
'-->MessageBox.Show(FeedRate, "iLogic")
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------
' OBLICZENIA
Dim totalPierces As Double
PierceDeclar = MessageBox.Show ("Czy chcesz zdefiniować ilość wpaleń danego typu: puls/normalne?" _
& vbLf & " " _
& vbLf & "Wybierz TAK aby zdefiniować ilości wpaleń danego typu." _
& vbLf & " " _
& vbLf & "Wybierz NIE - wszystkie występujące wpalenia zostaną uwzględnione jako normalne" _
& vbLf & " " _
& vbLf & "Wpalenia typu puls znajdują zastosowanie w przypadku gdy śr. otworu jest mniejsza lub równa od grubości palonego materiału", "iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2)
If PierceDeclar = vbYes Then
Do
nPierces = InputBox("Podaj ilość wpaleń normalne:" _
& vbLf _
& vbLf & "Wszystkie wpalenia: " & NoPierces,"iLogic", 0)
pPierces = InputBox("Podaj ilość wpaleń puls:" _
& vbLf _
& vbLf & "Wszystkie wpalenia: " & NoPierces _
& vbLf _
& vbLf & "Wpalenia normalne: " & nPierces,"iLogic", 0)
If nPierces = "" Then
Exit Sub
End If
pPierces_value = CDbl(pPierces) 'Function to convert string value into a double
nPierces_value = CDbl(nPierces)
totalPierces = nPierces_value + pPierces_value
If totalPierces <> NoPierces Then
MessageBox.Show("Zadeklarowano niewłaściwą ilość wpaleń!" _
& vbLf _
& vbLf & "Podaj prawidłową sumaryczną ilość wpaleń", "iLogic")
End If
Loop Until totalPierces = NoPierces 'Pętla wymusza na użytkowniku podanie prawidłowej ilości wpaleń, co ogranicza ryzyko błędu
'Return
Else
nPierces_value = CDbl(NoPierces)
End If
Dim EdgeCutTime As Double
If oInnerLength = 0 Then
EdgeCutTime = ((oOuterLength*10) / FeedRate) 'Przypadek gdy detal ma tylko obrys zewnętrzny, mnożnik x10 dodano aby przeliczyć jednostki cm -> mm
Else
Dim PerimeterFactor As Double
PerimeterFactor = Math.Round((oOuterLength / oInnerLength), 2, MidpointRounding.AwayFromZero) 'Współczynnik opisujący stosunek obwodu zewnętrzengo do wewnętrznego.
Select Case PerimeterFactor
Case <=2.5: EdgeCutTime = ((((oInnerLength + oOuterLength)*10) / FeedRate)*PerimeterFactor)
'MessageBox.Show("Case 1", "iLogic")
Case 2.5 To 3.5: EdgeCutTime = ((((oInnerLength + oOuterLength)*10)/ FeedRate)*(PerimeterFactor/2.5))
'MessageBox.Show("Case 2", "iLogic")
Case 3.5 To 5.5: EdgeCutTime = ((((oInnerLength + oOuterLength)*10) / FeedRate)*(PerimeterFactor/3.5))
'MessageBox.Show("Case 3", "iLogic")
Case Else: EdgeCutTime = (((oInnerLength + oOuterLength)*10) / FeedRate)
'MessageBox.Show("Case 4", "iLogic")
End Select
End If
Dim CutTime, WynikIFS As Double
'MessageBox.Show(EdgeCutTime, "iLogic")
CutTime = EdgeCutTime + ((nPierces_value * 0.025) + (pPierces_value * 0.055))
Dim Wynik As String
Wynik = Math.Round(CutTime,2, MidpointRounding.AwayFromZero).ToString("0.00")
WynikIFS = Math.Round((Wynik * 0.0167),3,MidpointRounding.AwayFromZero)
'-------------------------------------------------------------------------------------------
' PREZENTACJA WYNIKÓW
MessageBox.Show("Gatunek blachy: " & MaterialName _
&vbLf _
&vbLf & "Grubość blachy: " & Thickness & " mm." _
&vbLf _
&vbLf & "Ilość wpaleń: " & nPierces_value _
&vbLf _
&vbLf & "Prędkość posuwu: " & FeedRate & " mm/min." _
&vbLf _
&vbLf & "Czas palenia Laser: " & Wynik & " min." & " (" & WynikIFS & ") ", "iLogic")
'&vbLf & "Współczynnik: " & PerimeterFactor _ 'Wyświetla wartość współczynnika.
'&vbLf _
Try
oCustomPropSet.Add(WynikIFS, "Czas palenia")
Catch
iProperties.Value("Custom","Czas palenia") = WynikIFS
End Try
RuleParametersOutput()
InventorVb.DocumentUpdate()
End Sub
Thanks in advance for help.
Tomek