Get the name of a dimension

Get the name of a dimension

harvey_craig2RCUH
Advocate Advocate
358 Views
5 Replies
Message 1 of 6

Get the name of a dimension

harvey_craig2RCUH
Advocate
Advocate

I wish to create a matrix of the names and positions of all the dimensions on a drawing. Let's say I placed a dimension like so:

Dim BSPPLengthOverall = genDims.AddLinear("BSPPLengthOverall", VIEW1.SheetPoint(5, 6), E0, E1)

Later on I can retrieve the position of all these dimensions like so:

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.Sheets.Item(1)
Dim oDimensions As DrawingDimensions = oSheet.DrawingDimensions
Dim DimPosList As New ArrayList
For x = 1 To oDimensions.Count
	DimPosList.Add(oDimensions.Item(x).Text.Origin)
Next
SharedVariable("DimPosList") = DimPosList

The problem I have is these dimensions are stored in a list in a random order. If I could also Get the name that I assigned to them, in this case "BSPPLengthOverall", I could create a matrix with the names and positions. Is there a method to get the name?

 

Thanks,

Harvey

 

0 Likes
Accepted solutions (3)
359 Views
5 Replies
Replies (5)
Message 2 of 6

C_Haines_ENG
Collaborator
Collaborator
Accepted solution

Don't think you can't add a dimension like that, as in the AddLinear command the first item is a Point2D object representing where the dimensions text is. 

 

I think the only way to "Name" a dimension is to assign AttributeSets.  See link Link. I'm still learning how these work so you might be on your own there.

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

It looks like he is referring to the uniquely iLogic way of creating dimensions, which includes IManagedGeneralDimensions.AddLinear Method, not the main Inventor API way of creating them, which would be GeneralDimensions.AddLinear.  And yes, using that uniquely iLogic way, when we specify a name for the dimension, it works pretty much the same way as the iLogic 'Named Entities' system does...using Attributes, but I think the attribute sets and/or attributes may be named a little differently than the regular 'Named Entities' system uses.  I cant remember the exact names at the moment, and my notes/snippets are not readily available at the moment either.  So, when iterating through those dimensions, try inspecting their attributes, starting with the DrawingDimension.AttributeSets property value, which will be an AttributeSets type value, and go from there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

harvey_craig2RCUH
Advocate
Advocate

I did have a look at the attribute's. I wrote this little code and most of them contain 1 item that is of the object type, I can't find any information on what this object is? How can I convert it to something useful?

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.Sheets.Item(1)
Dim oDimensions As DrawingDimensions = oSheet.DrawingDimensions
For x = 1 To oDimensions.Count
	msgstring = "Dimension " & x & ": Count: " & oDimensions.Item(x).AttributeSets.Count
	If oDimensions.Item(x).AttributeSets.Count = 1
		msgstring = msgstring & " VarType: " & VarType(oDimensions.Item(x).AttributeSets.Item(1))
	End If
	Logger.Info(msgstring)
Next

 

The Log:

INFO| 2: >>---------------------------
TRACE|Entering external rule: AttributeChecker (from 103668HYD-1.idw)
INFO|Dimension 1: Count: 1 VarType: 9
INFO|Dimension 2: Count: 1 VarType: 9
INFO|Dimension 3: Count: 1 VarType: 9
INFO|Dimension 4: Count: 1 VarType: 9
INFO|Dimension 5: Count: 1 VarType: 9
INFO|Dimension 6: Count: 1 VarType: 9
INFO|Dimension 7: Count: 1 VarType: 9
INFO|Dimension 8: Count: 0
INFO|Dimension 9: Count: 0
INFO|Dimension 10: Count: 1 VarType: 9
INFO|Dimension 11: Count: 1 VarType: 9
INFO|Dimension 12: Count: 1 VarType: 9
INFO|Dimension 13: Count: 1 VarType: 9
INFO|Dimension 14: Count: 1 VarType: 9
INFO|Dimension 15: Count: 1 VarType: 9
INFO|Dimension 16: Count: 1 VarType: 9
INFO|Dimension 17: Count: 1 VarType: 9
INFO|Dimension 18: Count: 1 VarType: 9
INFO|Dimension 19: Count: 1 VarType: 9
INFO|Dimension 20: Count: 0
INFO|Dimension 21: Count: 0
INFO|Dimension 22: Count: 1 VarType: 9
INFO|Dimension 23: Count: 1 VarType: 9
INFO|Dimension 24: Count: 1 VarType: 9
INFO|Dimension 25: Count: 1 VarType: 9
INFO|Dimension 26: Count: 1 VarType: 9
TRACE|Exiting external rule: AttributeChecker (from 103668HYD-1.idw)

0 Likes
Message 5 of 6

harvey_craig2RCUH
Advocate
Advocate
Accepted solution

Scratch that, with a look through the intellisense I found it:

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.Sheets.Item(1)
Dim oDimensions As DrawingDimensions = oSheet.DrawingDimensions
For x = 1 To oDimensions.Count
	msgstring = "Dimension " & x & ": Count: " & oDimensions.Item(x).AttributeSets.Count
	If oDimensions.Item(x).AttributeSets.Count = 1
		msgstring = msgstring & " VarType: " & VarType(oDimensions.Item(x).AttributeSets.Item(1))
		msgstring = msgstring & " Value: " & oDimensions.Item(x).AttributeSets.Item(1).Item(1).Value
	End If
	Logger.Info(msgstring)
Next

Log:

