API: Select chain and convert macro help

May 25, 2004 5 Replies

Can someone show me how to change the API call to reflect a more generic macro? What I need is a simple macro to select chain ref. sketch geom. under the mouse and convert it entities. when I run the macro recorder I get:



Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main()



Set swApp = Application.SldWorks



Set Part = swApp.ActiveDoc boolstatus = Part.Extension.SelectByID2("Line31@Sketch7", "EXTSKETCHSEGMENT", 0.02657237821555, -0.04846803192663, 0, False, 0, Nothing) boolstatus = Part.SketchUseEdge2(False) Part.ClearSelection2 True End Sub


Not sure how to clean this up and just work with what under the mouse. Any help would be great.



Eric


If you play the macro you will notice that it only selects the one segment. I couldn't find an API to do this you may have to get all the segments and compare endpoints to do this a bit more intensive.

Corey

Corey's right. You can compare endpoints to chain select. I've done it with a similar macro. Pick a start point and cycle thru the segments in the sketch and select the next segment sharing that point. The code needs to then select the opposite end of the segment and re-cycle. You have to check to make sure you didn't pick the same segment as last time. Be prepared to spend a little time at it, it's not at simple as it appears.

This might not help but you can use ModelDoc.SketchOffset2 ( offset, Directions, chain ) to offset a chain. You can even offset 0.

If you need help, let me know.

Kent KCS Development

formatting link

If you want to "convert it entities", then have a look at Model2::SketchUseEdge2 in apihelp: it has a "chain" parameter" that will automatically select the chain from the single segment you select!

The end-point comparison approach is has a n^2 complexity, which means it is100x slower for a sketch with 10x more segments. Therefore, on complex sketches (with hundreds of segments, such as dissolved text for example), I found it faster to :

1) use retval = ModelDoc.SketchOffsetEntities2 ( offset, false, true) 3) get the offset segments through the SelectionManager. The segments are sequenced along the chain 4) use SketchSegment::GetConstraints(sgOFFSETEDGE) on every segment to retrieve the source segments 5) delete the offset segments execution time is almost independent of sketch complexity, which means SW has an internal representation of chains, which means we could ask for a SketchPoint::GetSketchSegments API...

I would add the segments to a collection and select them after they have all been found. It helps avoid deselecting anything. Philippe seems to have a less intensive solution kindof round about feeling but why not use SWs proven chain selection eventhough they didn't want to let us. =^)

Corey

Cool! I would use Philippe's solution for this app. It will come in handy.

Kent

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required