Creating a sketchpoint reg

Creating a sketchpoint reg

nsatheesan34D64
Advocate Advocate
691 Views
6 Replies
Message 1 of 7

Creating a sketchpoint reg

nsatheesan34D64
Advocate
Advocate

Hi all, 

 

I am creating a sketchpoint at the end of a line using below

Dim oPoint0 As SketchPoint
oPoint0 = ThisApplication.TransientGeometry.CreatePoint(oLine1.EndSketchPoint.Geometry.X, oLine1.EndSketchPoint.Geometry.Y)

 I need to autoselect the sketchpoint later to run another part of the code

 

Dim StartingPoint As SketchPoint = oPoint0


Dim StartingPointSketch As PlanarSketch = StartingPoint.Parent
Dim oRefPlane As WorkPlane = StartingPointSketch.PlanarEntity

StartingPointOffset = ThisApplication.MeasureTools.GetMinimumDistance(StartingPointSketch.OriginPointGeometry, StartingPoint.Geometry3d)
MessageBox.Show(StartingPointOffset)

I am getting the following error:


Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.SketchPoint'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8006A022-ECC4-11D4-8DE9-0010B541CAA8}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

What am I doing wrong ?

0 Likes
692 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @nsatheesan34D64. In the very first line you are declaring the variable's Type as a SketchPoint, but the object you are attempting to set as that variable's value in the next line is a regular Point object, not a SketchPoint.  The Point object is a transient object, which means that it's just a mathematical location with no physical/visible presence.  The SketchPoint object is created using the Sketch.SketchPoints.Add() method, but you have to create the sketch first, before you will have the variable that represents the sketch, then you can use that variable to create the sketch point using that method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

If your variable 'oLine1' represents a SketchLine object, you can get its Parent to get the Sketch, since it already exists.  Then use the variable of that parent sketch object to create the SketchPoint.

 

By the way...what exactly are you trying to accomplish with this bit of code?  It looks like you are trying to get a minimum distance between the end point of a sketch line and the origin point of a sketch, but I'm not sure if its supposed to be the same sketch or not.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

nsatheesan34D64
Advocate
Advocate

Thanks @WCrihfield .. I understood your explanation. Can you give me a sample line for Sketch.SketchPoints.Add()  method as when i modify code to 

oPoint0 = oSketch1.SketchPoints.Add(oLine1.EndSketchPoint.Geometry.X,oLine1.EndSketchPoint.Geometry.Y)

it throws an error : Value of type 'Double' cannot be converted to 'Inventor.Point2d'.

 

This was the code used to create the original line

Dim oSketch1 As PlanarSketch
oSketch1 = odoc.ComponentDefinition.Sketches.Add(odoc.ComponentDefinition.WorkPlanes.Item(4))

Dim oLine1 As SketchLine oLine1 = oSketch1.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(xval, yval), oTransGeom.CreatePoint2d(xval, -(yval -TopofHolesfromCylinderBottomEdge*2.54))) oSketch1.GeometricConstraints.AddMidpoint(oLine1.StartSketchPoint, oSketch1.SketchLines(2))
0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

If your end goal with this code is just to get the measurement from the end point of that line to the origin point of the sketch, then since your oSketch1 variable and oLine1 variable are already available, you can eliminate a bunch of that code and simply use something like this:

Dim oSketchOrigin As Point = oSketch1.OriginPointGeometry
Dim oEndPoint3D As Point = oLine1.EndSketchPoint.Geometry3d
StartingPointOffset = ThisApplication.MeasureTools.GetMinimumDistance(oSketchOrigin, oEndPoint3D)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

nsatheesan34D64
Advocate
Advocate

Hi @WCrihfield 

 

The end goal is to create a sketchpoint at the end of the line, select it and to run another series of sketches, based on that point.

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

OK.  It can be challenging to make suggestions without having all the related information.

So, if all you needed was a variable to hold the SketchPoint at the end of the oLine1, then that can be captured directly with the EndSketchPoint property of the SketchLine, without going through the extra steps, like this:

Dim oPoint0 As SketchPoint = oLine1.EndSketchPoint

I was not sure why you had created a new variable ("StartingPoint") for that same SketchPoint object, instead of just reusing the original variable ("oPoint0") directly.  And I was not sure why you created a new variable for a sketch, then setting its value using the Parent property of the SketchPoint object, if you still had access to the original sketch through the "oSketch1" variable.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes