03-15-2022
10:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-15-2022
10:52 AM
Hello,
i can't get it to work
this is currently my rule.
I would also like to export the individual dwg files.
would you kindly help me to integrate it into this rule?
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\l.azzariti\Desktop\Output" & "\" & sAsmName & "_" & Parameter("RIF_CMA") & Parameter("RIF_ID") & "Step" 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 '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 sRIF_CMA As String = Parameter("RIF_CMA") Dim sRIF_ID As String = Parameter("RIF_ID") oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sRIF_CMA & "_" & sRIF_ID & 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 & "\" & "Distinta" & "_" & Parameter("RIF_CMA") & "_" & Parameter ("RIF_ID") & ".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("Vista1").activate Catch oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Vista1") 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