Need Help in Dimension through API

Need Help in Dimension through API

Anonymous
Not applicable
1,074 Views
8 Replies
Message 1 of 9

Need Help in Dimension through API

Anonymous
Not applicable

Hi ,

 

I am new to coding part I need your help in generating dimension between two edges of sheet metal unfolded view pattern, I am unable to select the drawing curve of  view for those edges .

My coding is,

Edge Edge1, Edge2;

object obj1, obj2;
Inventor.ObjectCollection Obj;
Obj = invApp.TransientObjects.CreateObjectCollection();
Obj = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", EdgeName1);
Edge1 = (Edge)Obj[1];
Obj = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", EdgeName2);
Edge2 = (Edge)Obj[1];
Inventor.Point2d Point1, Point2;
DrawingCurvesEnumerator DrgCurveEnum;
DrawingCurve DrgCurve1 = null; ;
DrawingCurve DrgCurve2 = null;

 

/*getting error in getting drgcurveenum in below*/..................

 

DrgCurveEnum = CurrView.DrawingCurves[Edge1];
DrgCurve1 = DrgCurveEnum[1];

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

 

InsPt = invApp.TransientGeometry.CreatePoint2d(CurrView.Position.X + 2, CurrView.Position.Y + 2);
GeneralDimensions oGeneralDims;
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions;

GeneralDimension oDim;
oDim = (GeneralDimension)oGeneralDims.AddLinear(InsPt, oSheet.CreateGeometryIntent(DrgCurve1), oSheet.CreateGeometryIntent(DrgCurve2), DimType);




please help me i had also attached the screenshot of which dimension i need.

0 Likes
Accepted solutions (1)
1,075 Views
8 Replies
Replies (8)
Message 2 of 9

fidel.makatiaD5W7V
Alumni
Alumni

Hi @Anonymous ,

Have you tried  to select the drawing curves in the following manner ?

Inventor 2022 Help | Create linear foreshortened dimension sample | Autodesk

if not kindly check it and let me know if it works 



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 3 of 9

Anonymous
Not applicable
@fidel.makatiaD5W7V Thanks for your reply, but I want to select /generate drawing curve through coding ,I can able to do manual selection and get dimension. I am using attribute manager to assign name to edge & filtering. Any other method of dimensioning without drawing curve?
0 Likes
Message 4 of 9

fidel.makatiaD5W7V
Alumni
Alumni

Hi @Anonymous so you want to run a code that creates dimensions automatically without selecting it on the application? If I am getting you correctly that is 

Kindly clarify this



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 5 of 9

fidel.makatiaD5W7V
Alumni
Alumni

You can also dimension the distance between sketch points

 

 



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 6 of 9

Anonymous
Not applicable

@fidel.makatiaD5W7V thanks for your help, any sample code/reference ?
0 Likes
Message 7 of 9

fidel.makatiaD5W7V
Alumni
Alumni
Accepted solution

Check out this C# code that uses drawing curves to automatically set dimensions, try applying it to your context and let me know if it worked. If not you can send me your code I try it on my end 

DrawingDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
                                                      mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject, 
                                                        SystemOfMeasureEnum.kDefaultSystemOfMeasure, 
                                                        DraftingStandardEnum.kDefault_DraftingStandard, 
                                                        null), 
                                                      true) as DrawingDocument;

            //Create a new B size sheet.
            Sheet oSheet = oDoc.Sheets.Add(DrawingSheetSizeEnum.kBDrawingSheetSize,  
                                           PageOrientationTypeEnum.kDefaultPageOrientation, 
                                           "A Size", 0, 0);

            //Add the default border.
            oSheet.AddDefaultBorder(null, null, null, null, null, null, null, null, null, null, null, null, null, null);

            //Add ANSI A TitleBlock
            TitleBlock oTitleBlock = oSheet.AddTitleBlock(oDoc.TitleBlockDefinitions["ANSI A"], null, null);
            
            //Open the part document, invisibly.
            PartDocument oBlockPart = mApp.Documents.Open(@"C:\Temp\TestPart.ipt", false) as PartDocument;
            
            TransientGeometry oTG = mApp.TransientGeometry;

            //Create base drawing view
            DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document,
                                                                    oTG.CreatePoint2d(10, 10), 1,
                                                                    ViewOrientationTypeEnum.kFrontViewOrientation, 
                                                                    DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null);

            //Create Projected views
            DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView, 
                                                                          oTG.CreatePoint2d(20, 18), 
                                                                          DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);

            DrawingView oIsoView = oSheet.DrawingViews.AddProjectedView(oBaseView, 
                                                                        oTG.CreatePoint2d(10, 20), 
                                                                        DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);


            //Find an edge in the part to dimension.  Any method can be used, (attributes, B-Rep query, selection, etc.).  This
            //looks through the curves in the drawing view and finds the top horizontal curve.

            DrawingCurve oSelectedCurve = null;

            foreach(DrawingCurve oCurve in oBaseView.get_DrawingCurves(null))
            {
                //Skip Circles
                if(oCurve.StartPoint!=null && oCurve.EndPoint!=null)
                {
                    if(WithinTol(oCurve.StartPoint.X, oCurve.EndPoint.X, 0.001))
                    {
                        if(oSelectedCurve == null)
                        {
                            //This is the first horizontal curve found.
                            oSelectedCurve = oCurve;
                        }
                        else
                        {
                            //Check to see if this curve is higher (smaller x value) than the current selected
                            if(oCurve.MidPoint.X < oSelectedCurve.MidPoint.X) 
                            {
                                oSelectedCurve = oCurve;
                            }
                        }
                    }
                }
            }

            if (oSelectedCurve == null)
            {
                System.Windows.Forms.MessageBox.Show("no curve is selected!");
                return;
            }


            //Create geometry intents point for the curve.
            GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent);
            GeometryIntent oGeomIntent2 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent);

            GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions;

            Point2d oDimPos = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y);

            DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Default (ANSI)"];

            Layer layer = oDoc.StylesManager.Layers["Dimension (ANSI)"];

            //Create the dimension.
            LinearGeneralDimension oLinearDim; 
            oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, 
                                                      DimensionTypeEnum.kAlignedDimensionType, true, 
                                                      dimstyle, 
                                                      layer);

        private bool WithinTol(double Value1, double Value2, double tol)
        {
            return (Math.Abs(Value1 - Value2) < tol);
        }


Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 8 of 9

theo.bot
Collaborator
Collaborator

I see that you already used the ilogic named entities. can't you do it with the standard snippet for a linear dimension. in this case I defined an additional Named geometry because you have two edges:

 

Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim namedGeometry1 = VIEW1.GetIntent("Edge1")
Dim namedGeometry2 = VIEW1.GetIntent("Edge2")
Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW1.SheetPoint(0.5, -0.1), namedGeometry1,namedGeometry2)

 

0 Likes
Message 9 of 9

Anonymous
Not applicable

Thanks for your quick Reply , yes i am using attribute edge naming  but in API I cannot find the type Get Intent,  any how managed by creating drawing curve.

0 Likes