making a step from a iPart/iAssembly on a drawing level
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
To make the work easier, I wrote a piece of code to complete the entire process with 1 push of a button. This almost completely works. This is done at drawing level. It is then saves the file, a step and PDF are created and the file is checked in. Making a step is not going well.
If this is a model with 1 file it is no problem. Then the code works fine. However, we use iParts and iAssemblies within the company. Then my code doesn't work good anymore. It seems that then the last open model is used. To better explain what goes wrong, I also made this image.
This is the code that i use now. I've only shown the step making here. The rest of the code doesn't apply to my problem.
' The code to make a step from a drawing Sub Main 'The save path for option 3 SavePath = "C:\TEMP" 'Name of the file Name = iProperties.Value("Project", "Stock Number") Rev = iProperties.Value("Project", "Revision Number") FileName = Name + "-" + Rev 'SaveOption SaveLocation = SavePath 'Check the last sign for \ CheckLastSign = Right(SaveLocation, 1) If CheckLastSign <> "\" Then SaveLocation = SaveLocation + "\" End If 'Combine location and name LocationFileName = SaveLocation + FileName 'Get the model and make STEP Dim oModel As Document = ThisApplication.ActiveDocument.AllReferencedDocuments.Item(1) If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Or _ oModel.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then 'Make STEP ExportToSTEP(oModel, SaveLocation, LocationFileName) End If End Sub Sub ExportToSTEP(oModelDoc As Document, SaveLocation As String, LocationFileName As String) 'Get the STEP translator add-in Dim oSTEP As TranslatorAddIn For Each oAddIn As ApplicationAddIn In ThisApplication.ApplicationAddIns If oAddIn.DisplayName = "Translator: STEP" Then oSTEP = oAddIn End If Next If IsNothing(oSTEP) Then MsgBox("STEP Translator Add-in not found. Exiting.", vbCritical, "iLogic") Exit Sub End If 'Create needed variables for translator oTO = ThisApplication.TransientObjects oContext = oTO.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = oTO.CreateNameValueMap oDataMedium = oTO.CreateDataMedium oDataMedium.FileName = LocationFileName + ".stp" If oSTEP.HasSaveCopyAsOptions(oModelDoc, oContext, oOptions) Then ' Set application protocol. ' 2 = AP 203 - Configuration Controlled Design ' 3 = AP 214 - Automotive Design oOptions.Value("ApplicationProtocolType") = 3 oOptions.Value("IncludeSketches") = True oOptions.Value("export_fit_tolerance") = .000393701 'minimum oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName oOptions.Value("Authorization") = "" oOptions.Value("Description") = oModelDoc.PropertySets(3).Item("Description").Value oOptions.Value("Organization") = oModelDoc.PropertySets(2).Item("Company").Value Try oSTEP.SaveCopyAs(oModelDoc, oContext, oOptions, oDataMedium) Catch MsgBox("Export drawing model to STEP file failed.", vbExclamation, "Export to step error") End Try End If End Sub
Hopefully it is clear what is going wrong and what I am trying to achieve. Does anyone know how I can fix this?