Dimension using edge naming

Dimension using edge naming

nishantkumat5921
Enthusiast Enthusiast
842 Views
3 Replies
Message 1 of 4

Dimension using edge naming

nishantkumat5921
Enthusiast
Enthusiast

Hello,

 

I am trying to create dimensions using edge naming by assigning names to the edges manually and then identifying them and creating dimensions but i am getting an unspecified error in the general dimension creation line below is the code used

 

 

 

public static void Create_Linear_Dimensions_EntityNaming(Inventor.DrawingView CurrView, string PartNameWithoutExt, string OccNameInAssy, string EdgeName1, string EdgeName2, DimensionTypeEnum DimType, double DimGap, bool boolAssembly)
{
try
{
drawingDoc = (DrawingDocument)invApp.ActiveDocument;
Sheet oSheet = drawingDoc.ActiveSheet;
PartDocument oPartDoc = null;
Inventor.AssemblyDocument oAssyDoc = null;
Inventor.ComponentOccurrence CompOcc = null;
Inventor.Document CurrDocument =(Inventor.Document) CurrView.ReferencedDocumentDescriptor.ReferencedDocument;

if (CurrDocument.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
{
oAssyDoc = (AssemblyDocument)CurrDocument;
DrgViewDocuments = new List<Inventor.Document>();
DrgViewCompOcc = new List<Inventor.ComponentOccurrence>();
GetAssyOccurences(oAssyDoc.ComponentDefinition.Occurrences, 0);
for (int i = 0; i <= DrgViewDocuments.Count - 1; i++)
{
CompOcc = DrgViewCompOcc[i];
Inventor.Document CurrDoc = DrgViewDocuments[i];
if ((System.IO.Path.GetFileNameWithoutExtension(CurrDoc.FullDocumentName).ToUpper() == (PartNameWithoutExt).ToUpper() && (CompOcc.Name).ToUpper() == (OccNameInAssy).ToUpper()))

{
oPartDoc = (PartDocument)CurrDoc;
break;
}
}
}
else if (CurrDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)
oPartDoc = (PartDocument)CurrDocument;


Edge Edge1, Edge2;
Inventor.ObjectCollection Obj1,Obj2;

Obj1 = invApp.TransientObjects.CreateObjectCollection();
Obj2 = invApp.TransientObjects.CreateObjectCollection();
Obj1 = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", EdgeName1);
//Edge1 = (Edge)Obj[1];
Obj2 = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", EdgeName2);
// Edge2 = (Edge)Obj[1];

Inventor.Point2d Point1, Point2;
double XPos, YPos;
DrawingCurvesEnumerator DrgCurveEnum;
DrawingCurve DrgCurve1 = null;
DrawingCurve DrgCurve2 = null;
object object1 = null, object2 = null;
EdgeProxy Edge1Proxy = null;
EdgeProxy Edge2Proxy = null;

try
{
if (boolAssembly == true)
{
CompOcc.CreateGeometryProxy(Obj1[1], out object1);
CompOcc.CreateGeometryProxy(Obj2[1], out object2);
Edge1Proxy = (EdgeProxy)object1;
Edge2Proxy = (EdgeProxy)object2;

}
else
{
DrgCurveEnum = CurrView.DrawingCurves[object1];
DrgCurve1 = DrgCurveEnum[1];

DrgCurveEnum = CurrView.DrawingCurves[object2];
DrgCurve2 = DrgCurveEnum[1];

}
} catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

XPos = CurrView.Left + (CurrView.Width / 2); YPos = CurrView.Top;

Point2d point2D = invApp.TransientGeometry.CreatePoint2d(XPos, YPos);


GeneralDimensions oGeneralDims;
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions;

GeneralDimension oDim;

oDim = (GeneralDimension)oGeneralDims.AddLinear(point2D, oSheet.CreateGeometryIntent(object1), oSheet.CreateGeometryIntent(object2), DimensionTypeEnum.kHorizontalDimensionType);//going to catch
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}

 

0 Likes
Accepted solutions (1)
843 Views
3 Replies
Replies (3)
Message 2 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

You try to create a linear dimension with two geometry intents of a drawingcurve. This works afaik only if both drawingcurves are linear, parallel to the other and vertical. In all other cases you have to specify a point on the drawing curve as intent or a second geometry intersecting the first.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 4

nishantkumat5921
Enthusiast
Enthusiast

Hi Krieg thanks for the quick solution but as mentioned above both the edges are linear and parallel to each other still i am facing the issue below is the image showing the edges.. The names are passed as arguments so ignore the code (EdgeName1)

0 Likes
Message 4 of 4

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

No, you have not mentioned that the edges are linear, nor that they are parallel. Only that you start with named edges. 😉

Can you separate the creation of the both geometry intents and check if they are correct? You try to create geometry intents for object1 and object2, which are for a drawing view with a referenced part defined where?

 

I've tested the general functionality with a little VBA script. Works as expected. Maybe this can help you find a solution.

 

Public Sub CreateGeneralDimensions()
    
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet

    Dim oDrawingView As DrawingView
    Set oDrawingView = oActiveSheet.DrawingViews.Item(1)

    Dim oRefedDoc As Document
    Set oRefedDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
    
    Dim oDrawCurve1 As DrawingCurve
    Dim oDrawCurve2 As DrawingCurve

    Dim oObj1 As Object
    Dim oObj2 As Object
    
    Dim oObjColl1 As ObjectCollection
    Dim oObjColl2 As ObjectCollection
    Set oObjColl1 = ThisApplication.TransientObjects.CreateObjectCollection
    Set oObjColl2 = ThisApplication.TransientObjects.CreateObjectCollection
    
    If oRefedDoc.DocumentType = kAssemblyDocumentObject Then
        'check all reference documents to find the we need
        Dim oCompDef As AssemblyComponentDefinition
        Set oCompDef = oRefedDoc.ComponentDefinition
        
        Dim fso As New Scripting.FileSystemObject
        
        Dim oPartDoc As PartDocument
        Dim oOcc As ComponentOccurrence
        For Each oOcc In oCompDef.Occurrences.AllLeafOccurrences
            If fso.GetBaseName(oOcc.Definition.Document.FullDocumentName) = "TestFile" Then '<------------------------- simplified this name check
                Set oPartDoc = oOcc.Definition.Document
                Set oObjColl1 = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "Edge1")
                Set oObjColl2 = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "Edge2")
                Call oOcc.CreateGeometryProxy(oObjColl1.Item(1), oObj1)
                Call oOcc.CreateGeometryProxy(oObjColl2.Item(1), oObj2)
                
                Call CreateGeneralDimension(oActiveSheet, oDrawingView, oObj1, oObj2)
            End If
        Next
    ElseIf oRefedDoc.DocumentType = kPartDocumentObject Then
        Set oObjColl1 = oRefedDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "Edge1")
        Set oObjColl2 = oRefedDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "Edge2")
        Set oObj1 = oObjColl1.Item(1)
        Set oObj2 = oObjColl2.Item(1)
        
        Call CreateGeneralDimension(oActiveSheet, oDrawingView, oObj1, oObj2)
    Else
        'nothing left to do here
        Exit Sub
    End If
    
    
End Sub


Private Sub CreateGeneralDimension(ByVal oActiveSheet As Sheet, ByVal oDrawingView As DrawingView, ByVal oObj1 As Object, ByVal oObj2 As Object)

    Set oDrawCurve1 = oDrawingView.DrawingCurves(oObj1).Item(1)
    Set oDrawCurve2 = oDrawingView.DrawingCurves(oObj2).Item(1)

    Dim oIntent1 As GeometryIntent
    Dim oIntent2 As GeometryIntent
    Set oIntent1 = oActiveSheet.CreateGeometryIntent(oDrawCurve1)
    Set oIntent2 = oActiveSheet.CreateGeometryIntent(oDrawCurve2)
    
    Dim oPlacementPoint As Point2d
    Set oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left + oDrawingView.Width / 2, oDrawingView.Top + 1)

    Dim oGeneralDimension As GeneralDimension
    Set oGeneralDimension = oActiveSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPlacementPoint, oIntent1, oIntent2, kHorizontalDimensionType)

End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com