Message 1 of 4
Derive and Save As STEP Issues
Not applicable
02-10-2014
01:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone,
Im using the code below to derive my assembly to a single part and then save that as a STEP file. However i have run into a few difficulties.
1) For some reason the derivied part includes any suppressed components when it is created. is there an option to prevent this?
2) Is there a way to have the File Name different to the original file name? for example i would like to save the .stp file as the iProperties "Part Number". I have played around with this and can't seem to get it to work.
Any Help is appreciated.
Dan
'set a reference to the assembly component definintion.
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define the path and file name
Dim sPathandName as String
sPathandName = ThisDoc.PathAndFileName(False)
' Create a new part file to derive the selected part into
'note: kPartDocumentObject is the default template
'you could specifiy a path and file name for a custom template
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
'create the derived assembly deffinition
Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(sPathandName & ".iam")
'Set derive style options
oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsSingleBodyWithSeams
'options:
'kDeriveAsSingleBodyWithSeams
'kDeriveAsSingleBodyNoSeams
'kDeriveAsMultipleBodies
'kDeriveAsWorkSurface
'Create the derived part
Dim oDerivedAssembly As DerivedAssemblyComponent
oDerivedAssembly = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
'- - - - - - - - - - - - - - - - save *.stp file- - - - - - - - - - - - - - - - - - - - - - - - - - -
' 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 = sPathandName & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
End If
'- - - - - - - - - - - - end of *.stp file code - - - - - - - - - - - - - - - - - - - - - - - - -
'close the derived part without saving
oPartDoc.Close(True) 'True set's the skipsave boolean variant
MessageBox.Show("STP file created: " & sPathandName & ".stp", "iLogic")
