Remove baseline member if equal to another.

Remove baseline member if equal to another.

csandersPN6FA
Explorer Explorer
356 Views
2 Replies
Message 1 of 3

Remove baseline member if equal to another.

csandersPN6FA
Explorer
Explorer

I am trying to automated a drawing using baseline sets on all four sides of a part. I've been successful in doing so, however I am getting duplicate dimensions in the different baseline sets. I was wondering if there was a way to search the previous sets that were created so that any new set that is made would omit a dimension that would be a duplicate. I've been searching for answers but so far have come up with nothing. I would appreciate any help.

 

Thanks,

0 Likes
357 Views
2 Replies
Replies (2)
Message 2 of 3

AlexKorzun
Autodesk
Autodesk

Below is the code for the following workflow:

  1. Initial state:
     
    AlexKorzun_1-1616448259412.png

     

  2. Deleted some members of the vertical baseline dim set :
    AlexKorzun_2-1616448383850.png
  3. Created new baseline dim set on the right, adjusted origin
    AlexKorzun_3-1616448492680.png
  4. Ran rule, the result is:
    AlexKorzun_4-1616449868879.png

     

If this is what you need, the code is below:

Imports System.Collections.Generic

Sub
Main() Dim doc As DrawingDocument = ThisDoc.Document Dim sheet As Sheet = doc.ActiveSheet Dim tr As Transaction = ThisApplication.TransactionManager.StartTransaction(doc, "Remove duplicated dimensions") Try Dim dims As DimensionsSqueezer = New DimensionsSqueezer(sheet) MsgBox("Original count: " + dims.OriginalCount.ToString() + ", Unique dims count: " + dims.Count.ToString()) dims.Squeeze() tr.End() Catch tr.Abort() End Try End Sub Class DimensionsComparer Implements IEqualityComparer(Of LinearGeneralDimension) Public Overloads Function Equals (ByVal d1 As LinearGeneralDimension, ByVal d2 As LinearGeneralDimension) _ As Boolean Implements IEqualityComparer(Of LinearGeneralDimension).Equals If d1 Is Nothing And d2 Is Nothing Then Return True If d1 Is Nothing Or d2 Is Nothing Then Return False If d1.DimensionType <> d2.DimensionType Then Return False 'don't mix vert and hor dims Return String.Equals( d1.Text.Text , d2.Text.Text, StringComparison.OrdinalIgnoreCase) End Function Public Overloads Function GetHashCode(ByVal d As LinearGeneralDimension) _ As Integer Implements IEqualityComparer(Of LinearGeneralDimension).GetHashCode Return d.Text.Text.GetHashCode() Xor d.DimensionType End Function Public Shared Instance As IEqualityComparer(Of LinearGeneralDimension) = New DimensionsComparer End Class Class DimensionsSqueezer Inherits HashSet(Of LinearGeneralDimension) Public Sub New(sh As Sheet) MyBase.New(DimensionsComparer.Instance) BLDS = sh.DrawingDimensions.BaselineDimensionSets For Each bds As BaselineDimensionSet In BLDS For Each lgd As LinearGeneralDimension In bds.Members Add(lgd) OriginalCount+=1 Next Next End Sub Public Sub Squeeze() Dim toDelete As HashSet(Of LinearGeneralDimension) = New HashSet(Of LinearGeneralDimension) For Each bds As BaselineDimensionSet In BLDS For i As Integer = 1 To bds.Members.Count Dim lgd As LinearGeneralDimension = bds.Members(i) If Contains(lgd) Then ' Keeping dimension, updating hash Remove( lgd) Else 'Mark for delete toDelete.Add(lgd) End If Next Next ' MsgBox("Dimensions to be deleted : " + toDelete.Count.ToString()) For Each lgd As LinearGeneralDimension In toDelete lgd.Delete() Next End Sub Public Dim OriginalCount As Integer Dim BLDS As BaselineDimensionSets End Class

 

The important is the code in DimensionsComparer.Equals, which furnishes the criteria for the equality of two linear dimensions. In my example, the code compares the texts of the same dimension types. You may wish to change it. Also, the code is wrapped into transaction, to speed up a bit, and also to easily roll back the action.

Thank you,




Alex Korzun
Inventor-Revit Interop / Inventor-Fusion Interop / Inventor ETO
Autodesk, Inc.

0 Likes
Message 3 of 3

csandersPN6FA
Explorer
Explorer

I guess what I am looking for is a way to make a collection of the dimension vales and then comparing them to the new dimensions. However I am having a hard time with the collection. I am able to view the existing dimensions, but the only collection that Inventor uses is for geometry intent.

0 Likes