Punches tables for part drawing

Punches tables for part drawing

Ahmed.shawkyXTZHN
Enthusiast Enthusiast
111 Views
1 Reply
Message 1 of 2

Punches tables for part drawing

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi all , I have the below code which is working fine for assembly , how can I modify it to be applicable to parts level so table will be in part drawing instead of assembly , also is it possible to link it so it will come to sheet metal part table with length width thickness , thanks.

 

Dim oDrawing As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDrawing.ActiveSheet
Dim oHoles As New List(Of KeyValuePair(Of String, Integer))
Dim oPunches As New List(Of KeyValuePair(Of String, Integer))

Dim oAsm As AssemblyDocument = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
Dim oCustomProps As PropertySet = oAsm.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each oProp As Inventor.Property In oCustomProps
	If oProp.Name.StartsWith("Hole: ") Then
		oHoles.Add(New KeyValuePair(Of String, Integer)(oProp.Name.Replace("Hole: ", ""), oProp.Value))
	ElseIf oProp.Name.StartsWith("Punch: ") Then
		oPunches.Add(New KeyValuePair(Of String, Integer)(oProp.Name.Replace("Punch: ", ""), oProp.Value))
	End If
Next
Dim oHoleTable As CustomTable
Dim oPunchTable As CustomTable
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
If oHoles.Count > 0
	Dim colTitles(1) As String
	colTitles(0) = "Diameter"
	colTitles(1) = "Number"
	oHoleTable = oSheet.CustomTables.Add("Holes", oTG.CreatePoint2d(10, 10), 2, oHoles.Count, colTitles)
	oHoleTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	For i = 1 To oHoles.Count
		oHoleTable.Rows(i).Item("Diameter").Value = oHoles(i - 1).Key
		oHoleTable.Rows(i).Item("Number").Value = oHoles(i - 1).Value
	Next
End If
If oPunches.Count > 0
	Dim colTitles(1) As String
	colTitles(0) = "Name"
	colTitles(1) = "Number"
	oPunchTable = oSheet.CustomTables.Add("Punches", oTG.CreatePoint2d(If (oHoleTable Is Nothing, 10, 10 + oHoleTable.RangeBox.MaxPoint.X - oHoleTable.RangeBox.MinPoint.X) _
	, 10), 2, oPunches.Count, colTitles)
	oPunchTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	For i = 1 To oPunches.Count
		oPunchTable.Rows(i).Item("Name").Value = oPunches(i - 1).Key
		oPunchTable.Rows(i).Item("Number").Value = oPunches(i - 1).Value
	Next
End If
0 Likes
112 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

try this:

Dim oDrawing As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDrawing.ActiveSheet
Dim oHoles As New List(Of KeyValuePair(Of String, Integer))
Dim oPunches As New List(Of KeyValuePair(Of String, Integer))

Dim refDoc As Document = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
Dim oCustomProps As PropertySet = refDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each oProp As Inventor.Property In oCustomProps
	If oProp.Name.StartsWith("Hole: ") Then
		oHoles.Add(New KeyValuePair(Of String, Integer)(oProp.Name.Replace("Hole: ", ""), oProp.Value))
	ElseIf oProp.Name.StartsWith("Punch: ") Then
		oPunches.Add(New KeyValuePair(Of String, Integer)(oProp.Name.Replace("Punch: ", ""), oProp.Value))
	End If
Next
Dim oHoleTable As CustomTable
Dim oPunchTable As CustomTable
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim insertX = 10
If oHoles.Count > 0 Then
	Dim colTitles(1) As String
	colTitles(0) = "Diameter"
	colTitles(1) = "Number"
	oHoleTable = oSheet.CustomTables.Add("Holes", oTG.CreatePoint2d(insertX, 10), 2, oHoles.Count, colTitles)
	oHoleTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	For i = 1 To oHoles.Count
		oHoleTable.Rows(i).Item("Diameter").Value = oHoles(i - 1).Key
		oHoleTable.Rows(i).Item("Number").Value = oHoles(i - 1).Value
	Next
	insertX = oHoleTable.RangeBox.MaxPoint.X
End If
If oPunches.Count > 0 Then
	Dim colTitles(1) As String
	colTitles(0) = "Name"
	colTitles(1) = "Number"
	oPunchTable = oSheet.CustomTables.Add("Punches", oTG.CreatePoint2d(insertX, 10), 2, oPunches.Count, colTitles)
	oPunchTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	For i = 1 To oPunches.Count
		oPunchTable.Rows(i).Item("Name").Value = oPunches(i - 1).Key
		oPunchTable.Rows(i).Item("Number").Value = oPunches(i - 1).Value
	Next
	insertX = oPunchTable.RangeBox.MaxPoint.X
End If

If (refDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then

	Dim partDoc As PartDocument = refDoc
	Dim sheetMetalDef As SheetMetalComponentDefinition = partDoc.ComponentDefinition

	If (sheetMetalDef.HasFlatPattern) Then
		Dim colTitles(1) As String
		colTitles(0) = "Dimension"
		colTitles(1) = "Value"
		oHoleTable = oSheet.CustomTables.Add("Sheet size", oTG.CreatePoint2d(insertX, 10), 2, 2, colTitles)
		oHoleTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

		oHoleTable.Rows(1).Item("Dimension").Value = "Width"
		oHoleTable.Rows(1).Item("Value").Value = Math.Round(sheetMetalDef.FlatPattern.Width, 3)

		oHoleTable.Rows(2).Item("Dimension").Value = "Length"
		oHoleTable.Rows(2).Item("Value").Value = Math.Round(sheetMetalDef.FlatPattern.Length, 3)
	End If
End If

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes