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?
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
(Not an Autodesk Employee)
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.
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:
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
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.
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
Can't find what you're looking for? Ask the community or share your knowledge.