API Object - Extrude:getfaces

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

Reply to
Hacknwhack
Loading thread data ...

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

Reply to
CS

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

Reply to
Hacknwhack

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

Reply to
CS

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.

Reply to
Hacknwhack

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

Reply to
CS

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

Corey

ThisFeatureSurfaces

Reply to
CS

I'm curious how is this working or not.

Corey

Reply to
CS

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

Reply to
Hacknwhack

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

Reply to
CS

Oops I for got

snipped-for-privacy@GarErooneousLockequip.com

Remove eroneous info.

Corey

Reply to
CS

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

expiramenting.

cylindrical"

Reply to
CS

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.