Need help modifying an iLogic rule

Need help modifying an iLogic rule

Anonymous
Not applicable
747 Views
10 Replies
Message 1 of 11

Need help modifying an iLogic rule

Anonymous
Not applicable

Hello to all:

 

I need help modifying an iLogic rule, if possible.

 

This current rule suppresses all the features that contain "Control_Side" in their names.

 

SyntaxEditor Code Snippet

Sub Main()

    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
    Dim oUniqueOccurrencesFileNames As New List(Of String)()
    Dim oUniqueOccurrencesDefs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
    For Each oThing As ComponentOccurrence In oAsmDef.Occurrences
        If Not oUniqueOccurrencesFileNames.Contains(oThing.Definition.Document.FullFileName) Then
            oUniqueOccurrencesFileNames.Add(oThing.Definition.Document.FullFileName)
            oUniqueOccurrencesDefs.Add(oThing.Definition)
        End If
    Next
    
    Dim oStringToFilter As String = "Control_Side" ''' Make this whatever
    
    For Each oThing As ComponentDefinition In oUniqueOccurrencesDefs
        For Each oFeature As PartFeature In oThing.Features
            If oFeature.Name.ToUpper.Contains(oStringToFilter.ToUpper) Then
                oFeature.Suppressed = True
            End If
        Next
    Next
    InventorVb.DocumentUpdate()

End Sub

 

I need the rule to be changed; I now need this Rule to run in the Inventor Drawing (.idw) environment instead, and all the features to be placed on the Inventor drawing layer called "power_breaks".

 

I'm pretty sure that this is the line needs to be changed : 

oFeature.Suppressed = True

Can someone edit this for me?  I'd greatly appreciate it.  Thanks in advance! 

0 Likes
Accepted solutions (1)
748 Views
10 Replies
Replies (10)
Message 2 of 11

mcgyvr
Consultant
Consultant

So let me clarify..

You want a rule that you can run in the drawing environment that looks at all the views (and on every sheet?) and if it finds a part with features named "Control_Side" you want that linework to be put onto a layer that you have already created in the template called "power_breaks"?

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 11

Curtis_Waguespack
Consultant
Consultant

@mcgyvr wrote:

So let me clarify..

You want a rule that you can run in the drawing environment that looks at all the views (and on every sheet?) and if it finds a part with features named "Control_Side" you want that linework to be put onto a layer that you have already created in the template called "power_breaks"? 

 


 Hi @Anonymous,


mcgyvr's synopsis is what I understood the request to be as well. 

 

Working with the linework (called curves in inventor's API) gets pretty involved quickly, so I think it will be quite a bit more code to handle getting the linework to a layer, and since you're doing this from a drawing, looking through the assembly, through the part, at the features, I think it will require a lot of proxies. 

 

So this goes far beyond iLogic and gets heavily into the API, and for that reason I've asked the forum admins to move this post to the Inventor Customization forum where it will get the right audience:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 4 of 11

Anonymous
Not applicable

If it will involve that much work I'd consider it to be a paying gig to anyone who's reading this...

0 Likes
Message 5 of 11

Anonymous
Not applicable

According to this message from several years ago, what I want seems plainly possibe:

 

https://forums.autodesk.com/t5/inventor-customization/macro-to-put-specific-named-features-on-specif...

 

"...I'm wondering if there's a way to automate this: Select all edges, in an idw, of any part feature containing "Control_Side" and set these to a specific layer...."

 

The response was: "Use  the DrawingCurves(ModelObject) to get all the edges you want, and then use the Sheet.ChangeLayer to change the layer for the drawing curves."

 

I simply don't know how to do this, but I really need this functionality BADLY.  Can someone write the full code for me?  Thanks in advance!

0 Likes
Message 6 of 11

MechMachineMan
Advisor
Advisor

VBA (Because it's easier to debug)

Sub Main()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then: Exit Sub
    Dim oDwgDoc As DrawingDocument
    Set oDwgDoc = ThisApplication.ActiveDocument
    
    Dim oStringToFilter As String
    Dim oFilterLayerName As String
    
    oStringToFilter = "Control_Side" ''' Make this whatever
    oFilterLayerName = "power_breaks"
    
    Dim oNewLayer As Layer
    Set oNewLayer = oDwgDoc.StylesManager.Layers.Item(oFilterLayerName)
    If oNewLayer Is Nothing Then
        Call MsgBox("Layer Not Found! Please fix." & vbLf & vbLf & "Aboring Rule.", , "MacroMagic")
        Exit Sub
    End If

    Dim oRefDoc As Document
    For Each oRefDoc In oDwgDoc.AllReferencedDocuments
        If oRefDoc.DocumentType = kPartDocumentObject Then
            Dim oPCD As PartComponentDefinition
            Set oPCD = oRefDoc.ComponentDefinition
            
            Dim oFeature As PartFeature
            For Each oFeature In oPCD.Features
                
                'If feature name contains....
                If InStr(UCase(oFeature.Name), UCase(oStringToFilter)) <> 0 Then
                'If oFeature.Name.ToUpper.Contains(oStringToFilter.ToUpper) Then
                    Call SetPartToLayer(oDwgDoc, oRefDoc, oNewLayer)
                End If
            Next
        End If
    Next
