Problem in creating linear foreshortened dimensions using C# or vb.net

Problem in creating linear foreshortened dimensions using C# or vb.net

nimisha_nooti
Explorer Explorer
461 Views
5 Replies
Message 1 of 6

Problem in creating linear foreshortened dimensions using C# or vb.net

nimisha_nooti
Explorer
Explorer

 I'm encountering an issue with the 'AddLinearForeshortened' method when dimensioning, and the error message I receive is as follows: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)). Has anyone experienced a similar issue or can provide guidance on resolving this error in the context of dimensioning?

 

 

ForeshortenedDim.PNG

0 Likes
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

What I can see of the code looks OK.  Maybe if that specified Sheet object was not the 'active' one, that may cause an error.  I think that sheet may need to be active, before you can add dimensions to it.  Just one possible guess at this point.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

nimisha_nooti
Explorer
Explorer

The Sheet object is 'active,' and when I attempt to create dimensions using "AddLinear," it works fine. However, I am facing issue specifically with the 'AddLinearForeshortened' method. My current versions are Autodesk Inventor 2024 and Visual Studio 2019.

 

 

lineardim.png

0 Likes
Message 4 of 6

BM_Ashraf
Advocate
Advocate

Hi,

The Code looks fine.
Maybe you should debug it and check the values of Intent1 and intent2 (GI1 & GI2).

 

Otherwise check the code Samples:

 

Have a drawing document open and select two paralell linear drawing curve segments in the same drawing view and run the following macro.
Sub CreateLinearForeshortenedDimSample()
    ' Open a drawing document and select two parallel linear curves in same drawing view first.
    Dim oApp As Inventor.Application
    Set oApp = ThisApplication
    
    Dim oDoc As Document
    Set oDoc = oApp.ActiveDocument
    If Not (oDoc Is Nothing) Then
        If Not (oDoc.DocumentType = kDrawingDocumentObject) Then
            MsgBox "Please activate a drawing document for this sample.", vbCritical, "Inventor"
            Exit Sub
        End If
    Else
        MsgBox "Please open a drawing document for this sample.", vbCritical, "Inventor"
        Exit Sub
    End If
    
    If Not (oDoc.SelectSet.Count = 2) Then
        MsgBox "Please select two parallel linear drawing curves from same drawing view for this sample.", vbCritical, "Inventor"
        Exit Sub
    ElseIf (oDoc.SelectSet(1).Type <> kDrawingCurveSegmentObject Or oDoc.SelectSet(1).Type <> kDrawingCurveSegmentObject) Then
        MsgBox "Please select two parallel linear drawing curves from same drawing view for this sample.", vbCritical, "Inventor"
        Exit Sub
    End If
   
    Dim oCurve1 As DrawingCurve, oCurve2 As DrawingCurve
    Set oCurve1 = oDoc.SelectSet(1).Parent
    Set oCurve2 = oDoc.SelectSet(2).Parent
    
    Dim oSheet As Sheet
    Set oSheet = oCurve1.Parent.Parent
    
    ' Create two GeometryIntent based on the selected drawing curve segments.
    Dim oIntent1 As GeometryIntent, oIntent2 As GeometryIntent
    Set oIntent1 = oSheet.CreateGeometryIntent(oCurve1)
    Set oIntent2 = oSheet.CreateGeometryIntent(oCurve2)
    
    Dim oTextPos As Point2d
    Set oTextPos = oApp.TransientGeometry.CreatePoint2d(12, 12)
    
    ' Create the linear foreshortened dimension
    Dim oLinearForeshortenedDim As LinearGeneralDimension
    Set oLinearForeshortenedDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinearForeshortened(oTextPos, oIntent1, oIntent2, True)
    
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 5 of 6

nimisha_nooti
Explorer
Explorer

Hi, thanks for addressing my issue. I've checked the Intent values, and they are working fine; I can generate linear dimensions using these Intents. However, I specifically need foreshortened dimensions, and that method is not working for me. I also tried the provided macro, even in that case, the 'AddLinearForeshortened' method throws a runtime error. I suspect this issue might be related to the Autodesk Inventor version, but I'm not certain. Any insights would be appreciated.

Message 6 of 6

BM_Ashraf
Advocate
Advocate

Hi,
If you are using an IV Version newer than 2015 then it should work. Otherwise the forshortened dimension has a problem with the Entities or the text position.
I had a similar problem shortly with adding diameter dimension, and the solution was only chaning the position of the Text Position .
Another Idea, you can create Linear General dimension and change the Arrows and Extension lines visability.

Sub CreateLinearForeshortenedDimSample()
    ' Open a drawing document and select two parallel linear curves in same drawing view first.
    Dim oApp As Inventor.Application
    Set oApp = ThisApplication
    
    Dim oDoc As Document
    Set oDoc = oApp.ActiveDocument
    If Not (oDoc Is Nothing) Then
        If Not (oDoc.DocumentType = kDrawingDocumentObject) Then
            MsgBox "Please activate a drawing document for this sample.", vbCritical, "Inventor"
            Exit Sub
        End If
    Else
        MsgBox "Please open a drawing document for this sample.", vbCritical, "Inventor"
        Exit Sub
    End If
    
    If Not (oDoc.SelectSet.Count = 2) Then
        MsgBox "Please select two parallel linear drawing curves from same drawing view for this sample.", vbCritical, "Inventor"
        Exit Sub
    ElseIf (oDoc.SelectSet(1).Type <> kDrawingCurveSegmentObject Or oDoc.SelectSet(1).Type <> kDrawingCurveSegmentObject) Then
        MsgBox "Please select two parallel linear drawing curves from same drawing view for this sample.", vbCritical, "Inventor"
        Exit Sub
    End If
   
    Dim oCurve1 As DrawingCurve, oCurve2 As DrawingCurve
    Set oCurve1 = oDoc.SelectSet(1).Parent
    Set oCurve2 = oDoc.SelectSet(2).Parent
    
    Dim oSheet As Sheet
    Set oSheet = oCurve1.Parent.Parent
    
    ' Create two GeometryIntent based on the selected drawing curve segments.
    Dim oIntent1 As GeometryIntent, oIntent2 As GeometryIntent
    Set oIntent1 = oSheet.CreateGeometryIntent(oCurve1)
    Set oIntent2 = oSheet.CreateGeometryIntent(oCurve2)
    
    Dim oTextPos As Point2d
    Set oTextPos = oApp.TransientGeometry.CreatePoint2d(12, 12)
    
   ' Create the linear foreshortened dimension
Dim oLinearForeshortenedDim As LinearGeneralDimension
'Set oLinearForeshortenedDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinearForeshortened(oTextPos, oIntent1, oIntent2, True)
Set oLinearForeshortenedDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oTextPos, oIntent1, oIntent2, kHorizontalDimensionType)

oLinearForeshortenedDim.SecondArrowheadInside = False
oLinearForeshortenedDim.SecondArrowheadType = kNoneArrowheadType
oLinearForeshortenedDim.ExtensionLineTwoVisible = False
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!