We use cookies to operate this website, improve its usability and track visits. Please note that by using this site you are consenting to the use of cookies.
Learn More |

Hello,

I'm working on a macro that is meant to insert a line segment and then add relations to the line endpoints.

 

So I create a sketch segment with: Set skSegment = swModel.SketchManager.CreateLine(x1, y1, z1, x2, y2, z2)

My goal is to then get the .SketchPoint objects for both endpoints of the line segment. And the use .select4 method to select it.

I know ISketchArc has a GetStartPoint2() method that does what I'm looking for, the problem is though that I have a SketchSegment object not a SketchArc object.

I can't believe there is not a similar method for SketchSegment objects.

 

I'm trying to avoid using SelectByID, because even though I know the xyz location of the endpoints, there is also another sketchpoint at the same exact location of the endpoints. I'm actually trying to get the endpoints to have coincident relations with those.

 

Any help is appreciated,

Thank you!


Categories: API∕Macros

Comments
Last comment By: John Maldonado   Thu, 14 Sep 2017 14:02:42 GMT
Re: How to get .SketchPoint object of SketchSegment End Points?

There are multiple types of SketchSegments.  A SketchArc is a type of SketchSegment.  So is a SketchLine, SketchSpline, SketchEllipse, etc...

 

Dim you a SketchLine.  Set it = to the SketchSegment of interest.  Then you can use GetEndPoint2.

 

See the help for ISketchSegment.GetType.

By: Josh Brady  Wed, 13 Sep 2017 17:29:34 GMT
Re: How to get .SketchPoint object of SketchSegment End Points?

if you have this in your code :

Set skSegment = swModel.SketchManager.CreateLine(x1, y1, z1, x2, y2, z2)

Then you have obviously if the construction is successfull, the created sketch segment is line and thus you have a sketch line.
A SketchSegment in this case (and only this case) can be casted into a ISketchLine object (otherwise do the type check like Josh said).

Do something like this:

Dim swLine as SldWorks.SketchLine
Set swLine = skSegment

 

Than you can use these methods to get the start and the end:
2016 SOLIDWORKS API Help - GetStartPoint2 Method (ISketchLine)

2015 SOLIDWORKS API Help - IGetEndPoint2 Method (ISketchLine)

 

Be mindful that these methods can fail under certain circumstances.

 

Cheers,
Amen
CADHERO consulting SUARL – CAD Design Automation & Training – SOLIDWORKS API

By: Amen Allah Jlili  Thu, 14 Sep 2017 13:40:25 GMT
Re: How to get .SketchPoint object of SketchSegment End Points?

Set StartPoint = skSegment.GetStartPoint2()

Set EndPoint = skSegment.GetEndPoint2()

 

Worked. I was looking through the API help for a SketchSegment method to do it but I never saw this. I guess it is inherited.

 

Thank you Josh!

By: John Maldonado  Thu, 14 Sep 2017 14:02:42 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.