API (Programmatically select a face and create a sketch)

Dear all,

I am a newbie on solidworks api.

I create a 1x1x1 mm cube in solidworks. I collected all face objects (use GetFirstFace & GetNextFace) in my program. But I don't know to to create a sketch based on each face programmatically.

(I don't want to prompt user to select a face manually). It is because I want to create some 2D lines on each face and then do some extrusion.

Can anybody tell me?

Thank you very much.

Alan

Reply to
info.lowyeah
Loading thread data ...

A Face is also an Entity, so you can Select it. Referring to API help:

"In general, an Entity is something that can be selected through the user interface. Entities are useful because they support direct selection through Entity::Select4."

For example:

Dim model As SldWorks.ModelDoc2 'Assuming this is your model Dim face as SldWorks.Face2 'assuming this is your face ... Dim entity As SldWorks.Entity Set entity = face

Dim selectData As SldWorks.SelectData Set selectData = model.SelectionManager.CreateSelectData entity.Select4 False, selectData

model.SketchManager.InsertSketch False

Hope this helps!

-h-

Reply to
Heikki Leivo

Thanks for your help. This example is very USEFUL!!.

Actually, I am writing a bounding box program , in order to measure the part EXTACT size.

Could you also give me some ideas to get the edges of this face entity (just like SolidWorks [convert entities]) ? which API functions can I use?

I want to extract these edges and then use "extrude" for a distance.

Your earliest reply is very appreciated. Alan

Reply to
info.lowyeah

Well, can't you just like... convert entities? This is far too easy, record a macro and see.

Interesting - have you tried using the bounding box SolidWorks provides (for example, PartDoc.GetPartBox)?

-h-

Reply to
Heikki Leivo

Yes, I have tried this function. But it just give me a rough size. The returned values are not extactly true. Any ideas on this small project?

I also tried SolidWorks.com provied example, but the performance is very very slow (not acceptable). So, I decided to write by myself.

Alan

Reply to
info.lowyeah

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.