Inventor Customization

Inventor Customization

Reply
Distinguished Contributor
achmidt
Posts: 130
Registered: ‎07-21-2011
Message 11 of 21 (451 Views)

Re: Retrieve dimensions

10-16-2012 01:03 PM in reply to: theo.bot

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.

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Contributor
marco.suurlant
Posts: 19
Registered: ‎05-22-2008
Message 12 of 21 (439 Views)

Re: Retrieve dimensions

10-17-2012 02:39 AM in reply to: achmidt

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

Re: Retrieve dimensions

10-19-2012 08:50 AM in reply to: marco.suurlant

Excellent works just great.

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

 

Thanks,

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: 79
Registered: ‎09-30-2005
Message 14 of 21 (399 Views)

Re: Retrieve dimensions

10-22-2012 02:46 AM in reply to: achmidt

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

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

Re: Retrieve dimensions

10-22-2012 09:51 AM in reply to: achmidt

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 2011 / 2012 / 2013
Contributor
marco.suurlant
Posts: 19
Registered: ‎05-22-2008
Message 16 of 21 (378 Views)

Re: Retrieve dimensions

10-23-2012 12:33 AM in reply to: marco.suurlant

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

Re: Retrieve dimensions

11-01-2012 01:03 PM in reply to: achmidt

Thanks!!!

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Distinguished Contributor
achmidt
Posts: 130
Registered: ‎07-21-2011
Message 18 of 21 (337 Views)

Re: Retrieve dimensions

11-02-2012 06:57 AM in reply to: marco.suurlant

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,

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Member
Prasad.pet
Posts: 3
Registered: ‎07-21-2014
Message 19 of 21 (77 Views)

Re: Retrieve dimensions

07-21-2014 02:40 AM in reply to: marco.suurlant

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

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

Re: Retrieve dimensions

07-22-2014 01:59 AM in reply to: Prasad.pet

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 2011 / 2012 / 2013
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.