Inventor Customization

Reply
Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 1 of 6 (232 Views)
Accepted Solution

adding to existing KnitFeature

232 Views, 5 Replies
07-29-2013 08:49 AM

how would i go about adding a new surface to existing knitFeature with the API

It is possible to add surfaces to an existing knit feature.  Below is some sample code I used to verify it and the part (Inventor 2014) I used to test it.

 

An important thing to understand is that the surface you're adding to the stitch must exist in the browser tree before the stitch feature.  You can why this is a requirement when you try to do the same thing through the user-interface.  When you edit any feature, it rolls the tree back to the state where that feature was created, which means you don't have access to anything created after it.

 

Public Sub AddToKnit()
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument
Dim existingKnit As KnitFeature
Do
Dim selectedFeature As PartFeature
Set selectedFeature = ThisApplication.CommandManager.Pick( _
kPartFeatureFilter, "Select a stitch feature.")
If selectedFeature Is Nothing Then
Exit Sub
End If
If TypeOf selectedFeature Is KnitFeature Then
Set existingKnit = selectedFeature
Else
MsgBox "The selected feature must be a stitch feature."
End If
Loop While existingKnit Is Nothing
Dim surfaceFeature As WorkSurface
Set surfaceFeature = ThisApplication.CommandManager.Pick( _
kPartBodyFilter, "Select a body to add to the stitch feature.")
Dim newBody As Object
Set newBody = surfaceFeature.SurfaceBodies.Item(1)
Dim bodies As ObjectCollection
Set bodies = existingKnit.Surfaces
Call bodies.Add(surfaceFeature)
existingKnit.Surfaces = bodies
End Sub

 

ADN Support Specialist
wayne.brill
Posts: 248
Registered: ‎08-25-2004
Message 2 of 6 (205 Views)

Re: adding to existing KnitFeature

07-30-2013 01:02 PM in reply to: wowens63

Hello,

 

I am not sure I understand your question. The API allows you to create a KnitFeature using the Add method of the KnitFeatures collection. This Add method takes an ObjectCollection of surfaces. The help file has a VBA example:

StitchFeatureCreate()

 

You could get the worksurfaces from the existing KnitFeature you want to knit together and put them in the ObjectCollection that you pass to KnitFeatures.Add().

 

Here is some VBA code I used to test:

Sub addToStitchFeature()
       
        Dim oPartDoc As PartDocument
        Set oPartDoc = ThisApplication.ActiveDocument
       
         Dim oCompDef As PartComponentDefinition
         Set oCompDef = oPartDoc.ComponentDefinition

        Dim oSrf1 As WorkSurface
        Set oSrf1 = oPartDoc.SelectSet(1)
       
        Dim oSrf2 As WorkSurface
        Set oSrf2 = oPartDoc.SelectSet(2)
       
         Dim oSurfaces As ObjectCollection
         Set oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection
            
        oSurfaces.Add oSrf1
        oSurfaces.Add oSrf2
   
       Dim oKnitFeature As KnitFeature
       Set oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)
       
       
   End Sub

 

The attached screenshots help explain.

 

Hope this helps,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 3 of 6 (195 Views)

Re: adding to existing KnitFeature

07-30-2013 02:35 PM in reply to: wayne.brill

yes you are correct, and i do have the same code. the problem is after making the

Set oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)

I cant keep adding more surfaces to it. the only way i found that works is to delete the "oKnitFeature"

and remake it will all the surfaces.

ADN Support Specialist
wayne.brill
Posts: 248
Registered: ‎08-25-2004
Message 4 of 6 (169 Views)

Re: adding to existing KnitFeature

08-05-2013 02:14 PM in reply to: wowens63

Hi,

 

I have not found any way to add a new surface to a KnitFeature and agree with you that the faces needed to be added to the KnitFeature when it is created with the Add method. If you would like this functionality added to the API please log a post on the Inventor Idea Station.

http://forums.autodesk.com/t5/Inventor-IdeaStation/idb-p/v1232

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

ADN Support Specialist
ekinsb
Posts: 345
Registered: ‎07-21-2006
Message 5 of 6 (132 Views)

Re: adding to existing KnitFeature

08-16-2013 01:19 PM in reply to: wowens63

It is possible to add surfaces to an existing knit feature.  Below is some sample code I used to verify it and the part (Inventor 2014) I used to test it.

 

An important thing to understand is that the surface you're adding to the stitch must exist in the browser tree before the stitch feature.  You can why this is a requirement when you try to do the same thing through the user-interface.  When you edit any feature, it rolls the tree back to the state where that feature was created, which means you don't have access to anything created after it.

 

Public Sub AddToKnit()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    Dim existingKnit As KnitFeature
    Do
        Dim selectedFeature As PartFeature
        Set selectedFeature = ThisApplication.CommandManager.Pick( _
                        kPartFeatureFilter, "Select a stitch feature.")
        
        If selectedFeature Is Nothing Then
            Exit Sub
        End If
        
        If TypeOf selectedFeature Is KnitFeature Then
            Set existingKnit = selectedFeature
        Else
            MsgBox "The selected feature must be a stitch feature."
        End If
    Loop While existingKnit Is Nothing
    
    Dim surfaceFeature As WorkSurface
    Set surfaceFeature = ThisApplication.CommandManager.Pick( _
         kPartBodyFilter, "Select a body to add to the stitch feature.")
    Dim newBody As Object
    Set newBody = surfaceFeature.SurfaceBodies.Item(1)
    
    Dim bodies As ObjectCollection
    Set bodies = existingKnit.Surfaces
    
    Call bodies.Add(surfaceFeature)
    existingKnit.Surfaces = bodies
End Sub

 



Brian Ekins
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 6 of 6 (128 Views)

Re: adding to existing KnitFeature

08-16-2013 02:21 PM in reply to: wowens63

Thank you

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!