- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am looking for a code that will add up the mass of certain content center components only and add them to a total that will be displayed to the user. I am not very well versed in coding so any help that can be provided would be great. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @ober2558 . The dMassCC parameter (line 6) is the total mass of all components from the content center.
Sub Main()
Dim oDoc As Document = ThisDoc.Document
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
Dim dMassCC As Double
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
If TypeOf oRefDoc Is AssemblyDocument Then Continue For
Dim iQTy As Integer = oOccs.AllReferencedOccurrences(oRefDoc).Count
If iQTy = 0 Then Continue For
If Not oRefDoc.ComponentDefinition.IsContentMember Then Continue For
dMassCC += oRefDoc.ComponentDefinition.MassProperties.Mass * iQTy
Next
MessageBox.Show(dMassCC & " kg")
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you! This code seems to work well, but I am looking for something that will only take the mass of specific content center parts within a document (i.e. take the mass of CC Part 1 and 3 but not CC Part 2)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In order for the program not to count specific components, it is necessary to somehow explain it to it. For example: for each CC component, a message will appear with the question "Calculate the mass of the component: CC Part 2" (Yes/No), or in the code, create a list with the names of components that do not need to be calculated (for this you need all the names of the components) or you can specify a specific characteristic that you need bolts only.
First, explain how you want the code to work.
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @ober2558,
You could do as folowing :
Sub Main
Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
Dim occs As ComponentOccurrences = doc.ComponentDefinition.Occurrences
Dim mass As Double
For Each refDoc As Document In doc.AllReferencedDocuments
If TypeOf refDoc Is AssemblyDocument Then Continue For
Dim qty As Integer = occs.AllReferencedOccurrences(refDoc).Count
If Not refDoc.ComponentDefinition.IsContentMember Then Continue For
Dim list As New List(Of String)
list.Add("ISO 4032 M12")
list.Add("ISO 4032 M10")
list.Add("ISO 4032 M16")
If list.Contains(refDoc.DisplayName) = False Then Continue For
mass += refDoc.ComponentDefinition.MassProperties.Mass * qty
Next
MessageBox.Show(mass & " kg")
End SubSimply change the names in the list.add(name) method.
You can add more lines if desired.
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code works well, except the files I am looking to use for this list are under the structural shape category and I have them set up with a user input length. This user input length is then added to the name of the file and therefore variable. (i.e. if 50mm is chosen, the name will be X 25-25 Profile 50, if 100mm is chosen, the name will be X 25-25 Profile 100) So therefore this code will not work entirely unless I manually input the names of each 1 mm variation. I can do this but I believe it will take more time than its worth. Is there a way to add them by "Name contains ___" such as "X 25-25 Profile" committing the variable length? If you need more clarification let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What about this one? I used your exemple. The code will check if the document name contains the input words you specify in the list :
Sub Main
Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
Dim occs As ComponentOccurrences = doc.ComponentDefinition.Occurrences
Dim mass As Double
For Each refDoc As Document In doc.AllReferencedDocuments
If TypeOf refDoc Is AssemblyDocument Then Continue For
If Not refDoc.ComponentDefinition.IsContentMember Then Continue For
Dim list As New List(Of String)
list.Add("X 25-25 Profile")
Dim check As Boolean = False
For Each s As String In list
If refDoc.DisplayName.Contains(s) Then
check = True
Exit For
End If
Next
If check = False Then Continue For
Dim qty As Integer = occs.AllReferencedOccurrences(refDoc).Count
mass += refDoc.ComponentDefinition.MassProperties.Mass * qty
Next
MessageBox.Show(mass & " kg")
End SubKind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report