- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have an iLogic rule that lets me export selected parts from assembly as step files.
I want to add a modification so that when i select parts and run the rule, then a folder browser pops up and lets me choose where i want to save selected parts. Now it just saves step files in the same directory that the part files are located, but i want to be able to choose where i want to save .step files.
Rule i use for exporting selected files is from this forum, posted by marcin_otręba.
The rule:
Public Sub Main() 'MsgBox("BOM QTY Update ") Dim ass As AssemblyDocument= ThisApplication.ActiveDocument Dim oselset As SelectSet = ass.SelectSet Dim i As Integer = 0 Dim result As Boolean Dim occ As ComponentOccurrence If oselset.Count<>0 Then For Each occ In oselset Dim doc As Document = occ.Definition.Document ' Update or create the custom iProperty. result=ExportToSTEP(doc) If result = True Then i = i + 1 End If Next
MessageBox.Show(i & " files successfully exported", "result") Else MessageBox.Show("You must select files to export before running rule", "Error") End If End Sub 'Here's the subroutine. Function ExportToSTEP(doc As Document) As Boolean ' Get the STEP translator Add-In. Dim oSTEPTranslator As TranslatorAddIn oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") If oSTEPTranslator Is Nothing Then MsgBox("Could not access STEP translator.") ExportToSTEP=False Exit Function End If Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap If oSTEPTranslator.HasSaveCopyAsOptions(doc, 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 = kFileBrowseIOMechanism Dim oData As DataMedium oData = ThisApplication.TransientObjects.CreateDataMedium oData.FileName = Replace(Replace(doc.fullfilename,".ipt",""),".iam","") & ".stp" Call oSTEPTranslator.SaveCopyAs(doc, oContext, oOptions, oData) ExportToSTEP=True End If End Function
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try this:
Public Sub Main()
Dim ass As AssemblyDocument = ThisApplication.ActiveDocument
Dim RutaExport As String = ThisDoc.Path
Dim Dialog = New FolderBrowserDialog()
Dialog.SelectedPath = RutaExport
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose directory for saved .stp files"
Dialog.ShowDialog()
If DialogResult.OK Then
oPath = Dialog.SelectedPath & "\"
Else
Return
End If
Dim oselset As SelectSet = ass.SelectSet
Dim i As Integer = 0
Dim result As Boolean
Dim occ As ComponentOccurrence
If oselset.Count <> 0 Then
For Each occ In oselset
Dim doc As Document = occ.Definition.Document
result = ExportToSTEP(doc, oPath)
If result = True Then
i = i + 1
End If
Next
MessageBox.Show(i & " files successfully exported", "result")
Else
MessageBox.Show("You must select files to export before running rule", "Error")
End If
End Sub
Function ExportToSTEP(doc As Document, sPath As String) As Boolean
Dim oSTEPTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(doc, oContext, oOptions) Then
oOptions.Value("ApplicationProtocolType") = 3
oContext.Type = kFileBrowseIOMechanism
Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
uPath = Left(doc.FullDocumentName, InStrRev(doc.FullDocumentName, "\") -1)
uName = Mid(doc.FullDocumentName, Len(uPath) + 2, Len(doc.FullDocumentName) -Len(uPath) -5)
oData.FileName = sPath & uName & ".stp"
Call oSTEPTranslator.SaveCopyAs(doc, oContext, oOptions, oData)
ExportToSTEP = True
End If
End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is just another version that I was working on for you at the same time. It just puts the code for the folder dialog out into a separate function to keep the main code cleaner.
Sub Main()
Dim ass As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSelSet As SelectSet = ass.SelectSet
If oSelSet.Count = 0 Then
MessageBox.Show("You must select files to export before running rule", "Error")
Exit Sub
End If
'this runs the custom Function defined below to return a selected folder path
oFolder = GetFolder
'make sure a folder was selected, if not exit rule
If String.IsNullOrEmpty(oFolder) Then Exit Sub
Dim i As Integer = 0
Dim result As Boolean
Dim Occ As ComponentOccurrence
For Each Occ In oSelSet
Dim OccDoc As Document = Occ.Definition.Document
'get file name (without path & without file extension)
oName = System.IO.Path.GetFileNameWithoutExtension(OccDoc.FullFileName)
'put new STEP file name together
oNewName = oFolder & "\" & oName & ".stp"
result = ExportToSTEP(OccDoc, oNewName)
If result = True Then
i = i + 1
End If
Next
MessageBox.Show(i & " files successfully exported", "result")
End Sub
'Here's the subroutine.
Function ExportToSTEP(doc As Document, NewFileName As String) As Boolean
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
If oSTEPTranslator Is Nothing Then
MsgBox("Could not access STEP translator.")
ExportToSTEP = False
Exit Function
End If
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = NewFileName
If oSTEPTranslator.HasSaveCopyAsOptions(doc, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oOptions.Value("ApplicationProtocolType") = 3
'oOptions.Value("Author") = ""
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = ""
'oOptions.Value("Organization") = ""
oSTEPTranslator.SaveCopyAs(doc, oContext, oOptions, oData)
ExportToSTEP = True
End If
End Function
Function GetFolder() As String
'Imports System.Windows.Forms
Dim oSFolder As String
Dim oFDialog As New System.Windows.Forms.FolderBrowserDialog
oFDialog.Description = "SELECT DIRECTORY TO SAVE STEP FILES IN."
oFDialog.RootFolder = System.Environment.SpecialFolder.MyComputer
Dim oResult As DialogResult = oFDialog.ShowDialog()
If oResult = DialogResult.OK Then
oSFolder = oFDialog.SelectedPath
Else
Return String.Empty
End If
Return oSFolder
End Function
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes, i think i might have sent you a private message for help ![]()
Code works perfectly, thanks for the help