how would i go about adding a new surface to existing knitFeature with the API
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
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
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.
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
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
Can't find what you're looking for? Ask the community or share your knowledge.