Creating a Table on a drawing of Coordinates

Creating a Table on a drawing of Coordinates

CollinWNQ4L
Participant Participant
297 Views
2 Replies
Message 1 of 3

Creating a Table on a drawing of Coordinates

CollinWNQ4L
Participant
Participant

I want to start by saying I am by no means a programmer but managed to copy and paste together some stuff.

 

At our company we need to make tables of the coordinates of Tie-In Points, where our customers can set up the required connections in advance. Right now they are measuring and inserting all the coordinates by hand into a table in our drawings, which is a ridiculous amount of dumb work in my opinion.

 

So, I want to automate it.

 

Currently, I have code working that pulls the coordinates (Center Point) from all occurences of which the iProperty "Title" = Tie-In Point. This would allow us to make a specific part that you copy, paste and constrain on the appropriate locations. It gives those coordinates in mm already (the x10 factor), as this is required. Note that I run this code in a drawing document, and it pulls the main model / assembly from the drawing as reference.

 

I feel like I'm missing two steps to achieve what I want:

1. I want to number the coordinate values. This would mean that the first Tie-In Point would have the variables xCoord1, yCoord1, zCoord1, then the second point gets xCoord2, yCoord2, etc. Is there a way to automate these variables for "xCoordn"? Because it is unknown at the start how many points would be needed.

 

These variables could all be written into a table using the table creation feature, which seems easy enough. But, since the amount of points is unknown as stated above, the table length would be unknown as well.

 

2. Is there a way to make it so that a table is filled in using "Row 1 = Headers; Row 2 = xCoordn, yCoordn, zCoordn; Row 3 = xCoordn+1, yCoordn+1, zCoordn+1, etc."?

 

I imagine this would be possible using the same sequence integer for both questions I have (i=1, and for every occurence i+1). This could determine the length of the table as well as name the variables.

 

My current code, which just pops up text boxes with the coordinates, is as follows:

I'm gonna try and get the code working for the table using some values and reply to this thread if it works

 

 

Public Sub Main()
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc = ThisDrawing.ModelDocument
	Dim oAsmDef As AssemblyComponentDefinition
	oAsmDef = oAsmDoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
	Call TraverseAssembly(oAsmDef, oOccs)
End Sub

Function TraverseAssembly(oAsmDef As AssemblyComponentDefinition, oOccs As ComponentOccurrences)
	Dim oWPProxy As WorkPointProxy
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		Dim TitleCheck= oOcc.Definition.Document.PropertySets.Item("Inventor Summary Information").Item("Title").Value
		If TitleCheck = "Tie-In Point" Then
		Dim oWP As WorkPoint
		For Each oWP In oOcc.Definition.WorkPoints
			If Not oWP.Name.Contains("Center Point") Then Continue For
				i=i+1
			Call oOcc.CreateGeometryProxy(oWP, oWPProxy)
			Dim xCoord, yCoord, zCoord As Double
			xCoord = oWPProxy.Point.X * 10
			yCoord = oWPProxy.Point.Y * 10
			zCoord = oWPProxy.Point.Z * 10
			oLine = "X: " & Round(xCoord, 3) & vbLf & "Y: " & Round(yCoord, 3) & vbLf & "Z: " & Round(zCoord, 3)
			MsgBox(oLine, , oWP.Name)
		Next
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			'step into subassembly
			oSubOccs = oOcc.SubOccurrences
			Call TraverseAssembly(oAsmDef, oSubOccs)
		End If
		End If
	Next
End Function

 

 

0 Likes
Accepted solutions (1)
298 Views
2 Replies
Replies (2)
Message 2 of 3

CollinWNQ4L
Participant
Participant

I am now also able to create a table with 6 columns (Name, X, Y, Z, Size and Rating) and the amount of rows as there are components in the file using the following code pasted in front of the "End Function"

 

But, as I don't know how to create numbered variables yet, it's just giving me a filled table with 1/2/3/4/5/6 strings

 

 

Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet

	ColumnSize = 6
	Dim oTitles(0 To ColumnSize-1) As String
    	oTitles(0) = "Tie-In Point"
   		oTitles(1) = "X"
		oTitles(2) = "Y"
		oTitles(3) = "Z"
		oTitles(4) = "Size"
		oTitles(5) = "Rating"
		
	Dim a As Integer = 0
    Dim oContents(0 To (i*ColumnSize)-1) As String
	While a < i 
		oContents(a * ColumnSize) = "1"	
    	oContents(a * ColumnSize + 1) = "2"	
    	oContents(a * ColumnSize + 2) = "3"	
    	oContents(a * ColumnSize + 3) = "4"	
		oContents(a * ColumnSize + 4) = "5"	
    	oContents(a * ColumnSize + 5) = "6"
		a = a + 1
	End While

    Dim InsP As Point2d
    InsP = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
	
	Dim oCustomTable As CustomTable
   	oCustomTable = oSheet.CustomTables.Add("Tie-In Points", InsP, ColumnSize, i, oTitles, oContents, oColumnWidths)

 

