VBA IDW Toggle/Turn Off C-Sink Major Diameter

VBA IDW Toggle/Turn Off C-Sink Major Diameter

rcolon9E4ZX
Advocate Advocate
796 Views
7 Replies
Message 1 of 8

VBA IDW Toggle/Turn Off C-Sink Major Diameter

rcolon9E4ZX
Advocate
Advocate

Hello.

 

When we send flat patterns for lasering, we hide hole features to make sure the major diameters are not lasered by mistake. Tapped holes are easy because I can simply toggle 'Thread Feature' for the selected view. The problem lies with countersunk holes. I manually select the major diameter profile of each countersink and set the visibility to OFF. In the image below, I would turn off the red circles.

 

Hide C-Sink Major DiameterHide C-Sink Major Diameter

 

I am looking for a way to automate this off of a base view/selected view. Projected views will remain unaffected. Maybe there is a way to loop through the view or layer Visible (ANSI) and find holes with that have a countersink? I wish I had a little more time to investigate. 

 

Any help with this would be greatly appreciated. Thanks.

Rafael

 

INV PRO 2019.4.3, Win10 64-bit, Build 330

 

0 Likes
Accepted solutions (1)
797 Views
7 Replies
Replies (7)
Message 2 of 8

Michael.Navara
Advisor
Advisor

Hello

This rule hides all biggest edges (circles) of countersunk holes in all drawing views, where  the edge is projected as circle.

You can simply modify this rule to selected drawing view.

 

Sub Main()
HideEdgesInDrawing()
End Sub

Sub HideEdgesInDrawing()
	Dim model As PartDocument = ThisDrawing.ModelDocument
	Dim drawing As DrawingDocument = ThisDrawing.Document

	Dim edges As Edge() = GetHoleEdges(model)

	Dim t As Transaction = ThisApplication.TransactionManager.StartTransaction(drawing, "Hide hole edges")
	Try
		HideEdges(drawing, edges)
		t.End()
	Catch ex As Exception
		t.Abort()
		MsgBox(ex.Message, MsgBoxStyle.Exclamation)
	End Try
End Sub

Private Sub HideEdges(drawing As DrawingDocument, edges As Edge())
	For Each sheet As Sheet In drawing.Sheets
		For Each drawingView As DrawingView In Sheet.DrawingViews
			For Each edge As Edge In edges
				Dim curves As DrawingCurvesEnumerator = DrawingView.DrawingCurves(Edge)
				For Each drawingCurve As DrawingCurve In curves
					For Each segment As DrawingCurveSegment In DrawingCurve.Segments
						If segment.GeometryType = Curve2dTypeEnum.kCircleCurve2d Or
							segment.GeometryType = Curve2dTypeEnum.kCircularArcCurve2d Then
							segment.Visible = False
						End If
					Next
				Next
			Next

		Next
	Next
End Sub

Private Function GetHoleEdges(partDocument As PartDocument) As Edge()
	Dim edges As New List(Of Edge)
	For Each hole As HoleFeature In partDocument.ComponentDefinition.Features.HoleFeatures
		Dim holeEdges As New List(Of Edge)
		Dim radius As Double = 0
		If hole.HoleType <> HoleTypeEnum.kCounterSinkHole Then Continue For

		For Each face As Face In hole.Faces
			For Each edge As Edge In Face.Edges
				If Edge.CurveType <> CurveTypeEnum.kCircleCurve Then Continue For
				Dim circle As Circle = Edge.Geometry
				If Math.Abs(circle.Radius - radius) < 0.001 Then
					holeEdges.Add(Edge)
				ElseIf circle.Radius < radius Then
					Continue For
				ElseIf circle.Radius > radius Then
					holeEdges.Clear()
					holeEdges.Add(Edge)
					radius = circle.Radius
				End If
			Next
		Next
		edges.AddRange(holeEdges)
	Next
	Return edges.ToArray()
End Function

 

example with rule is in attachment.

 

Message 3 of 8

rcolon9E4ZX
Advocate
Advocate

@Michael.Navara ,

 

Really great stuff. I opened your attachment and running the iLogic rule indeed hid the large diameter circles for each countersunk hole. Is this code directly compatible with VBA? I have a VBA utility for exporting all opened drawings as dwg/dxf/pdf and I want to provide a checkbox for toggling this visibility. I will need to turn the visibility back on as well. It looks like you have collected these edges in a list/array, so maybe the list/array can be global instead and then loop through in a sub 'RevealEdges' to turn visibility back on afterward.

 

