Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

adding to existing KnitFeature

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
wowens63
596 Views, 5 Replies

adding to existing KnitFeature

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

5 REPLIES 5
Message 2 of 6
wayne.brill
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

Message 3 of 6
wowens63
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.

Message 4 of 6
wayne.brill
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

Message 5 of 6
ekinsb
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
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 6
wowens63
in reply to: wowens63

Thank you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report