End Sub

Sub SetPartToLayer(oDwgDoc As DrawingDocument, oRefDoc As Document, oDestinationLayer As Layer)
    Dim oSheet As Sheet
    For Each oSheet In oDwgDoc.Sheets
    
        Dim oCurveColl As ObjectCollection
        Set oCurveColl = ThisApplication.TransientObjects.CreateObjectCollection
        
        Dim oView As DrawingView
        For Each oView In oSheet.DrawingViews
        
            Set oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
            If oViewDoc.DocumentType = kAssemblyDocumentObject Then
                
                For Each oRefOcc In oViewDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
                    Dim oDrawingCurves As DrawingCurvesEnumerator
                    Set oDrawingCurves = oView.DrawingCurves(oRefOcc)
                    
                    'oCurveColl.Add(oDrawingCurves)
                    
                    For Each oCurve In oDrawingCurves
                        For Each oSegment In oCurve.Segments
                            Call oCurveColl.Add(oSegment)
                        Next 'Segment
                    Next 'Curve
                Next ' oOcc
                
            End If
        Next 'View
        
        Call oSheet.ChangeLayer(oCurveColl, oDestinationLayer)
        oCurveColl.Clear
    
    Next 'Sheet
End Sub

VB.net (iLogic rule)

Sub Main()
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then: Exit Sub: End If
    Dim oDwgDoc As DrawingDocument
    oDwgDoc = ThisApplication.ActiveDocument
    
    Dim oStringToFilter As String
    Dim oFilterLayerName As String
    
    oStringToFilter = "Control_Side" ''' Make this whatever
    oFilterLayerName = "power_breaks"
    
    Dim oNewLayer As Layer
    oNewLayer = oDwgDoc.StylesManager.Layers.Item(oFilterLayerName)
    If oNewLayer Is Nothing Then
        Call MsgBox("Layer Not Found! Please fix." & vbLf & vbLf & "Aboring Rule.", , "MacroMagic")
        Exit Sub
    End If

    Dim oRefDoc As Document
    For Each oRefDoc In oDwgDoc.AllReferencedDocuments
        If oRefDoc.DocumentType = kPartDocumentObject Then
            Dim oPCD As PartComponentDefinition
            oPCD = oRefDoc.ComponentDefinition
            
            Dim oFeature As PartFeature
            For Each oFeature In oPCD.Features
                
                'If feature name contains....
                If InStr(UCase(oFeature.Name), UCase(oStringToFilter)) <> 0 Then
                'If oFeature.Name.ToUpper.Contains(oStringToFilter.ToUpper) Then
                    Call SetPartToLayer(oDwgDoc, oRefDoc, oNewLayer)
                End If
            Next
        End If
    Next
End Sub

Sub SetPartToLayer(oDwgDoc As DrawingDocument, oRefDoc As Document, oDestinationLayer As Layer)
    Dim oSheet As Sheet
    For Each oSheet In oDwgDoc.Sheets
    
        Dim oCurveColl As ObjectCollection
        oCurveColl = ThisApplication.TransientObjects.CreateObjectCollection
        
        Dim oView As DrawingView
        For Each oView In oSheet.DrawingViews
        
            oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
            If oViewDoc.DocumentType = kAssemblyDocumentObject Then
                
                For Each oRefOcc In oViewDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
                    Dim oDrawingCurves As DrawingCurvesEnumerator
                    oDrawingCurves = oView.DrawingCurves(oRefOcc)
                    
                    'oCurveColl.Add(oDrawingCurves)
                    
                    For Each oCurve In oDrawingCurves
                        For Each oSegment In oCurve.Segments
                            Call oCurveColl.Add(oSegment)
                        Next 'Segment
                    Next 'Curve
                Next ' oOcc
                
            End If
        Next 'View
        
        Call oSheet.ChangeLayer(oCurveColl, oDestinationLayer)
        oCurveColl.Clear
    
    Next 'Sheet
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 11

Anonymous
Not applicable

Hello Justin:

 

Thanks very much for your generous reply.  Unfortunately, the code is moving ALL the geometry to the requested layer, not just the Control_Side.  Any further thoughts?

0 Likes
Message 8 of 11

MechMachineMan
Advisor
Advisor

Yes, that's the expected behavior from how I programmed it. Did not realize that you only wanted the feature swapped over. Looks like it should be doable with a quick code change.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 11

Anonymous
Not applicable

Great!  Thanks, I look forward to updated code.  BTW do you have Paypal?

0 Likes
Message 10 of 11

MechMachineMan
Advisor
Advisor
Accepted solution

I couldn't seem to tweak the other code to recognize the feature in a part in an assembly in the view, so I went with this instead:

 

'Vb.net

Sub Main()
    Dim oDwgDoc As Document
    oDwgDoc = ThisApplication.ActiveDocument
    
    oFeatureName = "Control_Side"
    oFilterLayerName = "power_breaks"
    
    Dim oNewLayer As Layer
    oNewLayer = oDwgDoc.StylesManager.Layers.Item(oFilterLayerName)
    If oNewLayer Is Nothing Then
        Call MsgBox("Layer Not Found! Please fix." & vbLf & vbLf & "Aboring Rule.", , "MacroMagic")
        Exit Sub
    End If
    
    
    For Each oSheet In oDwgDoc.Sheets
        Dim oCurveColl As ObjectCollection
        oCurveColl = ThisApplication.TransientObjects.CreateObjectCollection
    
        For Each oView In oSheet.DrawingViews
            For Each oCurve In oView.DrawingCurves
                oModelGeo = oCurve.ModelGeometry
                
                If oModelGeo.Type = 67119520 Then 'Variant/Object/FaceProxy
                Else
                        For Each oFace In oModelGeo.Faces
                            If UCase(oFace.CreatedByFeature.Name) = UCase(oFeatureName) Then
                                For Each oSegment In oCurve.Segments
                                    Call oCurveColl.Add(oSegment)
                                Next
                            End If
                        Next
                End If
            Next 'curve
        Next 'view
        
        Call oSheet.ChangeLayer(oCurveColl, oNewLayer)
        oCurveColl.Clear
    Next 'sheet
End Sub

 

'vba

Sub Main() Dim oDwgDoc As Document Set oDwgDoc = ThisApplication.ActiveDocument oFeatureName = "Control_Side" oFilterLayerName = "power_breaks" Dim oNewLayer As Layer Set oNewLayer = oDwgDoc.StylesManager.Layers.Item(oFilterLayerName) If oNewLayer Is Nothing Then Call MsgBox("Layer Not Found! Please fix." & vbLf & vbLf & "Aboring Rule.", , "MacroMagic") Exit Sub End If For Each oSheet In oDwgDoc.Sheets Dim oCurveColl As ObjectCollection Set oCurveColl = ThisApplication.TransientObjects.CreateObjectCollection For Each oView In oSheet.DrawingViews For Each oCurve In oView.DrawingCurves Set oModelGeo = oCurve.ModelGeometry If oModelGeo.Type = 67119520 Then 'Variant/Object/FaceProxy Else For Each oFace In oModelGeo.Faces If UCase(oFace.CreatedByFeature.Name) = UCase(oFeatureName) Then For Each oSegment In oCurve.Segments Call oCurveColl.Add(oSegment) Next End If Next End If Next 'curve Next 'view Call oSheet.ChangeLayer(oCurveColl, oNewLayer) oCurveColl.Clear Next 'sheet End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 11 of 11

Anonymous
Not applicable

AAAAGH Awesome thanks so much! Smiley Very HappySmiley Very HappySmiley Very Happy

0 Likes