Thanks.

Rafael

0 Likes
Message 4 of 8

Michael.Navara
Advisor
Advisor
Accepted solution

This code is NOT directly compatible with VBA, because I use .NET collection List(Of Edge). You need to modify this code to VBA by replacing this with another collection. For eaxample Inventor.ObjectCollection. 

My code for hiding edges is enclosed in one transaction for single undo step.

Or you can show all hidden entities by DrawingView.ShowHiddenCurves()  method.

Message 5 of 8

rcolon9E4ZX
Advocate
Advocate

@Michael.Navara ,

 

Thank you for the assistance. I will take some time to work on the VBA adaptation and post when it is ready.

 

Thank you.

Rafael

0 Likes
Message 6 of 8

rcolon9E4ZX
Advocate
Advocate

@Michael.Navara ,

 

I am taking another look at this. I modified your code to include counterbore holes too [below]. The code works until it gets to holes within a pattern. Any idea how to include those as well?

 

If hole.HoleType <> HoleTypeEnum.kCounterSinkHole And hole.HoleType <> HoleTypeEnum.kCounterBoreHole Then Continue For

 

Kind regards,

0 Likes
Message 7 of 8

Michael.Navara
Advisor
Advisor

You need to iterate pattern features also. Similar to 

For Each hole As HoleFeature In partDocument.ComponentDefinition.Features.HoleFeatures

But you need to check the pattern contains relevant holes as input feature. Iterate all pattern elements and get its faces and edges.

Be careful the pattern can contains more then one feature as input.

This is little bit more code but the idea is the same.

You can use VBA Object Browser for Inventor for insight how to obtain relevant faces and edges from pattern element.

0 Likes
Message 8 of 8

rcolon9E4ZX
Advocate
Advocate

@Michael.Navara ,

 

Thank you for the reply. I chose to SaveCopyAs the part document flat pattern and control the layer visibility so only the outer and inner profiles remain. This makes sure the C-Sink/C-Bore max diameters are removed. I was able to implement within my drawing export tool. It can iterate through all opened documents and batch export.

 

Sub ExportFlatFromIPT(oDoc As PartDocument, Optional sPath As String = "C:\temp\", Optional sName As String = vbNullString, Optional DwgOrDxf As String = "DXF")
    
    'Get date and time and make filename friendly
    Dim strTime As String
    strTime = Time
    strTime = Replace(strTime, ":", ".")
    Dim strDate As String
    strDate = Date
    strDate = Replace(strDate, "/", ".")

    Dim sFilename As String, sNameWExt As String, sFile As String, sOut As String
    Dim oDataIO As DataIO
    
    If sName = vbNullString Then
        sFilename = oDoc.FullFileName
        sNameWExt = Right(sFilename, Len(sFilename) - InStrRev(sFilename, "\"))
        sName = Left(sNameWExt, Len(sNameWExt) - 4)
    End If
    
    If DwgOrDxf = "DWG" Then
        sFile = sPath & sName & " " & strDate & " " & strTime & "_Profile.dwg"
    
        ' Get the DataIO object.
        Set oDataIO = oDoc.ComponentDefinition.DataIO
    
        ' Build the string that defines the format of the DWG file.
        sOut = "FLAT PATTERN DWG?" & _
                "&AcadVersion=2000" & _
                "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_FEATURE_PROFILES;" & _
                                "IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
    
        ' Create the DXF file.
        Call oDataIO.WriteDataToFile(sOut, sFile)
    End If
   
    If DwgOrDxf = "DXF" Then
        sFile = sPath & sName & " " & strDate & " " & strTime & "_Profile.dxf"
    
        ' Get the DataIO object.
        Set oDataIO = oDoc.ComponentDefinition.DataIO
    
        ' Build the string that defines the format of the DXF file.
        sOut = "FLAT PATTERN DXF?" & _
                "&AcadVersion=R12" & _
                "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_FEATURE_PROFILES;" & _
                                "IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
    
        ' Create the DXF file.
        Call oDataIO.WriteDataToFile(sOut, sFile)
    End If
    
    'Set oDoc = Nothing
    Set oDataIO = Nothing
End Sub

 

rcolon9E4ZX_0-1658863510079.png

 

Kind regards,

 

0 Likes