02-25-2021
05:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-25-2021
05:47 AM
Got this working. Here's a little more details on what I'm doing.
The goal is to create a global rule with a button in global forms that:
- In an assembly: Suppress parts or sub-assemblies and corresponding constraints
- In a part: suppress features
- In a drawing: suppress views
This is just a part of the program. I have a main global rule that evaluates the document type and then calls the correct external rule (assembly, part, drawing). The issue was that the rule wouldn't evaluate the correct document while double clicked into a part or sub-assembly (edit in place). Ended up solving this by adding the first "IF" statement. I don't know why this works but it does! Lemme know if you can clue me into the 'why'.
'Set oDoc to active edit document to allow editing of 'edit in place' parts & sub-assemblies
Dim oTest_Doc As Document = ThisApplication.ActiveEditDocument
Dim oDoc As Document
If Not (oTest_Doc Is ThisApplication.ActiveDocument) Then
oDoc = ThisApplication.ActiveDocument
Else
oDoc = ThisDoc.Document
End If
'Set the user selection'
Dim oSelectSet As SelectSet = oDoc.SelectSet
'Toggle parts on or off based upon user selection and current state.
For Each oFeature In oSelectSet
oFeature_Name = oFeature.name
If Feature.IsActive(oFeature_Name) = False Then
Feature.IsActive(oFeature_Name) = True
'MsgBox("part is off - unsuppress it")
ElseIf Feature.IsActive(oFeature_Name) = True Then
Feature.IsActive(oFeature_Name) = False
'MsgBox("part is on - suppress it")
Else
MsgBox("Unable to change feature: " & oFeature_Name)
End If
oMessage = oMessage & " • " & oFeature_Name & vbnewline
Next
'Notify user'
MsgBox ("Changed Suppression States on Parts: " & vbnewline & oMessage)