API Feature Selection

Discussion in 'SolidWorks' started by Hacknwhack, Dec 2, 2004.

  1. Hacknwhack

    Hacknwhack Guest

    I am trying to create a simple dome feature on a cylinder face that is also
    created from within my macro. The problem I'm having is that I do not know
    how to select the appropriate face on the cylinder by name.

    The line:

    boolstatus = Part.Extension.SelectByID("", "FACE",
    0.02256158044904, -4.995574477107E-04, 0.004999999999995, False, 1, Nothing)

    was created by the macro record function when selecting the face using the
    GUI. There is no way I can use absolute coordinate values so I want to be
    able to use the name parameter (first set of "").

    The cylindar has three surfaces so can someone please tell me how to name
    the correct surface on the cylindar during creation such that i can use it
    in the creation of my dome

    thanks a bunch
    -hack
     
    Hacknwhack, Dec 2, 2004
    #1
  2. Hacknwhack

    CS Guest

    You can access the surfaces through the Extrude features faces

    Then you will have to check to see if the surface is cylindrical If it is
    discard it. Now you are left with your other 2 surfaces. You will have to
    compare them by their normal direction.

    Feature::GetFaces
    Dim Faces as variant
    Dim i as variant
    Dim Norm as variant
    Dim WantedFace as Face2

    Faces = MyFeature.GetFaces
    for each i in Faces
    Norm = i.normal
    if Norm(0) = 0 and Norm(1) = 0 and Norm(2) = 0 then
    'this is a cylindrical surface don't do anything
    else
    'Norm is the direction vector. Compare this to a known
    vector
    If 'some vector comparison then
    set WantedFace = i
    end if
    end if
    next

    WantedFace.select4(false, nothing)


    Regards,

    Corey
     
    CS, Dec 2, 2004
    #2
  3. Hacknwhack

    Hacknwhack Guest

    I am a little unclear on some of your code:
    I assume the getfaces method will put the three faces of the cylinder
    into the array faces.
    (I'm not clear on what is actually stored in the array and how that refers
    to the face)
    Then you are going to test each face's normal vector??

    I'm not sure what the test statement does in order to id this face as the
    being cylindrical:
    if Norm(0) = 0 and Norm(1) = 0 and Norm(2) = 0 then
    What does a value of 0 constitute.

    Then, if i am able to narrow the selections down to the 2 opposite surfaces,
    how can I differentiate between them. I would assume they both share the
    same normal vector albeit offset. Note I will be using a point (that is
    named) and subsequent plane, to initiate the sketch for the first side of
    the cylinder. Perhaps some characteristic of this point or plane can be
    compared to something on the "not wanted" surface to identify it and
    subsequently reject it.

    sorry if some of my questions seem crazy, I am very new to the API.

    -hack
     
    Hacknwhack, Dec 3, 2004
    #3
  4. Hacknwhack

    CS Guest

    see comments below

    Regards

    Corey

    It is a pointer to the face object this can be passed to a variant or object
    or Face2 variable.


    The normal vector is a point and a direction can be figured in relation to
    the origin. If the face is not planar Face2::Normal returns an array
    [0,0,0] so in the if statement you are able to check if the face is planar
    or not

    Actually they shouldn't they should be exact opposites because the normal
    vector would be the direction away from the solid body the OUT direction if
    you will.
    I would maybe compare the normal direction of the sketch to each face. I
    presume you want the end away from the sketch. If you extrude it without
    flipping the extrution the normal of the sketch and the normal of your face
    should be the same direction. The next problem is going to be that even
    though 2 planes may have the same normal direction you may have a point
    further out on the direction vector for one than the other. You may want to
    compare ratios instead of a direct comparison.

    x1/y1 = x2/y2 and z1/x1 = z2/x2

    but then you have to watch out for divide by zero.

    Maybe someone else has had to compare Direction Vectors in SW and could
    enlighten us on how they handled the comparison.

    Corey

    Questions are never crazy it is just that sometimes you don't know anyone
    with the right answer.
     
    CS, Dec 3, 2004
    #4
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.