- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone, I've tried searching but I can't find a solution to my problem. I need to create a rule that checks if, in my assembly (only first level), there is a Virtual Part with the same name as the assembly.
thank
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @tecnico. Here is something you can try for that task. First, it makes sure it is working with an assembly (not a part or drawing). Then it gets the components collection. Then iterates through them, skipping any that are suppressed, and if a 'virtual' one is found, it compares the first part of that components name to the DisplayName of the main assembly. If a match is found, a message will pop-up and let you know.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For 'cant access Definition if Suppressed
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then
If oOcc.Name.StartsWith(oADoc.DisplayName) Then
MsgBox("Found a Virtual component with same name as main assembly.", vbInformation, "iLogic")
End If
End If
Next 'oOcc
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, thank you for the response. I tried the rule you wrote, but I don't get any effect. I created a virtual part with the same name as the assembly from which I launch it, the rule runs but nothing happens. Rather than the assembly name, I would need it to look at the part number though.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @tecnico. OK. Here is a slightly different version of the code, but this version compares the Part Number of the main assembly to the Part Number of the virtual component. And also uses a Boolean to let you know if no match was found after the loop.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim sAssemblyPN As String = oADoc.PropertySets.Item(3).Item(2).Value
Dim bFound As Boolean = False
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For 'cant access Definition if Suppressed
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then
Dim oVCD As VirtualComponentDefinition = oOcc.Definition
Dim sVOccPN As String = oVCD.PropertySets.Item(3).Item(2).Value
If sVOccPN.Equals(sAssemblyPN, StringComparison.CurrentCultureIgnoreCase) Then
bFound = True
MsgBox("Found a Virtual component with same Part Number as main assembly.", vbInformation, "iLogic")
End If
End If
Next 'oOcc
If bFound = False Then
MsgBox("Did not find a Virtual component with same Part Number as main assembly.", vbInformation, "iLogic")
End If
End Sub
Wesley Crihfield
(Not an Autodesk Employee)