Retrieving endpoint of an extensionline

Retrieving endpoint of an extensionline

Anonymous
Not applicable
990 Views
12 Replies
Message 1 of 13

Retrieving endpoint of an extensionline

Anonymous
Not applicable

Hi,

I'm trying retrieve the endpoint of an extensionline via C#. I use the property ExtensionLineOne of a LinearDimensionObject. Via the debug-window of Visual Studio I know that ExtensionLineOne has a property "EndPoint".

The problem lays in the fact that ExtensionLineOne is defiend as an Object and an object hasn't got a property Endpoint. So in C# I always get an compilation error. I've tried casting ExtensionLineOne to all kind of things, but no succes.

What can I do to retieve the endpoints of an extensionline using C# ?

 

Cheers,

Mark Brouwers

 

 

0 Likes
991 Views
12 Replies
Replies (12)
Message 2 of 13

frederic.vandenplas
Collaborator
Collaborator

HI,

 

You need to declare the dimensionline as a LineSegment2d

This example gets the endpoint of the dimensionline (vba) , hope it helps!

If you debug in vba, you can find this easy by creating a watch.

 

 

Sub ExtensionLine()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

Dim oDim As GeneralDimension
Dim oDimLine As LineSegment2d

For Each oDim In oSheet.DrawingDimensions.GeneralDimensions

Set oDimLine = oDim.DimensionLine

Debug.Print oDimLine.EndPoint.X

Next oDim
End Sub

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 13

Anonymous
Not applicable

Thanks Frederic for your swift reply.

The problems lays in the fact that I use c#. When I get a reference to the extensionline (not dimensionline), the compiler sees this as an object, and an object does not have a definition of an endpoint so the complier does not compile. I need to cast this extensionline into an other object that contains the definition of an endpoint. I know that C# works stongly typed and that's my problem right now !.

 

Hopelijk heb ik het iets wat duidelijk kunnen uitdrukken.

 

Cheers,

Mark

0 Likes
Message 4 of 13

frederic.vandenplas
Collaborator
Collaborator


DrawingDocument oDrawDoc = ThisApplication.ActiveDocument;

Sheet oSheet = oDrawDoc.ActiveSheet;

GeneralDimension oDim = default(GeneralDimension);
LineSegment2d oDimLine = default(LineSegment2d);


foreach ( oDim in oSheet.DrawingDimensions.GeneralDimensions) {
oDimLine = oDim.DimensionLine;

Debug.Print oDimLine.EndPoint.X

}

 

Hopelijk helpt dit!

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 5 of 13

Anonymous
Not applicable

Hi,

I've tried what you suggested but I still got the same compilation error :

Screen Shot 09-08-16 at 08.35 PM.PNG

 

I think this problem has more to do with c# (late/early binding) than with Inventor, but there has to be some kind of solution !

 

Cheers,

Mark

 

0 Likes
Message 6 of 13

frederic.vandenplas
Collaborator
Collaborator

Could you please provide te code, otherwise i have to recreate it in a language i'm not familiar with.

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 7 of 13

Anonymous
Not applicable

