Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find all holes in idw and set their layer through VBA

1 REPLY 1
Reply
Message 1 of 2
insomnix
522 Views, 1 Reply

Find all holes in idw and set their layer through VBA

Just as the title states. I want to change the layer of every hole in an idw to the holes layer. This idw will iterate through a factory and export to individual files that will then be imported into another program for the machines to make the parts. My code is long, so I will place the portion that I am working on:

 

        If createProgram = "Y" Then
            oMemberProgramTemplate = oRow.Item(iProgramTemplateColumnIndex).Value
            If Len(Dir(templatesfileLocation & oMemberProgramTemplate & ".idw")) > 0 Then
                'get the drawing template
                Set oDrawingDoc = ThisApplication.Documents.Open(templatesfileLocation & oMemberProgramTemplate & ".idw")
                Set oSheet = oDrawingDoc.ActiveSheet
                
                Dim oHoleLayer As Layer
                oHoleLayer = oDrawingDoc.StylesManager.Layers.Item("holes")
    
                'get the drawing view
                Dim oViewDin As DrawingView
                For Each oViewDin In oSheet.DrawingViews
                    Select Case oViewDin.Name
                        Case "ALPHA"
                            Call oViewDin.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(ipartsfileLocation & oMemberFile)
                            'Dim oHoles As HoleFeatures
                            oViewDin.IsRasterView = False
                        Case Else
                        
                    End Select
                Next
        
                'save copy as one new idw using the member name in the prints folder
                Call oDrawingDoc.SaveAs(printsfileLocation & oMemberName & ".dwg", True)
                Call oDrawingDoc.Close
            End If
        End If

 As you can probably see I am changing the view in the select statement, and it is here I believe the holes should be found and the layer set. I have already created a variable, oHoleLayer, that I need to apply to the holes. Size of the holes do not matter, the importing program will detect the size, I just need to tell the program to drill those holes by setting them to that layer.

1 REPLY 1
Message 2 of 2
insomnix
in reply to: insomnix

I've made some progress, but now I'm running into another problem. "Case 5124" does return all the circles, but it is also grabbing a few lines. There does not appear to be any reason why these lines are changing layer's but I would apprecieate any insite. I have attached a snapshot of what the exported dwg looks like.

 

        If createProgram = "Y" Then
            oMemberProgramTemplate = oRow.Item(iProgramTemplateColumnIndex).Value
            If Len(Dir(templatesfileLocation & oMemberProgramTemplate & ".idw")) > 0 Then
                'get the drawing template
                Set oDrawingDoc = ThisApplication.Documents.Open(templatesfileLocation & oMemberProgramTemplate & ".idw")
                Set oSheet = oDrawingDoc.ActiveSheet
                
                Set oHoleLayer = oDrawingDoc.StylesManager.Layers.Item("holes")

                'get the drawing view
                Dim oViewDin As DrawingView
                For Each oViewDin In oSheet.DrawingViews
                    Select Case oViewDin.Name
                        Case "ALPHA"
                            Call oViewDin.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(ipartsfileLocation & oMemberFile)
                            oViewDin.IsRasterView = False
                            
                            Set oDrawViewCurves = oViewDin.DrawingCurves()
                            For Count = 1 To oDrawViewCurves.Count
                                Set oCircularCurve = oDrawViewCurves.Item(Count)
                                Select Case oCircularCurve.CurveType
                                    Case 5121:
                                        'Debug.Print "Unknown curve type."
                                    Case 5122:
                                        'Debug.Print "Line curve."
                                    Case 5123:
                                        'Debug.Print "Line segment curve."
                                    Case 5124:
                                        'Debug.Print "Circular curve."
                                        For Each oSEG In oCircularCurve.Segments
                                            oSEG.Layer = oHoleLayer
                                        Next oSEG
                                    Case 5125:
                                        'Debug.Print "Circular arc curve."
                                    Case 5126:
                                        'Debug.Print "Ellipse full curve."
                                    Case 5127:
                                        'Debug.Print "Elliptical arc curve."
                                    Case 5128:
                                        'Debug.Print "B-spline curve."
                                End Select
                            Next
                        Case Else
                        
                    End Select
                Next
        
                'save copy as one new idw using the member name in the prints folder
                Call oDrawingDoc.SaveAs(printsfileLocation & oMemberName & ".dwg", True)
                Call oDrawingDoc.Close
            End If
        End If

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report