Inventor Customization

Reply
Valued Contributor
theo.bot
Posts: 65
Registered: ‎09-30-2005
Message 1 of 21 (981 Views)
Accepted Solution

Retrieve dimensions

981 Views, 20 Replies
10-08-2012 06:45 AM

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

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,

Contributor
marco.suurlant
Posts: 19
Registered: ‎05-22-2008
Message 2 of 21 (958 Views)

Re: Retrieve dimensions

10-09-2012 11:54 PM in reply to: theo.bot

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 2011 / 2012 / 2013
Distinguished Contributor
achmidt
Posts: 130
Registered: ‎07-21-2011
Message 3 of 21 (944 Views)

Re: Retrieve dimensions

10-10-2012 01:18 PM in reply to: marco.suurlant

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

Thank you so much!!!

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Valued Contributor
theo.bot
Posts: 65
Registered: ‎09-30-2005
Message 4 of 21 (933 Views)

Re: Retrieve dimensions

10-11-2012 01:39 AM in reply to: theo.bot

:smileyvery-happy:

 

Marco,

 

Thanks, it works great!!

 

Houdoe,:smileywink:

 

gr Theo

 

 

Valued Mentor
jcneal
Posts: 337
Registered: ‎04-10-2010
Message 5 of 21 (924 Views)

Re: Retrieve dimensions

10-11-2012 05:17 AM in reply to: marco.suurlant

 

hi

 

will this rule delete dimensions by hole features?

 

it seems not going to work at that way.

 

thanks.

Autodesk Inventor Professional 2014
Autodesk Product Design Suite Standard 2014
Microsoft Office 2007 & 2013
Windows 7 64bit
Synergis Adept 2014
Visual Studio Express 2010
ADN Support Specialist
xiaodong.liang
Posts: 1,273
Registered: ‎06-12-2011
Message 6 of 21 (884 Views)

Re: Retrieve dimensions

10-16-2012 03:11 AM in reply to: jcneal

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Valued Mentor
jcneal
Posts: 337
Registered: ‎04-10-2010
Message 7 of 21 (875 Views)

Re: Retrieve dimensions

10-16-2012 05:06 AM in reply to: xiaodong.liang

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 2014
Autodesk Product Design Suite Standard 2014
Microsoft Office 2007 & 2013
Windows 7 64bit
Synergis Adept 2014
Visual Studio Express 2010
Contributor
marco.suurlant
Posts: 19
Registered: ‎05-22-2008
Message 8 of 21 (864 Views)

Re: Retrieve dimensions

10-16-2012 07:17 AM in reply to: jcneal

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 2011 / 2012 / 2013
Valued Mentor
jcneal
Posts: 337
Registered: ‎04-10-2010
Message 9 of 21 (860 Views)

Re: Retrieve dimensions

10-16-2012 10:18 AM in reply to: marco.suurlant

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 2014
Autodesk Product Design Suite Standard 2014
Microsoft Office 2007 & 2013
Windows 7 64bit
Synergis Adept 2014
Visual Studio Express 2010
Contributor
marco.suurlant
Posts: 19
Registered: ‎05-22-2008
Message 10 of 21 (852 Views)

Re: Retrieve dimensions

10-16-2012 10:46 AM in reply to: jcneal

 

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 2011 / 2012 / 2013
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.