Here is the code. Please mind the fact I'm using ETO, so some APIfunctions may look unfamiliar.

 

	try
			{
				Render_Intentmodel();
				Part topview = Get_TopView(Intent.IntentAPI.ActiveRoot);
				Value[] dimensions_intent = topview.EvaluateExpression(new Source("GetChildrenOfType(me,{:ivlineardimension})")).ToList();
				foreach (var dim_intent in dimensions_intent)
				{
					object dim_inventor = Intent.HostObjectFromPart(dim_intent);
					if (dim_inventor == null)
						((Part)dim_intent).SetRuleValue("visible?", new Value(false));
					else
						((Part)dim_intent).SetRuleValue("visible?", new Value(true));
				}

				DrawingDimensions dims = ((DrawingDocument)_Inventorapplication.ActiveDocument).ActiveSheet.DrawingDimensions;

				LinearGeneralDimension dim;
				foreach (var d in dims)
				{
					dim = d as LinearGeneralDimension;
					string s = Intent.RefChainFromHostObject(dim);
					Part p = Intent.IntentAPI.Utilities.GetPart(s);
					if (p != null)
						p.SetRuleValue("textOrigin", new Value(new Autodesk.Intent.Point(dim.Text.Origin.X * 10, dim.Text.Origin.Y * 10)));
					else
					{
						////Dimensie bestaat niet in intent
					
						dynamic  oExtLine = default(LineSegment2d);
						Point2d ptEnd;
						
						oExtLine = dim.ExtensionLineOne;
						ptEnd=oExtLine.EndPoint;

						Autodesk.Intent.Parameters parameters = new Autodesk.Intent.Parameters(new Name("ivlineardimension"));

						parameters.Add("origin", new Value((new Autodesk.Intent.Point(ptEnd.X * 10, ptEnd.Y * 10))));
						parameters.Add("radius", new Value(1));
						parameters.Add("Startangle", new Value(0));
						parameters.Add("Endangle", new Value(360));
						ChildRule cirkelExt1 = topview.GetDynamicRules().AddChild(Intent.IntentAPI.Utilities.UniqueName("Extensionpoint"), parameters);

						oExtLine = dim.ExtensionLineTwo;
						ptEnd = oExtLine.EndPoint;

						parameters = new Autodesk.Intent.Parameters(new Name("IvSketchArc"));
						parameters.Add("origin", new Value((new Autodesk.Intent.Point(ptEnd.X * 10, ptEnd.Y * 10))));
						parameters.Add("radius", new Value(10));
						parameters.Add("Startangle", new Value(0));
						parameters.Add("Endangle", new Value(360));
						ChildRule cirkelExt2 = topview.GetDynamicRules().AddChild(Intent.IntentAPI.Utilities.UniqueName("Extensionpoint"), parameters);

					}
				}
				Render_Intentmodel();
			}
			catch (System.Exception ex)
			{
				DisplayMessage(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name);
			}

The code goes (raise an exception, see other posts) wrong when it reaches/executes the red colored line.

 

Cheers,

Mark

0 Likes
Message 8 of 13

ekinsb
Alumni
Alumni

You can use either one of the two lines before to cast the variable to a more specific type.  The first uses the "as" operator and the second uses traditional casting syntax.

 

Inventor.LineSegment2d oExtLine = dim.ExtensionLineOne as Inventor.LineSegment2d;

Inventor.LineSegment2d oExtLine = (Inventor.LineSegment2d) dim.ExtensionLineOne;

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 13

Anonymous
Not applicable

Brian,

Changed the line of code accordingly, but I still got an exception : 

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)).

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.LinearGeneralDimension.get_ExtensionLineOne()
at WPC_Addin.UI.frmWPC.btnAdoptDimensies_Click(Object sender, EventArgs e)

 

Any ideas left ?

 

Cheers,

Mark

0 Likes
Message 10 of 13

ekinsb
Alumni
Alumni

Can you please post or send me (brian.ekins@autodesk.com) a drawing that you're having problems with.  You can delete everything but the dimension that's causing the problems.  I suspect that what you're getting back isn't a line.  I don't remember why the return type of the ExtensionLineOne is typed as an Object but it must be because there are cases where something other than a line is returned.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 11 of 13

Anonymous
Not applicable

Brian,

Could it have anything to do with the fact that I place a dimension on 2 different entities ? Because if I place a dimension on 1 entity, I don't get the error and the code works ! As soon as I place a dimension on 2 different (parallel) lines, I get the error.

 

Cheers,

Mark

0 Likes
Message 12 of 13

ekinsb
Alumni
Alumni

I'm still not able to reproduce the problem.  Can you attach a simple drawing with a dimension that demonstrates the problem?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 13 of 13

gkniksch_aep
Contributor
Contributor

I know this is an old thread, but just in case others are coming across this looking for info...

I was recently working through a situation where I wanted to attach sketch symbols to the ends of dimension lines as I created them. I noticed that the extension lines were not available to cast to LineSegment2d objects when the dimension is created between two existing lines on the drawing. I was creating the dimensions between centerlines associated with planes in the model so no extension lines needed to exist. If I had moved the text origin point out further past the endpoints of the centerlines, then the extension lines would exist and I could cast them.

0 Likes