0 Likes
Message 3 of 3

CollinWNQ4L
Participant
Participant
Accepted solution

I got it working!! Very happy right now, expected it to be very hard but got it done within a day. For those interested: I managed to write the texts I got from each occurence to a list, and had the table get every n-th string from the list. Ended up being quite a few more Columns, but as soon as I got it working it was easy to add

 

Public Sub Main()
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc = ThisDrawing.ModelDocument
	Dim oAsmDef As AssemblyComponentDefinition
	oAsmDef = oAsmDoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
	Call TraverseAssembly(oAsmDef, oOccs)
End Sub

Function TraverseAssembly(oAsmDef As AssemblyComponentDefinition, oOccs As ComponentOccurrences)
	Dim oWPProxy As WorkPointProxy
	Dim oOcc As ComponentOccurrence
	Dim oTPList, oSizeList, oRatingList, oTypeList, oDescriptionList, oMaterialList, oxList, oyList, ozList As New List(Of String)
	Dim TP, Size, Rating, Type, Description, Material As String
	Dim i As Integer = 0
		For Each oOcc In oOccs 	
		Dim TitleCheck= oOcc.Definition.Document.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value
		If TitleCheck = "Tie-In Point" Then
		i = i+1
		Dim oWP As WorkPoint
		For Each oWP In oOcc.Definition.WorkPoints
			If Not oWP.Name.Contains("Center Point") Then Continue For
			Call oOcc.CreateGeometryProxy(oWP, oWPProxy)
			Dim xCoord, yCoord, zCoord As String
			xCoord = Round(oWPProxy.Point.X * 10, 0)
			yCoord = Round(oWPProxy.Point.Y * 10, 0)
			zCoord = Round(oWPProxy.Point.Z * 10, 0)
			oxList.Add(xCoord)
			oyList.Add(yCoord)
			ozList.Add(zCoord)
			
		Next
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			'step into subassembly
			oSubOccs = oOcc.SubOccurrences
			Call TraverseAssembly(oAsmDef, oSubOccs)
		End If
			oTP = oOcc.Definition.Document.PropertySets.Item("Inventor Summary Information").Item("Title").Value
			oSize = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("Size").Value
			oRating = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("Rating").Value
			oType = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("Type").Value
			oDescription = oOcc.Definition.Document.PropertySets.Item("Inventor Summary Information").Item("Subject").Value
			oMaterial = oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value
			
			oTPList.Add(oTP)
			oSizeList.Add(oSize)
			oRatingList.Add(oRating)
			oTypeList.Add(oType)
			oDescriptionList.Add(oDescription)
			oMaterialList.Add(oMaterial)
		End If
				
	Next

	

Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet

	ColumnSize = 9
	Dim oTitles(0 To ColumnSize-1) As String
    	oTitles(0) = "TP"
   		oTitles(1) = "Description"
		oTitles(2) = "Size"
		oTitles(3) = "Rating"
		oTitles(4) = "Type"
		oTitles(5) = "Material"
		oTitles(6) = "X"
		oTitles(7) = "Y"
		oTitles(8) = "Z"
		
	Dim a As Integer = 0
    Dim oContents(0 To (i*ColumnSize)-1) As String
	While a < i 
		oContents(a * ColumnSize) = oTPList(a)
    	oContents(a * ColumnSize + 1) = oDescriptionList(a)
    	oContents(a * ColumnSize + 2) = oSizeList(a)
    	oContents(a * ColumnSize + 3) = oRatingList(a)
		oContents(a * ColumnSize + 4) = oTypeList(a)
		oContents(a * ColumnSize + 5) = oMaterialList(a)
    	oContents(a * ColumnSize + 6) = oxList(a)
    	oContents(a * ColumnSize + 7) = oyList(a)
		oContents(a * ColumnSize + 8) = ozList(a)
		a = a + 1
	End While
	
    Dim oColumnWidths(0 To ColumnSize-1) As Double
    oColumnWidths(0) = 1.5
    oColumnWidths(1) = 6
	oColumnWidths(2) = 1.5
	oColumnWidths(3) = 1.5
	oColumnWidths(4) = 2.25
	oColumnWidths(5) = 1.5
	oColumnWidths(6) = 1.25
	oColumnWidths(7) = 1.25
	oColumnWidths(8) = 1.25

    Dim InsP As Point2d
    InsP = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
	
	Dim oCustomTable As CustomTable
   	oCustomTable = oSheet.CustomTables.Add("Tie-In Points", InsP, ColumnSize, i, oTitles, oContents, oColumnWidths)

End Function	

 

 

0 Likes