TRACE|Entering external rule: AttributeChecker (from 103668HYD-1.idw)
INFO|Dimension 1: Count: 1 VarType: 9 Value: SouthBSPPLengthOverall
INFO|Dimension 2: Count: 1 VarType: 9 Value: SouthBSPPInternalDiameter
INFO|Dimension 3: Count: 1 VarType: 9 Value: SouthThreadDia_Dim
INFO|Dimension 4: Count: 1 VarType: 9 Value: SouthBSPPSealAngle
INFO|Dimension 5: Count: 1 VarType: 9 Value: SouthBottomOfGroove_BaseView
INFO|Dimension 6: Count: 1 VarType: 9 Value: SouthThreadDes_Dim
INFO|Dimension 7: Count: 1 VarType: 9 Value: SouthNotchDepthDim_Detail
INFO|Dimension 8: Count: 0
INFO|Dimension 9: Count: 0
INFO|Dimension 10: Count: 1 VarType: 9 Value: SouthMaxLengthGroove
INFO|Dimension 11: Count: 1 VarType: 9 Value: SouthUndercut34Dim
INFO|Dimension 12: Count: 1 VarType: 9 Value: SouthUndercut45Dim
INFO|Dimension 13: Count: 1 VarType: 9 Value: NorthBSPPLengthOverall
INFO|Dimension 14: Count: 1 VarType: 9 Value: NorthBSPPInternalDiameter
INFO|Dimension 15: Count: 1 VarType: 9 Value: NorthThreadDia_Dim
INFO|Dimension 16: Count: 1 VarType: 9 Value: NorthBSPPSealAngle
INFO|Dimension 17: Count: 1 VarType: 9 Value: NorthBottomOfGroove_BaseView
INFO|Dimension 18: Count: 1 VarType: 9 Value: NorthThreadDes_Dim
INFO|Dimension 19: Count: 1 VarType: 9 Value: NorthNotchDepthDim_Detail
INFO|Dimension 20: Count: 0
INFO|Dimension 21: Count: 0
INFO|Dimension 22: Count: 1 VarType: 9 Value: NorthMaxLengthGroove
INFO|Dimension 23: Count: 1 VarType: 9 Value: NorthUndercut34Dim
INFO|Dimension 24: Count: 1 VarType: 9 Value: NorthUndercut45Dim
INFO|Dimension 25: Count: 1 VarType: 9 Value: HexHeight
INFO|Dimension 26: Count: 1 VarType: 9 Value: Dim_DrillDepth
TRACE|Exiting external rule: AttributeChecker (from 103668HYD-1.idw)

 

This will work great for what I need, cheers,

Harvey

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Good morning @harvey_craig2RCUH.  Glad to see that you got it figured out.  Now that I am back at my work computer, and have access to my notes & snippets, I see that the AttributeSet and Attributes used in this situation are actually named exactly the same as those used by the iLogic 'NamedEntities' system, on the part / model side.  The name of the AttributeSet is "iLogicEntityNameSet", and the name of the Attribute is "iLogicEntityName".  It can be tempting to use a Try...Catch...End Try block of code, or check Count, around where we access those Attributes, to avoid the potential error of no attributes present, and keep the code a bit shorter, but the attributes already have a system in place for that sort of thing, when you already know the names of the ones you are looking for (AttributeSets.NameIsUsed & AttributeSet.NameIsUsed), so I usually use that system instead.  Since I already had multiple iLogic snippets saved for finding &/or deleting dimensions by their names, I will post a code example below that is a combination of your code process, and one of the ones I had on hand.  You may find this helpful, or at least interesting, due to how it gets and records the data, then sorts that data, then writes a report out about that data.  However, the way it is right now, if a dimension is encountered which does not have an attribute based name, it is skipped (Line 19)...not sure if that is desired or not though.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	'define the variable and its Type, for recording the data
	'a Dictionary is like a List, but with each entry having two factors
	'Key and Value - Key is used to identify each item
	Dim oDimsData As New Dictionary(Of String, Inventor.Point2d)
	'the names of the AttributeSet & Attribute objects we are looking for
	Dim sSetName As String = "iLogicEntityNameSet"
	Dim sAttName As String = "iLogicEntityName"
	'now start iterating through the dimensions on the active sheet
	For Each oDDim As DrawingDimension In oDDoc.ActiveSheet.DrawingDimensions
		Dim sName As String = ""
		If oDDim.AttributeSets.NameIsUsed(sSetName) AndAlso
			oDDim.AttributeSets.Item(sSetName).NameIsUsed(sAttName) Then
			sName = oDDim.AttributeSets.Item(sSetName).Item(sAttName).Value
		End If
		If sName = "" Then
			Continue For 'not a 'named' dimension, so skip recording it
		Else
			'record name and location as an entry into the Dictionary
			oDimsData.Add(sName, oDDim.Text.Origin)
		End If
	Next
	'sort the data entries by the names of the dimensions now
	Dim oSortedData As IOrderedEnumerable(Of KeyValuePair(Of String, Inventor.Point2d)) = oDimsData.OrderBy(Function(d) d.Key)
	'now write this data into the iLogic Log window (only works if that tab is visible)
	For i As Integer = 0 To oSortedData.Count() -1
		Dim oPt As Inventor.Point2d = oSortedData.ElementAt(i).Value
		Logger.Info(vbCrLf & _
		"Name = " & oSortedData.ElementAt(i).Key & vbCrLf & _
		"Location = " & oPt.X.ToString & " x " & oPt.Y.ToString & vbCrLf)
	Next
	'now click on the iLogic Log tab to look within that window and view the results
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes