What is the most efficient method for checking if a drawing dimension is bad?

What is the most efficient method for checking if a drawing dimension is bad?

inulobo
Advocate Advocate
735 Views
6 Replies
Message 1 of 7

What is the most efficient method for checking if a drawing dimension is bad?

inulobo
Advocate
Advocate

I have run into different types of errors with different dimension types. With ordinate dimension sets I have realized that sometimes on my drawing I'll have invisible ornate dimension members on a sheet. With general dimension types I've noticed that when I check the parent geometry and look for the view it is attached to sometimes it'll be broken which tells me the dimension is not attached properly. Is there something I can check that will always tell me if it dimension is bad? I want to come up with a way to cycle through the drawing dimensions and remove bad members and dimensions.

0 Likes
736 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hello @inulobo . This is what I am using to check my drawings.

Hope will works for you.

 

The code will let you select multiple files.

It will check unattached things that causes the error.

If found one error, the code will leave the drawing open for you to check.

 

 

Sub Main()
	Dim oFileDlg As Inventor.FileDialog = Nothing
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Autodesk Inventor Drawings (*.idw)|*.idw"
	oFileDlg.DialogTitle = "Select Drawings To Check"
	oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oFileDlg.MultiSelectEnabled =True 
	oFileDlg.FilterIndex = 1
	oFileDlg.CancelError = True
	On Error Resume Next
	oFileDlg.ShowOpen()
	Dim oDrgDoc As DrawingDocument
	If Err.Number <> 0 Then
		MsgBox("File not chosen.",,"Dialog Cancellation")
	ElseIf oFileDlg.FileName <> "" Then
		For Each oFileName As String In oFileDlg.FileName.Split("|")
			oDrgDoc = ThisApplication.Documents.Open(oFileName)
			doc = ThisApplication.ActiveDocument
			'oDwgName = IO.Path.GetFileNameWithoutExtension(oFileName)
			
			Dim oFD As FileDescriptor
			oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
			oModelRef = (oFD.FullFileName.Split("\").Last()).Split(".").First()
			Dim oCount As Integer = 0
			
			'Loop through all unattached dimensions
			For Each oDrawingDim In oDrgDoc.ActiveSheet.DrawingDimensions
				If oDrawingDim.Attached = False Then
				oCount = oCount + 1
				End If
			Next
			
			
			
			'Loop through all orphaned centermarks
			For Each oCenterMark In oDrgDoc.ActiveSheet.Centermarks
				If oCenterMark.Attached = False Then
				oCount = oCount + 1
				End If
			Next

			'Loop through all orphaned centerlines
			For Each oCenterLine In oDrgDoc.ActiveSheet.Centerlines 
				If oCenterLine.Attached = False Then
				oCount = oCount + 1
				End If
			Next

						
			'If oCount is equal to zero, it means no error found.
			'It will then close the drawing. 
			'If oCount Is Not equal To zero, it will leave the drawing open for you to check and edit.
			If oCount = 0  Then  
				oDrgDoc.Close(True)
				oDrgDoc.ReleaseReference
			End If

		Next
	End If
End Sub

 

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

When you have your individual drawings open, you can run this code to delete unattached things.

 

Dim oDrgDoc As DrawingDocument = ThisApplication.ActiveDocument

'Loop through all unattached dimensions
For Each oDrawingDim In oDrgDoc.ActiveSheet.DrawingDimensions
	If oDrawingDim.Attached = False Then
	oDrawingDim.Delete
	End If
Next


'Loop through all orphaned centermarks
For Each oCenterMark In oDrgDoc.ActiveSheet.Centermarks
	If oCenterMark.Attached = False Then
	oCenterMark.Delete
	End If
Next

'Loop through all orphaned centerlines
For Each oCenterLine In oDrgDoc.ActiveSheet.Centerlines 
	If oCenterLine.Attached = False Then
	oCenterLine.Delete
	End If
Next

Message 4 of 7

inulobo
Advocate
Advocate

Hello, I wish I got these messages earlier I actually wrote something very similar. But Regardless neither of our macros work. I still error out on and I still have unattached dimensions. I will try to experiment more. I think we need to do something like this. For OrdinateDimensions we need to check OrdinateDim.Intent.Geometry.Parent.Name if this results in an error then it means the dimension is not properly attached to the drawing view. Then we can remove the dimension via a function. I'll attach the code I wrote that was similar to yours. It runs through each sheet. 

 

Public Sub Delete_UnattachedDimensions()

    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Dim oSheets As Sheets
    Dim oOrdinateSets As OrdinateDimensionSets
    Dim oDrawingDim As DrawingDimension
    Dim oDrawingDims As DrawingDimensions
    Dim i As Integer
    
    Set oSheets = oDoc.Sheets
       
For Each oSheet In oSheets
    oSheet.Activate
    
    Set oOrdinateSets = oSheet.DrawingDimensions.OrdinateDimensionSets
    
    If oOrdinateSets.Count > 0 Then
        Dim oOrdinateSet As OrdinateDimensionSet
        For Each oOrdinateSet In oOrdinateSets
            Dim ODEnum As OrdinateDimensionsEnumerator
            Set ODEnum = oOrdinateSet.Members
            
            For i = 1 To ODEnum.Count
                If ODEnum(i).Attached = False Then
                    oOrdinateSet.Delete
                    Exit For
                End If
            Next i
        Next
    End If
    
    Set oDrawingDims = oSheet.DrawingDimensions
    For Each oDrawingDim In oSheet.DrawingDimensions
        If oDrawingDim.Attached = False Then
            Call oDrawingDim.Delete
        End If
    Next
Next

End Sub
0 Likes
Message 5 of 7

inulobo
Advocate
Advocate

Here is an example of what I was talking about. I labeled all dimensions. There are two invisible members of the ordinate dimension type.

Capture.PNG

 

0 Likes
Message 6 of 7

AlexKorzun
Autodesk
Autodesk

What might happen: skipping next collection member after deletion.

Imagine the collection 1,2,3,4. Element 2,3 are "bad" and thus have to be deleted.

So, after you delete 2, the collection will be reorganized to 1,3,4 . The next member to inspect will be 4, and inspection of 3 is skipped. Result: the 3 survived.

 

There are two possible solutions to avoid such scenarios:

1. Iterate backwards: 

For i = ODEnum.Count To 1 Step -1

2. Decrease i right after you've deleted the dimension

 

Case of foreach is little bit more complicated: Foreach should collect bad members into the separate collection. Then, members of the new collection are deleted till it becomes empty.

 

Thank you,




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

0 Likes
Message 7 of 7

inulobo
Advocate
Advocate

I did try to collect bad member to another set but it still failed. Not sure what to do because they are considered "attached". I'll try your method of iterating backwards and see if it has any success. I really do not want to delete a full set unless it's the set that has the bad members.

0 Likes