API Object - Extrude:getfaces

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

  1. Hacknwhack

    Hacknwhack Guest

    This is my first attempt at using the API and I am stuck on a particular
    problem.

    I am creating a dome feature on an existing extrude feature, and believe I
    know how to handle the feature however I am having trouble getting it. The
    feature in question is named so I ideally would like to get the feature by
    name then perform a getfaces on it.

    Just to clarify, I can select it into the SelectionMgr but I believe I need
    define the object in order to perform a getfaces.

    Hope this makes some sense.

    Thanks
    -hack
     
    Hacknwhack, Dec 7, 2004
    #1
  2. Hacknwhack

    CS Guest

    Could you post the code used to create the extrude feature.
    When working with objects that you created in the same macro it isn't
    advised to select them by name. IMHO Anyway if you post the code I could
    show you how to get the feature object

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

    Hacknwhack Guest

    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID("CircleSketch" & strCutNum, "SKETCH",
    0, 0, 0, False, 0, Nothing)
    Part.FeatureManager.FeatureCut False, False, False, 0, 0, Lc, EightInch,
    False, False, False, False, 0, 0, False, False, False, False, 0, 1, 1
    Set ThisFeatureCut = Part.FeatureByPositionReverse(0)
    ThisFeatureCut.Name = "Cylinder_" & strCutNum
    Part.ClearSelection2 True

    You can see that I access a sketch created within the macro called
    CircleSketch** on which to build my extrude. I could do the same thing for
    the extrude feature, however I need to perform some face tests (as you
    probably recall) so a simply selection isn't sufficient (I believe).
    Please note that I use no absolute coordinates anywhere in the macro, as
    they are ultimately provided by a user data file.

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

    CS Guest

    Try this

    Dim ThisFeatureCut as Feature
    Dim ThisFeatureSurfaces as variant

    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID("CircleSketch" & strCutNum, "SKETCH",
    0, 0, 0, False, 0, Nothing)
    set ThisFeatureCut = Part.FeatureManager.FeatureCut (False, False, False, 0,
    0, Lc, EightInch,
    False, False, False, False, 0, 0, False, False, False, False, 0, 1, 1)

    If thisfeaturecut is nothing then
    msgbox "Feature Cut Failed! Aborting Operations."
    end sub
    end if

    'you shouldn't need the next line now
    'Set ThisFeatureCut = Part.FeatureByPositionReverse(0)
    ThisFeatureCut.Name = "Cylinder_" & strCutNum


    ThisFeatureSurfaces = thisfeaturecut.GetFaces

    msgbox "Found " & str(ubound(ThisFeatureSurfaces) + 1) & " faces on feature
    " & ThisFeatureCut.Name

    Part.ClearSelection2 True

    Regards,
    Corey
     
    CS, Dec 7, 2004
    #4
  5. Hacknwhack

    Hacknwhack Guest

    Thanks again CS.

    Is there any easy way to get a look at the contents of the array now.

    I have the array ThisFeatureSurfaces now containing 2 elements as per your
    msgbox.

    I tried to just do a simple:

    For each i in ThisFeatureSurfaces
    MsgBox "This face info: " & ThisFeatureSurfaces(i)
    Next

    just to get a better handle on the contents here. This fails with object
    doesn't support this property or method. If I enclose ThisFeatureSurfaces
    in a Str() function I get a data mismatch.

    I will then test the surfaces to understand which is the flat surface so I
    can continue to use it for the next feature.
     
    Hacknwhack, Dec 7, 2004
    #5
  6. Hacknwhack

    CS Guest

    Well you can add a watch by selecting the variable and RMB>Add Watch the
    only thing this will give you is a list showing that you have two valid
    objects and possibly that they are of Face2 type. If you want to see the
    surfaces that are selected you could do this.

    Dim ThisSurfaceEnt as Entity

    for each i in ThisFeatureSurfaces
    Set ThisSurfaceEnt = i
    ThisSurfaceEnt.Select4 false, nothing
    msgbox "Do you see the surface that is selected?"
    Norm = i.normal
    Face2.
    if Norm(0) = 0 and Norm(1) = 0 and Norm(2) = 0 then
    'this is a cylindrical surface don't do anything
    msgbox "The selected Face is probably cylindrical"
    else
    'Norm is the direction vector. Compare this to a known
    msgbox "The selected Face is probably Planar"
    If 'some vector comparison then
    set WantedFace = i
    end if
    end if
    next
     
    CS, Dec 7, 2004
    #6
  7. Hacknwhack

    CS Guest

    Woops the line that says "Face2." needs to be deleted.

    Corey
     
    CS, Dec 7, 2004
    #7
  8. Hacknwhack

    CS Guest

    I'm curious how is this working or not.

    Corey

     
    CS, Dec 9, 2004
    #8
  9. Hacknwhack

    Hacknwhack Guest

    Thanks for your interest. What I have done is created and circular extruded
    cut into a rectangular solid such that a third of the circle is outside the
    block. the Extrusion only penetrates the block to about 1/3 depth. From
    here my goal was to add an extrusion to the back of the extruded cut, such
    that I would now have a backing if you will of the same shape, which travels
    an additional 1/3 into the block. Once this was complete I would then add a
    dome feature to my extruded "backing" to blend it into the block.

    I have completed all of this from 2 points pulled from a data file,
    however I have been unsuccessful creating the dome. I have used the getfaces
    method to obtain the faces of the backing and I think ruled out the
    cylindrical face, however, cannot figure out how to eliminate the front face
    of the extrusion and then how to select the remaining face to use as the
    origin of the dome.

    I have tried posting screen caps to explain this better, but when I did the
    posts would not show up.
    I could probably post these pics on a website for you to view if that would
    help.

    Thanks
    hack
     
    Hacknwhack, Dec 13, 2004
    #9
  10. Hacknwhack

    CS Guest

    If you e-mail me your code and example files to run I could maybe get it
    working for you.
    Pictures might help. But would leave me with no real way of expiramenting.

    Corey
     
    CS, Dec 13, 2004
    #10
  11. Hacknwhack

    CS Guest

    Oops I for got



    Remove eroneous info.

    Corey
     
    CS, Dec 13, 2004
    #11
  12. Hacknwhack

    CS Guest

    For future reference this works

    Dim NormalVofCut as MathVector
    Dim NormalVofThis as MathVector
    '.........

    ThisFeatureSurfaces = ThisFeatureBackStop.GetFaces

    Debug.Print "Found " & Str(UBound(ThisFeatureSurfaces) + 1) & " faces on
    feature" & ThisFeatureCut.Name

    For Each i In ThisFeatureSurfaces
    Norm = i.Normal
    If Norm(0) = 0 And Norm(1) = 0 And Norm(2) = 0 Then
    Debug.Print "This face is cylindrical"
    Else
    Set WantedFace = i
    Set NormalVofThis = GetNormalVector(WantedFace.Normal)
    Debug.Print "Normalised:" & NormalVofThis.GetLength
    'Corey: check to be sure the vector of this surface doesn't
    match the
    'bottom of the origional cut. They should be exact opposites.
    If Not NormalVofThis.ArrayData(0) = NormalVofCut.ArrayData(0) Or
    _
    Not NormalVofThis.ArrayData(1) = NormalVofCut.ArrayData(1) Or _
    Not NormalVofThis.ArrayData(2) = NormalVofCut.ArrayData(2) Then
    'select the surface
    WantedFace.Select4 True, Nothing
    'MsgBox "This should be your face"
    Exit For
    End If
    End If
    Next
    'Corey: set the mark as required by the dome feature
    SelMan.SetSelectedObjectMark 1, 1, swSelectionMarkSet
    Part.InsertDome 0.007, False, True
    '.........


    Function GetNormalVector(Normal As Variant) As MathVector
    'Corey: make sure the vector is normalised
    Dim MathUtil As SldWorks.MathUtility
    Dim NormalPoint As New MathPoint

    Set MathUtil = swApp.GetMathUtility
    Set NormalPoint = MathUtil.CreatePoint(Normal)
    'NormalPoint.ArrayData = Normal

    Set GetNormalVector = NormalPoint.ConvertToVector
    Debug.Print GetNormalVector.GetLength
    Set GetNormalVector = GetNormalVector.Normalise

    End Function


    Regards,
    Corey
     
    CS, Dec 16, 2004
    #12
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.