API (Programmatically select a face and create a sketch)

Discussion in 'SolidWorks' started by info.lowyeah, May 19, 2007.

  1. info.lowyeah

    info.lowyeah Guest

    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
     
    info.lowyeah, May 19, 2007
    #1
  2. info.lowyeah

    Heikki Leivo Guest

    I create a 1x1x1 mm cube in solidworks. I collected all face objects
    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-
     
    Heikki Leivo, May 19, 2007
    #2
  3. info.lowyeah

    info.lowyeah Guest

    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
     
    info.lowyeah, May 19, 2007
    #3
  4. info.lowyeah

    Heikki Leivo Guest

    Could you also give me some ideas to get the edges of this face entity
    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-
     
    Heikki Leivo, May 19, 2007
    #4
  5. info.lowyeah

    info.lowyeah Guest

    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
     
    info.lowyeah, May 21, 2007
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.