- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
ok, what you say is right, but I have a general assembly with sub-assemblies and related parts all under ilogic rules.
this in relation to the levels of detail have changes on the bill of materials.
if I set custom level of detail on the basis of ilogic rules I only see what interests me because all the components are inactive by ilogic rules and in the bill of materials (parts only) I only see what interests me.
if instead I enable the master level of detail it is as if the ilogic rules for inactivating sub-assemblies and parts no longer have an effect and in fact I see everything in the bill of materials.
I therefore tampered with your code with to make sure that the lod master is forced to get the bill of materials that I am interested in (parts only) export to excel and then retoten in customized level of detail.
the problem that in this way I receive an error message indicating that some subassemblies are set are not set to a custom level of detail but this is false and furthermore ignoring these errors it exports the parts list correctly only.
do you think I can do something?
Option Explicit On
Sub Main()
'check that the active document is an assembly file
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
Dim oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName )
Dim sFolder As String = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)" & "\" & sAsmName & Parameter("d109") & "Step Files"
Dim STEPTranslator As TranslatorAddIn
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureSTEPTranslatorSettings(STEPTranslator, oContext, oOptions, oDataMedium)
If Not System.IO.Directory.Exists(sFolder) Then
System.IO.Directory.CreateDirectory(sFolder)
End If
'sFolder = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)"& Parameter"d118"
'look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
If Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
'get all occurrences of the referenced file, if one on them is visible - export that file to STEP, otherwise skip
Dim oOccs As ComponentOccurrencesEnumerator = oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
Dim oOcc As ComponentOccurrence
Dim bVis As Boolean = False
For Each oOcc In oOccs
If oOcc.Visible
bVis = True
Exit For
End If
Next
If bVis = False Then
Continue For 'Next For
End If
'check that model is saved
If(System.IO.File.Exists(oRefDoc.FullDocumentName)) Then
Dim sFilename As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
Dim sDesc As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
Parameter.Quiet = True
Dim sSospensione As String = Parameter("sospensione")
Dim srif As String = Parameter("d109")
oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sSospensione & srif & sDesc & ".stp"
Try
Call STEPTranslator.SaveCopyAs(oRefDoc, oContext, oOptions, oDataMedium)
Catch
MsgBox("Export of " & oRefDoc.DisplayName & " failed. Continue next one", MsgBoxStyle.Critical)
End Try
End If
Next
MessageBox.Show("New Files Created in: " & vbLf & sFolder, "iLogic")
Shell("explorer.exe " & sFolder,vbNormalFocus)
Dim oDock As Document = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDock.ComponentDefinition
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Principale").activate
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Principale").activate
Dim ExportSheet = sFolder & "\" & "Parts Only " & Parameter("d109") & ".xls"
'oAsmDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
'' Export the BOM view
Dim oPartsOnlyBOMView As BOMView
oPartsOnlyBOMView = oBOM.BOMViews.Item("Solo parti")
oPartsOnlyBOMView.Export(ExportSheet, kMicrosoftExcelFormat)
Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("View1").activate
Catch
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("View1")
End Try
Try
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Livello di dettaglio1").activate
Catch
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations.Add("Livello di dettaglio1")
End Try
End Sub
Sub ConfigureSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oOptions.Value("ApplicationProtocolType") = 3
' Other options...
'oOptions.Value("Author") = ""
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = ""
'oOptions.Value("Organization") = ""
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".stp"
End If
End Sub