Make a STEP of the model on the working drawing

Make a STEP of the model on the working drawing

FeelGoodGirl
Advocate Advocate
481 Views
4 Replies
Message 1 of 5

Make a STEP of the model on the working drawing

FeelGoodGirl
Advocate
Advocate

Hey,

I'm trying to make something, but I don't really know if it's possible or how.

 

My work process is as follows. First I make a model with the drawings. When that's all done, I'll need to make the STEP and PDF. For the PDF I use the working drawings and for the STEP I have to open the model. Now I want to make a iLogic rule thats make a STEP of the model thats is on the drawings. Then I would only have to open the working drawing to make the STEP and PDF.

 

Is this possibly?

0 Likes
Accepted solutions (1)
482 Views
4 Replies
Replies (4)
Message 2 of 5

theo.bot
Collaborator
Collaborator

Here's a sample that you could use. I manipulated my export to step rule for you. Instead of working with the part document i take the first model from the drawing.

 
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

oPath = ThisDoc.Path
oFolder = oPath & "\Step"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim modelDoc = ThisDrawing.ModelDocument


If oSTEPTranslator.HasSaveCopyAsOptions(modelDoc, 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
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = oFolder & "\" & ThisDoc.FileName(False) & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
End If

 You might need to add some error checks, but the code works. 

0 Likes
Message 3 of 5

FeelGoodGirl
Advocate
Advocate

Thank you for your responds.

 

I have tried the code. A STEP file is created, but it is empty....

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @FeelGoodGirl.  Here is a different version of the code to export the drawing's model out to a STEP file you can try.  This attempts to save the STEP file with the same path & file name as the model, but with the ".stp" file extension.

 

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument

	'get the 'Model' document
	If oDDoc.AllReferencedDocuments.Count = 0 Then
		MsgBox("This drawing is not currently referencing any other documents.  Exiting.", vbInformation, "iLogic")
		Exit Sub
	End If
	'Dim oModel As Document = oDDoc.AllReferencedDocuments.Item(1)
	For Each oModel As Document In oDDoc.AllReferencedDocuments
		If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Or _
			oModel.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			'run our custom Sub below on it
			ExportToSTEP(oModel)
		End If
	Next
End Sub

Sub ExportToSTEP(oModelDoc As Document)
	'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

	'specify full file name of new STEP file it is to create
	'this will keep full path & file name of model, but with ".stp" file extension
	oNewFile = System.IO.Path.ChangeExtension(oModelDoc.FullFileName, ".stp")
	
	'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(oNewFile) 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 = oNewFile

	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

 

 

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 5 of 5

FeelGoodGirl
Advocate
Advocate

That works! Super thanks.

0 Likes