Hi David, I have been working on some BIM Export automatio and here is my code. I hope this is a good starting point for you.
Public Sub CreateBIM(ThisDoc As AssemblyDocument, Optional ForcePreviewImage As Boolean = False)
Dim _invApp As Inventor.Application
_invApp = ThisDoc.Parent
Dim oDef As AssemblyComponentDefinition
oDef = ThisDoc.ComponentDefinition
'Get file Name of Assembly
Dim BaseFileName As String
BaseFileName = Left(ThisDoc.FullFileName, Len(ThisDoc.FullFileName) - 4)
'If we want to skip this process if the .adsk file already exists, we need to break here
'If BaseFileName & ".adsk" exists then Exit Sub
' Create a new part document that will be the shrinkwrap substitute
Dim oPartDoc As PartDocument
'True/False means Visable/Invisable
'If ForcePreviewImage set to False, there will be no preview in the BIM export (TK's preference)
'If ForcePreviewImage set to True, increased runtime by 18 seconds in test
oPartDoc = _invApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , ForcePreviewImage)
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(ThisDoc.FullDocumentName)
' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedIncludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedIncludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.ReducedMemoryMode = True
Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchAll)
Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemovePartsAndFaces, 25)
' Create the shrinkwrap component
Dim oDerivedAssembly As DerivedAssemblyComponent
oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
'Save the shrinkwapped part
Dim strSubstituteFileName As String
strSubstituteFileName = BaseFileName & "_Shrinkwrap.ipt"
'Saving this file is essential for export to run sucessfully
Call oPartDoc.SaveAs(strSubstituteFileName, False)
'Properties
Dim Description As String
Dim PartNumber As String
Dim ComponentType As String
Dim Manufacturer As String
Dim Model As String
Dim URL As String
'Set properties
Description = "Test"
PartNumber = "Test"
Manufacturer = ""
Model = Right(BaseFileName, 6)
URL = ""
'Release reference to Assembly Doc
ThisDoc = Nothing
'Set Component Type
If Left(Model, 3) = "DFE" Or Left(Model, 3) = "RDE" Then
ComponentType = "23.40.20.17.14.27" 'Nursery/Children's Furniture
ElseIf Model = "UCSDKS"
ComponentType = "23.40.20.24.31" 'Desk
Else
ComponentType = "23.40.20.00" 'General Furniture and Specialties
End If
'Write to the iProperties of the Shrinkwapped Part.
'Part Number needs to be written after file save otherwise will be overwrittem
Dim invPartNoProperty As Object
Dim invDescProperty As Object
invPartNoProperty = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
invDescProperty = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Description")
invPartNoProperty.Value = PartNumber
invDescProperty.Value = Description
'Get Reference BIM Component
Dim oBIM As BIMComponent
oBIM = oPartDoc.ComponentDefinition.BIMComponent
'Write Component Type Definition
'If this line isn't run, the Model Properties tickbox will not get ticked and Model Properties will not get exported
oBIM.ComponentDescription.ComponentType = ComponentType
'Get reference for writting Identity Data
Dim oBimOC As BIMComponentPropertySet
oBimOC = oBIM.ComponentDescription.ComponentPropertySets.Item("Identity Data")
'Write BIM Identity data
'This must be set after 'Write Component Type Definition' otherwise this data will get wiped
Dim BIMDescProp As BIMComponentProperty
Dim BIMManProp As BIMComponentProperty
Dim BIMModelProp As BIMComponentProperty
Dim BIMURLProp As BIMComponentProperty
BIMDescProp = oBimOC.Item(1)
BIMDescProp.Value = Description
BIMManProp = oBimOC.Item(2)
BIMManProp.Value = Manufacturer
BIMModelProp = oBimOC.Item(3)
BIMModelProp.Value = Model
BIMURLProp = oBimOC.Item(4)
BIMURLProp.Value = URL
'Export .adsk file
oBIM.ExportBuildingComponent("INSERT YOUR EXPORT LOCATION AND FILE NAME HERE")
'Close the invisibly opened part document.
'If this document isn't closed or unreferenced, a retry of the code will fail.
oPartDoc.Close(False)
oPartDoc = Nothing
End Sub
Wayne Helley
Inventor 2013 Certified Professional
Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit