Extract iso from SolidWorks line - VBA

Hi all.

This topic is about solidworks - vba:

I'm looking for a way to extract all the points from a 3D sketch in the order followed during the scan function . This is in order to perform calculations such as: quantity surveys, pressure drop, wired rdm...

I tried the following 4 functions:

swSketch.GetSketchSegments: Gives the segments out of order
swSketch.GetSketchPoints2: gives the points out of order--> I attach an example. I tried swSkPt.GetID(0) and swSkPt.GetID(1) but it doesn't give the order.
swSketch.GetSketchPaths: nothing in my case
swSketch.GetLines: gives the points in order, but only processes about half of the sketch --> really bad, I was almost there!!

For each one I proceeded to a loop of the type:

                        For i = LBound(vSketchPt) To UBound(vSketchPt)
                            Set swSkPt = vSketchPt(i)
                            Debug.Print (swSkPt.X & "; " & swSkPt.Y & "; " & swSkPt.Z)
                        Next

I would be interested if you would have any advice to give me on this issue.

Thank you


exemple.png

Hello

GetLines seems outdated. Try it with GetLines2

https://help.solidworks.com/2020/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.ISketch~GetLines2.html

As for the order of the dots, instinct and what I interpret of the result obtained in your image, I would say that it is only defined by the order of creation. That a sketch fillet added after drawing lines 1-2 2-3 3-4 will be numbered 5-6 with the arc center point of the fillet point number (#2 in your case). As a result, your code will read them (and link them) in this order.

SW doesn't care about the order of the points, all he cares about is which point is connected to which point to draw his line (1-2 or 1-5 is the same for him).

Do the test with your code on a W-shaped sketch, see the result, then apply a leave on the 3 intermediate points, and restart your code, and see the result.

Thank you for your feedback. Indeed, it is the holidays that disturb order.

I did some tests with GetLines2, it only processes part of the sketch as well.

Note that despite the holidays, SW is able to make an increasing sorting according to the position of the points on the trajectory. During a trajectory constraint, it is for example possible to enter a percentage and the object is placed at the position indicated (cf. PJ with a ball at 50% of the trajectory).

A priori, with the 4 functions mentioned, it is not possible to access this sorting according to the trajectory. The question would then be:

Is this increasing sorting accessible via VBA functions?


trajectoire.png

With IGetLines2 you have an ArraySize parameter that I assume provides you with the number of rows and therefore allows you to manage the number of iterations of your loop. I guess it should allow you to go through and process your entire sketch.

EDIT: message to forget...

1 Like

Regarding the GetID, what does this function mean? Depending on the situation, it may be possible to associate the id of a point with a position on the plot.

EDIT: message deleted, I was off the mark. Sorry.

Thank you for your feedback. I'm going to test the IGetLines2 function  .

It's a subject that I deal with as a common thread when I have availability. I'll leave the subject open in the meantime.

GetID(0) and GetID(1) each return an integer, different for each point. I sorted according to these 2 values, but it doesn't show the trajectory.

I have noted that in VBA there are methods and "I-methods":

GetLines2 & IGetLines2, GetID & IGetID, GetSpecificFeature2 & IGetSpecificFeature2

Often I-Methods require more parameters than methods but return the same type of object.

If you have any documentation on this duality Method and I-Method I'm interested.

See you again

Hello
From memory, I believe that the path function in a sketch orders entities, but it is only accessible for 2D sketches.
On a similar principle, the joined macro looks for one end of a continuous chain of entities in a 2D or 3D sketch, and orders them in an increasing order.
It also displays the successive points of the chain, which seems to meet your request.
The macro was only tested on the two sketches in the attached example (SW 2021)...

Kind regards.


sketchptsorder.zip