Retrieve dimensions

Retrieve dimensions

theo_bot
Advocate Advocate
6,272 Views
21 Replies
Message 1 of 22

Retrieve dimensions

theo_bot
Advocate
Advocate

Hi,

 

I want to retrieve dimensions in a drawing with ilogic. I found some code in de api help, but i can't figure out how to translate it into a ilogic code.

 

I always use assembly models in these drawing and all the parameters have unique names. So in my drawing i want to retrieve some specific dimensions in a view.

 

Can anyone point me in the right direction? maybe a small sample?

 

kind regards,

 

theo

Accepted solutions (1)
6,273 Views
21 Replies
Replies (21)
Message 2 of 22

marco_suurlant
Enthusiast
Enthusiast
Accepted solution

Hello Theo,

 

Here you have a little example how-to retrieve dimensions with a special parameter name in iLogic.

 

The workflow I use is:

1. Retrieve all dimensions.

2. Iterate through the dimensions.

3. Delete dimensions if not a special parameter.

 

The special parameter name has a prefix “RetD_” as model / userparameter.

 

 RetrieveDimensions illogic Parameter.png

 

Start code”

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

 

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

 

Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

 

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator

oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)

 

Dim PrefixStr As String = "RetD_"

 

Dim oGeneralDimension As GeneralDimension

For Each oGeneralDimension In oGeneralDimensionsEnum

    Dim oParameter As Parameter

    oParameter = oGeneralDimension.RetrievedFrom.Parameter

 

    If oParameter.DrivenBy.count <> 0 Then

        Dim oDrivenByParameter As Parameter

        For Each oDrivenByParameter In oParameter.DrivenBy

            If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then

                oGeneralDimension.Delete

            End If

        Next

                Else

        If InStr(oParameter.Name, PrefixStr) = 0 Then

            oGeneralDimension.Delete

        End If

    End If

Next

“End Code

 

I hoop it was use full.

 

Best regards,

Marco Suurlant

Programmer Engineering
inventor professional 2015
Message 3 of 22

Anonymous
Not applicable

Wow!!! That is the great code!!!!

Thank you so much!!!

0 Likes
Message 4 of 22

theo_bot
Advocate
Advocate

Smiley Very Happy

 

Marco,

 

Thanks, it works great!!

 

Houdoe,Smiley Wink

 

gr Theo

 

 

0 Likes
Message 5 of 22

skyngu
Collaborator
Collaborator

 

hi

 

will this rule delete dimensions by hole features?

 

it seems not going to work at that way.

 

thanks.

Autodesk Inventor Professional 2019
0 Likes
Message 6 of 22

xiaodong_liang
Autodesk Support
Autodesk Support

I'd suggest you provide a dataset to recreate the problem you met with. This will help the peers here to diagnose.

0 Likes
Message 7 of 22

skyngu
Collaborator
Collaborator

HI,

 

please check attachment. there will be an error when run ilogic rule.

the dimension by hole feature is not going to work.

it is 1/4--20 hole. the diameter of tap drill hole casues the error.

 

thanks a lot.

Autodesk Inventor Professional 2019
0 Likes
Message 8 of 22

marco_suurlant
Enthusiast
Enthusiast

Hi,

 

You were right the code stopped working because the Tapped Hole has no RetrievedFrom.Parameter.

 

Here you have the modified code.

 

Start code”

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)

Dim oGeneralDimension As GeneralDimension
For Each oGeneralDimension In oGeneralDimensionsEnum
	Dim oParameter As Parameter

	Try
		oParameter = oGeneralDimension.RetrievedFrom.Parameter
	Catch
		' Error to set oParameter.
		' Go further to delete the dimension.
	End Try

    If oParameter.DrivenBy.count <> 0 Then
        Dim oDrivenByParameter As Parameter
        For Each oDrivenByParameter In oParameter.DrivenBy
            If InStr(oDrivenByParameter.Name, "RetD_") = 0 Then
                oGeneralDimension.Delete
            End If
        Next
    Else
        oGeneralDimension.Delete
    End If
Next

“End Code

 

I didn’t test it with your Part because I have now only version 2011.

 

Best regards,

Marco Suurlant

Programmer Engineering
inventor professional 2015
0 Likes
Message 9 of 22

skyngu
Collaborator
Collaborator

hi,

 

at the near end of your code, you miss some parts. it should be like this,

If InStr(oParameter.Name, "test_") = 0 Then

oGeneralDimension.Delete
End If

 

otherwise, the code will delete all dimensions.

 

thanks for your information.

Autodesk Inventor Professional 2019
0 Likes
Message 10 of 22

