I can add sketch on a part's workplane (xy, xz, yz) by using sketchs.add.
is there anyway i can select a face of part and create a new sketch?
thanks for any tips.
Solved! Go to Solution.
Here's one method I use on Extruded parts, but hopefully you can gleem enough from it.
Sub Sketch2Face2() 'J.Kriek 2012 Dim oApp As Application Set oApp = ThisApplication Dim oPart As PartDocument Set oPart = oApp.ActiveDocument Dim oCompDef As ComponentDefinition Set oCompDef = oPart.ComponentDefinition Dim oExtrude As ExtrudeFeatures Set oExtrude = oCompDef.Features.ExtrudeFeatures Dim oFaces As Faces 'This can be changed to .SideFaces, .EndFaces, or .StartFaces 'But .Faces will let you choose between all faces Set oFaces = oExtrude.Item(1).Faces Dim oSketch As PlanarSketch 'Put a sketch on the first face (1) - change to suit Set oSketch = oCompDef.Sketches.Add(oFaces(1), True) End Sub
thanks a lot.
I modified your code to fit my need. It works fine.
I don't understand how you get .sidefaces, endfaces to work. I have to test few times to get face right. in thise case is oFace(4)
Is there any way I always get top face of a face feature in sheet metal part?
SideFaces, EndFaces, ect is only available for extruded features. When dealing with sheetmetal faces features you can only choose the item number. And yes unfortunately it's a guessing game as to which number that is depending on how the face was created.
However, I did have a crazy idea...
You can obtain the .BaseFace from the flat pattern and since it's a face feature it's going to be the top face. It will create the sketch in the folded. This worked for me, but try it out.
Sub Sketch2FlatFace() 'J.Kriek 2012 Dim oApp As Application Set oApp = ThisApplication Dim oPart As PartDocument Set oPart = oApp.ActiveDocument Dim oSheetMetalComp As SheetMetalComponentDefinition Set oSheetMetalComp = oPart.ComponentDefinition 'Make sure there is a flat pattern If oSheetMetalComp.HasFlatPattern = False Then 'Create flat pattern Call oSheetMetalComp.Unfold 'Switch back to Folded Set oDef = oApp.CommandManager.ControlDefinitions.Item("PartS
witchRepresentationCmd") Call oDef.Execute End If Dim oFlatpattern As FlatPattern Set oFlatpattern = oSheetMetalComp.FlatPattern 'Edit the flat pattern Call oFlatpattern.Edit 'Grab the BaseFace (Top) - can also be .BottomFace Dim oFace As Face Set oFace = oFlatpattern.BaseFace 'Exit the flat pattern Call oFlatpattern.ExitEdit 'Sketch on Top Face Dim oSketch As PlanarSketch Set oSketch = oSheetMetalComp.Sketches.Add(oFace, True) 'Remove the flat pattern - optional 'Call oFlatpattern.Delete End Sub
well, mine is front face. so the sketch goes to my flange side whick is top face.
I did face feature on x-y plane.
thanks a lot. I learn something from it.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register