Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Retrieve model dimensions with tolerances

abhay.gilka
Enthusiast

Retrieve model dimensions with tolerances

abhay.gilka
Enthusiast
Enthusiast

Is it possible to retrieve only those model dimensions in inventor drawing for features that has tolerance specified in model sketch. Inventor brings all dimensions which are not useful.

0 Likes
Reply
345 Views
8 Replies
Replies (8)

Viktor.Lukjanow
Advocate
Advocate

I need that too, is there a possibility?

0 Likes

ryan.rittenhouse
Advocate
Advocate

This is pretty quick and dirty, but it should get the job done for you:

 

Dim currentDoc As DrawingDocument = ThisDrawing.Document
Dim currentSheet As Sheet = currentDoc.ActiveSheet

For Each drawView As DrawingView In currentSheet.DrawingViews
	Try
		currentSheet.DrawingDimensions.GeneralDimensions.Retrieve(drawView)
	Catch
		Logger.Error("Error auto dimensioning " & drawView.Name)
	End Try
Next drawView

For Each genDim As GeneralDimension In currentSheet.DrawingDimensions.GeneralDimensions
	If genDim.Tolerance.ToleranceType = kDefaultTolerance Then genDim.Delete
Next genDim

 

Let me know if it works for you.

If this solved your problem, or answered your question, please click Accept Solution.

WCrihfield
Mentor
Mentor

Yep, the DrawingView.Include3DAnnotations property is just a Read/Write Boolean, so it does not offer a custom way to filter which ones it will include.  You may just have to include all of them at first, then iterate through them afterwards with your code, and delete the ones you don't want, based on their tolerance settings.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Viktor.Lukjanow
Advocate
Advocate

Really great. Thank you very much. Can you extend it a bit so that when I run the iLogic I can select the view first and then only that view should run that iLogic.

0 Likes

Viktor.Lukjanow
Advocate
Advocate

Hi @ryan.rittenhouse,

I've adapted the code so that I have to select the view first and this function doesn't go through all the views. that's how it works. Would you do it differently? or like this?


Dim currentDoc As DrawingDocument = ThisDrawing.Document
Dim currentSheet As Sheet = currentDoc.ActiveSheet

' Überprüfen, ob eine Ansicht ausgewählt ist
Dim selectedObjects As SelectSet = ThisApplication.ActiveDocument.SelectSet

If selectedObjects.Count = 0 Then
	MessageBox.Show("Keine Ansicht ausgewählt. Bitte wählen Sie eine Ansicht aus.", "Hinweis")
	Return
End If

For Each selectedObj In selectedObjects
	If TypeOf selectedObj Is DrawingView Then
		Dim drawView As DrawingView = selectedObj
		Try
			currentSheet.DrawingDimensions.GeneralDimensions.Retrieve(drawView)
		Catch
			Logger.Error("Fehler beim automatischen Bemaßen von " & drawView.Name)
		End Try

		' Löschen von Standardtoleranzmaßen
		For Each genDim As GeneralDimension In drawView.Parent.DrawingDimensions.GeneralDimensions
			If genDim.Tolerance.ToleranceType = kDefaultTolerance Then genDim.Delete
		Next genDim
	Else
		MessageBox.Show("Bitte wählen Sie eine Zeichnungsansicht aus.", "Hinweis")
	End If
Next

 

0 Likes

ryan.rittenhouse
Advocate
Advocate

That looks good. Most importantly, if it's working for you, go with it.

If this solved your problem, or answered your question, please click Accept Solution.

Viktor.Lukjanow
Advocate
Advocate

THX @ryan.rittenhouse 
Your code was a great help to me.

0 Likes

Viktor.Lukjanow
Advocate
Advocate

 

for all others who also need this code. this one works better. here really only retrieved measures and without tolerance are deleted.

 

Dim currentDoc As DrawingDocument = ThisDrawing.Document
Dim currentSheet As Sheet = currentDoc.ActiveSheet

' Überprüfen, ob eine Ansicht ausgewählt ist
Dim selectedObjects As SelectSet = ThisApplication.ActiveDocument.SelectSet

If selectedObjects.Count = 0 Then
    MessageBox.Show("Keine Ansicht ausgewählt. Bitte wählen Sie eine Ansicht aus.", "Hinweis")
    Return
End If

For Each selectedObj In selectedObjects
    If TypeOf selectedObj Is DrawingView Then
        Dim drawView As DrawingView = selectedObj
        drawView.Include3DAnnotations = True ' Sicherstellen, dass 3D-Anmerkungen berücksichtigt werden
        
        Try
            ' Abrufen der Modellbemaßungen
            currentSheet.DrawingDimensions.GeneralDimensions.Retrieve(drawView)
            ThisApplication.CommandManager.ControlDefinitions.Item("DrawingSelectAllModelDimsCmd").Execute
        Catch ex As Exception
            Logger.Error("Fehler beim automatischen Bemaßen von " & drawView.Name & ": " & ex.Message)
        End Try

        ' Erstellen einer Liste aller ausgewählten Modellbemaßungen
        Dim selectedDims As New List(Of GeneralDimension)
        For Each selectedItem In ThisApplication.ActiveDocument.SelectSet
            If TypeOf selectedItem Is GeneralDimension Then
                selectedDims.Add(CType(selectedItem, GeneralDimension))
            End If
        Next

        ' Löschen aller ausgewählten Modellbemaßungen ohne Toleranz
        For Each genDim As GeneralDimension In selectedDims
            If genDim.Tolerance Is Nothing OrElse genDim.Tolerance.ToleranceType = kDefaultTolerance Then
                Try
                    genDim.Delete()
                Catch ex As Exception
                    Logger.Error("Fehler beim Löschen der Bemaßung: " & ex.Message)
                End Try
            End If
        Next
    Else
        MessageBox.Show("Bitte wählen Sie eine Zeichnungsansicht aus.", "Hinweis")
    End If
Next

 

0 Likes