STEP Conversion based on File

STEP Conversion based on File

RNDinov8r
Collaborator Collaborator
1,114 Views
5 Replies
Message 1 of 6

STEP Conversion based on File

RNDinov8r
Collaborator
Collaborator

So, I stumbled upon this genius little code snippet which is included in Inventor.

' 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

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

Based on my playing around with it, if I set it to trigger on an event, say, "After Save", it only creates/updates the step file if it does not exist or the part has changed. This is exactly the behavior I am looking for.  I have saved this code to an external rule (see above). My only change is that we save to "STEP", and not "STP"...so I tweaked that code.

 

I am wondering is there a way to run this so that If I apply this external rule to both Parts and Assemblies, that I can save to STEP based on the Part number "scheme"?

 

We have M, A, P, C, & Z numbers. so they would be for example:

M10001234.ipt

A10000246.iam

P10003579.ipt/.iam

C10002468.ipt/.iam

Z10003142.iam

 

Because C & Z, can be .iam files I could apply this accross the board, however, I don't want to convert P or A numbers to STEP files. A-numbers could be massive assemblies...so on the fly conversion would be major time suck. And we don't need P-Numbers as STEP files, since those are purchased parts and we don't send neutral files of those to our vendors.

 

So is it possible to modify the code to say If FileName starts with "M", "C", or "Z" that it converts, otherwise it ignores the coversion?

0 Likes
Accepted solutions (3)
1,115 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

You mean like:

If filename.contains(M) or filename.contains(A) then

Do this

Else

Do that 

End if

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 6

RNDinov8r
Collaborator
Collaborator

Yes, I beleive so, specifically:

 

If filename.contains(M) or filename.contains(C) or filename.contains(Z) then

"Convert to STEP"

Else

"Do Nothing"

End if

0 Likes
Message 4 of 6

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Try this:

Public Sub Main'(oThisApplication As Inventor.Application,oThisDoc As thisdo)
' Get the STEP translator Add-In.

If ThisDoc.FileName.Contains("M") Or ThisDoc.FileName.Contains("C") Or ThisDoc.FileName.Contains("Z") Then
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
'MsgBox (osteptranslator.Description)
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
'MsgBox (oContext.Type)
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'MsgBox (ThisDoc.FileName)
If oSTEPTranslator.HasSaveCopyAsOptions(ThisDoc.Document, oContext, oOptions) Then
'MsgBox (Thisapplication.ActiveDocument.PathAndFileName)
    ' 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 Inventor.DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
	MsgBox ("")
    'oData.FileName = ThisDoc.PathAndFileName(False) & ".step"
	oData.FileName = ThisDoc.ChangeExtension("step") '& ".step"
	msgbox (odata.FileName)
oSTEPTranslator.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oData)
End If
End If
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

I was going to suggest leaving that block of code as it's own separate Sub, then simply having a conditional check in you main code, that controls when to call it, like this:

Sub Main
	Dim oFName As String = ThisDoc.FileName(False)
	If oFName.StartsWith("M") Or oFName.StartsWith("C") Or oFName.StartsWith("Z") Then
		ExportStep
	End If
End Sub

Sub ExportStep()
	' Get the STEP translator Add-In.
	Dim oSTEPTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oContext As TranslationContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oOptions As NameValueMap = oTO.CreateNameValueMap
	Dim oData As DataMedium = oTO.CreateDataMedium
	oData.FileName = ThisDoc.PathAndFileName(False) & ".step"

	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") = ""
		oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
	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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

bradeneuropeArthur
Mentor
Mentor
Accepted solution

@RNDinov8r 
The base code was giving an error on different points, so I have modified it a bit to a more working code.

Maybe you we can combine them!

Sub Main
	Dim oFName As String = ThisDoc.FileName(False)
	If oFName.StartsWith("M") Or oFName.StartsWith("C") Or oFName.StartsWith("Z") Then
		ExportStep
	End If
End Sub

'Sub ExportStep()

Public Sub ExportStep'(oThisApplication As Inventor.Application,oThisDoc As thisdo)
' Get the STEP translator Add-In.

'If ThisDoc.FileName.Contains("M") Or ThisDoc.FileName.Contains("C") Or ThisDoc.FileName.Contains("Z") Then
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
'MsgBox (osteptranslator.Description)
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
'MsgBox (oContext.Type)
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'MsgBox (ThisDoc.FileName)
If oSTEPTranslator.HasSaveCopyAsOptions(ThisDoc.Document, oContext, oOptions) Then
'MsgBox (Thisapplication.ActiveDocument.PathAndFileName)
    ' 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 Inventor.DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
	MsgBox ("")
    'oData.FileName = ThisDoc.PathAndFileName(False) & ".step"
	oData.FileName = ThisDoc.ChangeExtension("step") '& ".step"
	msgbox (odata.FileName)
oSTEPTranslator.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oData)
End If
'End If
End Sub

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes