export STEP of assembly parts

export STEP of assembly parts

FeelGoodGirl
Advocate Advocate
955 Views
3 Replies
Message 1 of 4

export STEP of assembly parts

FeelGoodGirl
Advocate
Advocate

Hey,

 

I don't know if it can done what I'm trying to achieve.

 

If you have a assembly, it consists of different parts. Now I open these parts 1 by 1 to export a STEP of it. This takes of course quite some time. Is there a possibility to export these at once when you have the assmebly open? Or, even beter, if you have the drawing open of the assembly?

0 Likes
Accepted solutions (1)
956 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @FeelGoodGirl.  It can definitely be done.  Have you tried searching for this solution within the main search box of this forum?  It sounds like one that has been discussed several times before.  Exporting model files to STEP format is probably the most popular format for sharing 3D CAD data, so it has been a popular task to automate.  Please specify which of these scenarios you would like to use the most, and I'm sure we can come up with something to suit your needs.  Also please specify the details of the task.  Where do you want the new files to be created?  How do you want the new files to be named?  Do you want to also export the main assembly as a STEP file?  Do you want to export any of the sub-assemblies as STEP files, or only parts?  If you have sub-assemblies within your main assembly, how many levels deep do you want this code to go down through sub-assemblies, and sub-assemblies of sub-assemblies?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Here is one variation of an iLogic rule that will export the main assembly, and each of the referenced model files within out to STEP files.  It saves the new STEP files to the same location the model file is at, and gives them the same file name as the model file, except the file extension is now ".stp".  It also sets most of the settings within the translator to certain values.  You may want to change those if they don't meet your needs.

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	
	oAssemSTEP = System.IO.Path.ChangeExtension(oADoc.FullFileName, ".stp")
	ExportToSTEP(oADoc, oAssemSTEP)
	
	For Each oRefDoc As Document In oADoc.AllReferencedDocuments
		'only export it to STEP if it's either an Assembly or a Part
		If oRefDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
			oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
			Continue For
		End If
		oNewName = System.IO.Path.ChangeExtension(oRefDoc.FullFileName, ".stp")
		ExportToSTEP(oRefDoc, oNewName)
	Next
End Sub

Sub ExportToSTEP(oDoc As Document, oNewFullFileName 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

	'Check to see if the STEP file already exists, if it does, ask if you want to overwrite it or not.
	If System.IO.File.Exists(oNewFullFileName) Then
		oAns = MsgBox("A STEP file with this name already exists." & vbCrLf &
		"Do you want to overwrite it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "STEP FILE EXISTS")
		If oAnswer = vbNo Then Exit Sub
	End If
	oDataMedium.FileName = oNewFullFileName

	If oSTEP.HasSaveCopyAsOptions(oDoc, 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") = iProperties.Value("Summary", "Title")
		 oOptions.Value("Organization") = iProperties.Value("Summary", "Company")
		Try
			 oSTEP.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
		Catch
			MsgBox("Your attempt to export this document as a STEP file FAILED!", vbOKOnly + vbExclamation, "Export to STEP Error")
		End Try
	End If
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

FeelGoodGirl
Advocate
Advocate

Hi @WCrihfield ,

Thank you for your comment.

I've searched, but couldn't really find anything about it. I will dig in even longer next time. But the code you sent does what I want. Thank you!

0 Likes