marco_suurlant
Enthusiast
Enthusiast

 

Hi,

 

Something like this:

 

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)

Dim PrefixStr As String = "RetD_"

Dim oGeneralDimension As GeneralDimension
For Each oGeneralDimension In oGeneralDimensionsEnum
    Dim oParameter As Parameter
	Try
		oParameter = oGeneralDimension.RetrievedFrom.Parameter
	Catch
		' Error to set oParameter.
		' Go further to delete the dimension.
	End Try

    If oParameter.DrivenBy.count <> 0 Then
        Dim oDrivenByParameter As Parameter
        For Each oDrivenByParameter In oParameter.DrivenBy
            If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
                oGeneralDimension.Delete
            End If
        Next
	Else
        If InStr(oParameter.Name, PrefixStr) = 0 Then
            oGeneralDimension.Delete
        End If
    End If
Next

 



 

 

Marco Suurlant

Programmer Engineering
inventor professional 2015
0 Likes
Message 11 of 22

Anonymous
Not applicable

Guys,

 

What if I have 3 views and I need to dimension OAL length on the front view, OAL width on the side view, and lets say a hole on the top view. How to modify the code. I tried to play with it, copiyng the part of the code and changing the view name, but it gives me an error.

 

Thanks in advance.

0 Likes
Message 12 of 22

marco_suurlant
Enthusiast
Enthusiast

Hi,

 

Here you have some code that can do that, only thing what you must have do is give the Drawing View a name and give the user / model parameter the right name.

 

Drawing View.JPG

 

Sub Main
Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
RetrieveDimByView(oSheet, "FrontView", "RetD_")
RetrieveDimByView(oSheet, "RightView", "RetDRight_")
RetrieveDimByView(oSheet, "TopView", "RetDTop_")
End Sub

Sub RetrieveDimByView(ByVal oSheet As Sheet, ByVal ViewName As String, ByVal PrefixStr As String)
Dim oDrawView As DrawingView
For Each oDrawView In oSheet.DrawingViews
If oDrawView.Name = ViewName Then
Exit For
End If
Next
Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)
Dim oGeneralDimension As GeneralDimension
For Each oGeneralDimension In oGeneralDimensionsEnum
Dim oParameter As Parameter
Try
oParameter = oGeneralDimension.RetrievedFrom.Parameter
Catch
' Error to set oParameter.
' Go further to delete the dimension.
End Try
If oParameter.DrivenBy.count <> 0 Then
Dim oDrivenByParameter As Parameter
For Each oDrivenByParameter In oParameter.DrivenBy
If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
oGeneralDimension.Delete
End If
Next
Else
If InStr(oParameter.Name, PrefixStr) = 0 Then
oGeneralDimension.Delete
End If
End If
Next
oSheet = Nothing
End Sub

 

 

Marco Suurlant

Programmer Engineering
inventor professional 2015
0 Likes
Message 13 of 22

Anonymous
Not applicable

Excellent works just great.

One more question, is there any chance to offset the dimensions?

 

Thanks,

0 Likes
Message 14 of 22

theo_bot
Advocate
Advocate

Hi Marco,

 

It works fine, but my model is based on a multi body part.

 

So if i retrieve the dimensions, i get the dimensions from every part from my assembly.

 

in the standard interface, i can select a part thats part of the view, how can i do this thru the api?

 

the API help tells me that you can use a "demensionToRetrive":

 

Sub Retrieve(ViewOrSketch As IDispatch, ByRef DimensionsToRetrieve As [optional] VARIANT, Result As [out, retval] GeneralDimensionsEnumerator*)

 

I've tried some to create a ObjectCollection with the specific part, but i doesn't seem to work. Do you have any suggestion.

 

Kind regards,

 

Theo

0 Likes
Message 15 of 22

marco_suurlant
Enthusiast
Enthusiast

Hello achmidt,

 

What you can do is select all dimension and then arrange dimensions.

 

Start code"

    Dim oCommandMgr As CommandManager = _
    ThisApplication.CommandManager

    oCommandMgr.ControlDefinitions.item("DrawingSelectAllInventorDimsCmd").Execute
    oCommandMgr.ControlDefinitions.item("DrawingArrangeDimensionsCmd").Execute

"End code

 

 

Best regards,


Marco Suurlant

Programmer Engineering
inventor professional 2015
0 Likes
Message 16 of 22

marco_suurlant
Enthusiast
Enthusiast

Hello Theo,

 

If you want to make a collection of a Part you can do something like this,

 

