VB.net create drawing dimensions for an assembly

VB.net create drawing dimensions for an assembly

BromanSillito
Advocate Advocate
1,632 Views
1 Reply
Message 1 of 2

VB.net create drawing dimensions for an assembly

BromanSillito
Advocate
Advocate

I'm trying to create dimensions for an assembly in an Inventor drawing using VB.net. I found a function that uses workpoints to create the dimension. However, when I run the function, it finds the workpoints, makes them visible, but gives an exception

{"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"} when it gets to the point where it is supposed to create the dimension. I am running Inventor 2016 update 2. Here is the sub I'm using to create the dimension:

 

Public Sub DimToWorkPoints(ByVal DrawView As DrawingView,
                                    ByVal WorkPoint1 As WorkPoint,
                                    ByVal WorkPoint2 As WorkPoint,
                                    ByVal TextPosition As Point2d,
                                    ByVal AlignmentType As DimensionAlignmentTypeEnum)
        Try
            Dim sheet As Sheet
            sheet = DrawView.Parent
            ' Create centermarks based on the work points. 
            Dim marks(1) As Centermark
            marks(0) = sheet.Centermarks.AddByWorkFeature(WorkPoint1, DrawView)
            'marks(0).Visible = False
            marks(1) = sheet.Centermarks.AddByWorkFeature(WorkPoint2, DrawView)
            'marks(1).Visible = False
            ' Create geometry intents for the center marks. 
            Dim intent1 As GeometryIntent
            intent1 = sheet.CreateGeometryIntent(marks(0))
            Dim intent2 As GeometryIntent
            intent2 = sheet.CreateGeometryIntent(marks(1))
            ' Add a dimension. 
            MsgBox(AlignmentType.ToString)
            Dim genDim As GeneralDimension
            genDim = sheet.DrawingDimensions.GeneralDimensions.AddLinear(TextPosition, intent1, intent2, AlignmentType)
        Catch ex As Exception
        End Try
    End Sub

 

 

Here is the list showing the exception I get:

 

DimensionException.JPG

 

I've also attached the code that calls out the sub. Can anyone give me a hand with this?

0 Likes
Accepted solutions (1)
1,633 Views
1 Reply
Reply (1)
Message 2 of 2

xiaodong_liang
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

Since your code contains some your own functions that do not work at my side, I followed your workflow to create the isolated code as below. It works well, the files I tested with are also attached. Hope it helps you to diagnose the problem at your side.

 

   Public Sub CreateViews_ADNTest()

        Dim oInventorApplication As Inventor.Application
        Try
            oInventorApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch
        End Try

        Dim oDrawDoc As DrawingDocument = oInventorApplication.ActiveDocument

        Dim oSheet As Sheet = oDrawDoc.ActiveSheet

        Dim oView As DrawingView = oSheet.DrawingViews(1)

        Dim oRefDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument

        Dim WorkPoint1 As WorkPoint = oRefDoc.ComponentDefinition.WorkPoints(1)
        Dim WorkPoint2 As WorkPoint = oRefDoc.ComponentDefinition.WorkPoints(2)

        Dim oTG As TransientGeometry = oInventorApplication.TransientGeometry
         
        Try
 
            ' Create centermarks based on the work points. 
            Dim marks(1) As Centermark
            marks(0) = oSheet.Centermarks.AddByWorkFeature(WorkPoint1, oView)
            'marks(0).Visible = False
            marks(1) = oSheet.Centermarks.AddByWorkFeature(WorkPoint2, oView)
            'marks(1).Visible = False
            ' Create geometry intents for the center marks. 
            Dim intent1 As GeometryIntent
            intent1 = oSheet.CreateGeometryIntent(marks(0))
            Dim intent2 As GeometryIntent
            intent2 = oSheet.CreateGeometryIntent(marks(1))

            Dim oTextPosition As Point2d = oTG.CreatePoint2d(0, 0)

            Dim genDim As GeneralDimension
            genDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oTextPosition, intent1, intent2, DimensionTypeEnum.kAlignedDimensionType)

        Catch ex As Exception
        End Try 


    End Sub