03-29-2021
03:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-29-2021
03:34 AM
Hello
I don't have Factory Design Utilities installed, so I can't test it. Maybe it runs anyway.
AddReference "Autodesk.Factory.PublicAPI.dll"
Imports Autodesk.Factory.PublicAPI.Currency.v2
Sub Main()
' Update ID Number
' Item Number = ID Number
Dim oDoc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM
oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
' Set the Row Merge Settings
oBOM.SetPartNumberMergeSettings(False)
Dim oBOMRow As BOMRow
For Each oBOMRow In oBOMView.BOMRows
'Set a reference to the primary ComponentDefinition of the row
Dim oCompDef As ComponentDefinition
oCompDef = oBOMRow.ComponentDefinitions.Item(1)
Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
Dim CompFileNameOnly As String
Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
CompFileNameOnly = CompFullDocumentName.Substring(index + 1)
Try
ItemNumber = oBOMRow.ItemNumber
Parameter(CompFileNameOnly, "ID_Number") = ItemNumber
Catch
End Try
If IsFactoryInstance(oDoc, oCompDef.Document, factoryInstance)) Then
ChangeAssetTag(oDoc, oCompDef.Document, factoryInstance)
End if
Next
iLogicVb.UpdateWhenDone = True
End Sub
'Use this Function To see If the models are Assets
Function IsFactoryInstance(layoutDoc As Document, oDoc As Document, ByRef factoryInstance As IAssetInstance)
Dim instances = Autodesk.Factory.PublicAPI.API.Instance.GetAssetInstances(layoutDoc)
Dim found as Boolean=False
For Each instance In instances
If instance.NativeObject.Definition.Document.Equals(oDoc) Then
factoryInstance = instance
found=true
Exit For
End If
Next
Return found
End Function
'The public subroutine will allow the editing of Asset Tags
Public Sub ChangeAssetTag(layoutDoc As Document, oDoc As Document, Asset_Instance As IAssetInstance)
For Each grp In Asset_Instance.PropertyGroups
If grp.Name = "AssetTag" Then
For Each prop In grp.Properties
If prop.Name = "Asset Tag" Then
New_Value = Parameter(oDoc.Name, "ID_Number") & " - " & iProperties.Value(oDoc.Name, "Project" ,"Part Number")
prop.Value = New_Value
End If
Next
End If
Next
'After changed some value, you need To update the instance
Dim ins() As IAssetInstance={Asset_Instance}
Autodesk.Factory.PublicAPI.API.Instance.UpdateAssetInstances(layoutDoc,ins)
End Sub
R. Krieg
RKW Solutions
www.rkw-solutions.com