Dim oAssemblyDocument As Inventor.AssemblyDocument = _
	oDrawView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oOcc As Inventor.ComponentOccurrence = _
	oAssemblyDocument.ComponentDefinition.occurrences.item(1)

Dim oGeneralDimensionsObj As ObjectCollection = _
	oSheet.DrawingDimensions.GeneralDimensions.GetRetrievableDimensions(oDrawView, oOcc)

The oGeneralDimensionsObj has now the retrieved dimensions form the first Part.

 

Best regards,

Marco Suurlant

Programmer Engineering
inventor professional 2015
0 Likes
Message 17 of 22

Anonymous
Not applicable

Thanks!!!

0 Likes
Message 18 of 22

Anonymous
Not applicable

I`d like to share the code I assembled from different pieces (see attached). Configurator works great but I have few problems with the drawing dimensions.

 

I`m not sure how to place flat pattern OAL dim`s, can`t place bend dim`s, not sure how to modify flat pattern placement code so it shows bend extents.

 

oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint4, ViewScale,kDefaultViewOrientation, kHiddenLineDrawingViewStyle,,, oBaseViewOptions)

 Also I`m not sure how to do ordinate dim`s for the holes (horizontal & vertical).

If you`d like to test it out don`t forget to change the template path and name in the code.

 

I have an external rule that I run after drawing creation (see below), it places the dimensions I need.

Sub Main
    Dim oDrawDoc As DrawingDocument = ThisDoc.Document
    Dim oSheet As Sheet = oDrawDoc.ActiveSheet
    RetrieveDimByView(oSheet, "VIEW1", "Fr_") ' front view
    RetrieveDimByView(oSheet, "VIEW3", "Rs_") ' right side view
	RetrieveDimByView(oSheet, "VIEW2", "Tv_") ' top view
    'RetrieveDimByView(oSheet, "View3", "RetDTop_")
End Sub

Sub RetrieveDimByView(ByVal oSheet As Sheet, ByVal ViewName As String, ByVal PrefixStr As String)
    Dim oDrawView As DrawingView
    For Each oDrawView In oSheet.DrawingViews
        If oDrawView.Name = ViewName Then
            Exit For
        End If
    Next
    Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
    oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)
    Dim oGeneralDimension As GeneralDimension
    For Each oGeneralDimension In oGeneralDimensionsEnum
        Dim oParameter As Parameter
        Try
            oParameter = oGeneralDimension.RetrievedFrom.Parameter
        Catch
            ' Error to set oParameter.
            ' Go further to delete the dimension.
        End Try
        If oParameter.DrivenBy.count <> 0 Then
            Dim oDrivenByParameter As Parameter
            For Each oDrivenByParameter In oParameter.DrivenBy
                If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
                    oGeneralDimension.Delete
                End If
            Next
        Else
            If InStr(oParameter.Name, PrefixStr) = 0 Then
                oGeneralDimension.Delete
            End If
        End If
    Next
    oSheet = Nothing
	
	
	Dim oCommandMgr As CommandManager = _
    ThisApplication.CommandManager

    oCommandMgr.ControlDefinitions.item("DrawingSelectAllInventorDimsCmd").Execute
    oCommandMgr.ControlDefinitions.item("DrawingArrangeDimensionsCmd").Execute
	
End Sub

 Would be great to add a code that automatically scales up/down the views and places them on the sheet.

 

Any help appreciated. Thanks,

0 Likes
Message 19 of 22

Anonymous
Not applicable

The Following code suggested by you is performing the necessary action but ends with "Unexpected error".

Also it is retrieving the dimension without the special characters like "RteD_". Please guide me.

 

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)

Dim PrefixStr As String = "RetD_"

Dim oGeneralDimension As GeneralDimension
For Each oGeneralDimension In oGeneralDimensionsEnum
    Dim oParameter As Parameter
Try
oParameter = oGeneralDimension.RetrievedFrom.Parameter
Catch
' Error to set oParameter.
' Go further to delete the dimension.
End Try

    If oParameter.DrivenBy.count <> 0 Then
        Dim oDrivenByParameter As Parameter
        For Each oDrivenByParameter In oParameter.DrivenBy
            If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
                oGeneralDimension.Delete
            End If
        Next
Else
        If InStr(oParameter.Name, PrefixStr) = 0 Then
            oGeneralDimension.Delete
        End If
    End If
Next

0 Likes
Message 20 of 22

marco_suurlant
Enthusiast
Enthusiast

Hello,

 

I have tested the code on my side and it is working, the test part is included.

If it is still not working can you include the part.

 

Best regards,

 

Marco

Marco Suurlant

Programmer Engineering
inventor professional 2015
0 Likes