Inventor Customization

Reply
Valued Mentor
jcneal
Posts: 324
Registered: ‎04-10-2010
Message 1 of 7 (764 Views)
Accepted Solution

add sketch on part's face by vba

764 Views, 6 Replies
10-22-2012 01:32 PM

hi,

 

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.

 

Autodesk Inventor Professional 2014
Autodesk Product Design Suite Standard 2013
Microsoft Office 2007 & 2013
Windows 7 64bit
Synergis Adept 2013
Visual Studio Express 2010
*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 2 of 7 (753 Views)

Re: add sketch on part's face by vba

10-23-2012 09:07 AM in reply to: jcneal

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

 

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Valued Mentor
jcneal
Posts: 324
Registered: ‎04-10-2010
Message 3 of 7 (737 Views)

Re: add sketch on part's face by vba

10-24-2012 09:41 AM in reply to: jdkriek

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?

Autodesk Inventor Professional 2014
Autodesk Product Design Suite Standard 2013
Microsoft Office 2007 & 2013
Windows 7 64bit
Synergis Adept 2013
Visual Studio Express 2010
*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 4 of 7 (699 Views)

Re: add sketch on part's face by vba

10-25-2012 06:35 AM in reply to: jcneal

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("PartSwitchRepresentationCmd")
        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
Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Valued Mentor
jcneal
Posts: 324
Registered: ‎04-10-2010
Message 5 of 7 (694 Views)

Re: add sketch on part's face by vba

10-25-2012 08:51 AM in reply to: jdkriek

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.

Autodesk Inventor Professional 2014
Autodesk Product Design Suite Standard 2013
Microsoft Office 2007 & 2013
Windows 7 64bit
Synergis Adept 2013
Visual Studio Express 2010
Mentor
akosi
Posts: 256
Registered: ‎09-17-2010
Message 6 of 7 (434 Views)

Re: add sketch on part's face by vba

09-10-2013 10:20 AM in reply to: jdkriek

how to execute the 2d sketch command in vba?

Mentor
akosi
Posts: 256
Registered: ‎09-17-2010
Message 7 of 7 (427 Views)

Re: add sketch on part's face by vba

09-10-2013 11:06 AM in reply to: jcneal

i want to select a face from a derived solid and project geometry to get a sketch.

 

can anybody help me with this?

 

thanks:smileyhappy:

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube