general Drawing Dimension .

general Drawing Dimension .

Anonymous
Not applicable
846 Views
6 Replies
Message 1 of 7

general Drawing Dimension .

Anonymous
Not applicable

Hello All,

I am getting a problem for creating automatic dimension. I am done with " Retrived Dimension " and "two arc select dimension" methods.Please give me the solution of general drawing dimension so that i will try to work on it too.

 

                           Thank You...!!

0 Likes
Accepted solutions (2)
847 Views
6 Replies
Replies (6)
Message 2 of 7

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 

Here is the sample code in VBA.

This code will add General Dimensions to the straight line segments on the active drawing document.

I think you can translate this to other languages (such as C#).

 

Sub test()
    Dim drwDoc As DrawingDocument
    Set drwDoc = ThisApplication.ActiveDocument
    
    Dim sheet As sheet
    Set sheet = drwDoc.ActiveSheet
    
    Dim drwView As DrawingView
    Set drwView = sheet.DrawingViews(1)
    
    Dim gds As GeneralDimensions
    Set gds = sheet.DrawingDimensions.GeneralDimensions
    
    Dim dcs As DrawingCurvesEnumerator
    Set dcs = drwView.DrawingCurves
    
    Dim intentOne As GeometryIntent
    
    Dim dc As DrawingCurve
    Dim dcSegs As DrawingCurveSegments
    Dim dcSeg As DrawingCurveSegment
    
    For Each dc In dcs
        Set dcSegs = dc.Segments
        If dc.CurveType = kLineSegmentCurve And dcSegs.Count = 1 Then
            Set dcSeg = dcSegs.Item(1)
            If (Not dcSeg.StartPoint Is Nothing) And (Not dcSeg.EndPoint Is Nothing) Then
                Dim textOrigin As Point2d
                Set textOrigin = ThisApplication.TransientGeometry.CreatePoint2d
                textOrigin.X = (dcSeg.StartPoint.X + dcSeg.EndPoint.X) / 2
                textOrigin.Y = (dcSeg.StartPoint.Y + dcSeg.EndPoint.Y) / 2
                Set intentOne = drwDoc.Sheets(1).CreateGeometryIntent(dc)
                gds.AddLinear textOrigin, intentOne
            End If
        End If
    Next dc
End Sub

 

The result is...

capture.PNG

 

 

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 3 of 7

Anonymous
Not applicable

Thanks for giving me the solution..Can you please give this in c#..

Thank you..

0 Likes
Message 4 of 7

Anonymous
Not applicable

GeneralDimensions gds = oSheet.DrawingDimensions.GeneralDimensions;
DrawingCurvesEnumerator dcs = oView.DrawingCurves;

GeometryIntent intent1;

DrawingCurve dc;
DrawingCurveSegments dcSegs;
DrawingCurveSegment dcSeg;

foreach (var dc in dcs)
{
dcSegs = dc.Segments;
if (dc.CurveType == kLineSegmentCurve & dcSegs.Count == 1)
{
dcSeg = dcSegs.Item[1];
}

if ((!dcSeg.StartPoint == null) & (!dcSeg.EndPoint == null))
{
Point2d textOrigin;
textOrigin = application.TransientGeometry.CreatePoint2d();

textOrigin.X = (dcSeg.StartPoint.X + dcSeg.EndPoint.X) / 2;
textOrigin.Y = (dcSeg.StartPoint.Y + dcSeg.EndPoint.Y) / 2;
intent1 = oDrawDoc1.Sheets[1].CreateGeometryIntent(dc);
gds.AddLinear(textOrigin, intent1);
}
}

 

 

 

 

I did like this..This is giving error-------->foreach (var dc in dcs)------>dc cannot be declared in this scope because that name is used in an enclosing local scope to define a local or paramter..

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

DrawingView targetView = oSheet.DrawingViews[1];

GeneralDimensions gds = (GeneralDimensions) oSheet.DrawingDimensions.GeneralDimensions;
DrawingCurvesEnumerator dcs = oView.DrawingCurves;

GeometryIntent intent1 = default(GeometryIntent);
DrawingCurveSegments dcSegs = default(DrawingCurveSegments);

dcSegs = oDrawDoc1.SelectSet[1];

DrawingCurve dc = default(DrawingCurve);

DrawingCurveSegment dcSeg = default(DrawingCurveSegment);

foreach (var DrawingCurve in dcs)
{

dcSegs = dc.Segments;
if (dc.CurveType == CurveTypeEnum.kLineSegmentCurve && dcSegs.Count == 1)
{
dcSeg = (DrawingCurveSegment)dcSegs[1];
}

if (!(dcSeg.StartPoint == null) && (!(dcSeg.EndPoint == null)))
{
Point2d textOrigin;
textOrigin = application.TransientGeometry.CreatePoint2d();

textOrigin.X = (dcSeg.StartPoint.X + dcSeg.EndPoint.X) / 2;
textOrigin.Y = (dcSeg.StartPoint.Y + dcSeg.EndPoint.Y) / 2;
intent1 = oDrawDoc1.Sheets[1].CreateGeometryIntent(dc);
gds.AddLinear(textOrigin, intent1);
}
}

 

 

------ I draw the code like this...there is no error but its not working     ---->

foreach (var DrawingCurve in dcs)
{

dcSegs = dc.Segments;

0 Likes
Message 6 of 7

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 

Here is the code that has been rewritten in C#.

try
{
    if (!(application.ActiveEditDocument is DrawingDocument oDrawDoc1))
    {
        return;
    }
    Sheet targetSheet = oDrawDoc1.ActiveSheet;
    if (targetSheet == null || targetSheet.DrawingViews.Count == 0)
    {
        return;
    }
    DrawingView targetView = targetSheet.DrawingViews[1];

    foreach (DrawingCurve drawingCurve in targetView.DrawingCurves)
    {
        DrawingCurveSegments drawingCureveSegments = drawingCurve.Segments;
        if (drawingCurve.CurveType == CurveTypeEnum.kLineSegmentCurve && drawingCureveSegments.Count == 1)
        {
            DrawingCurveSegment drawingCurveSegment = drawingCureveSegments[1];
            if (drawingCurveSegment.StartPoint != null && drawingCurveSegment.EndPoint != null)
            {
                Point2d textOrigin = application.TransientGeometry.CreatePoint2d();

                textOrigin.X = (drawingCurveSegment.StartPoint.X + drawingCurveSegment.EndPoint.X) / 2;
                textOrigin.Y = (drawingCurveSegment.StartPoint.Y + drawingCurveSegment.EndPoint.Y) / 2;
                GeometryIntent intentOne = targetSheet.CreateGeometryIntent(drawingCurve);
                targetSheet.DrawingDimensions.GeneralDimensions.AddLinear(textOrigin, intentOne);
            }
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

Hacking APIs is easier in VBA than C#.

How about using VBA to explore APIs?

 

I always understand how the APIs work in VBA well and then write AddIn codes in C#.

Hacking the APIs in C#(or VB.net) requires much effort than in VBA because we must restart Inventor when the code is changed.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 7 of 7

Anonymous
Not applicable

Thank you for taking the time to help me out. Sorry I forgot to mention it but I am completely new to api and so far my experience have been to get codes from forums/help file then modify them to fit my need. I did try to build upon the example you provided me but I couldn’t get anywhere after researching for a while. Attached is what I did based on your suggestion not sure if I even did that right, could you build upon it when you get the chance.

 

Sincerely,

0 Likes