Sometimes we get code samples with hundreds of lines of code in iLogic where the last part fails. Even if it's not iLogic, it's still better to narrow down things to the specific function that is not working and create a test that focuses on it.
This will make it much easier for others to help you (e.g. on the forum) and might enable you to spot the issue with your code (if it's not a problem with the API itself)
For example, if your code is creating all the geometry that you want to add a feature to and that last bit fails for some reason, then
- remove the feature creation you have problems with
- run the rest of the code to create the geometry that the feature needs
- save that part/assembly and create a function that focuses on the feature that you're having problems with creating
The best is to do that in a programming environment that allows you to step through code and investigate the variables you are using. The simplest way for everyone to run your code in is VBA - if you create a .NET project (whether add-in or stand-alone app) not everyone has Visual Studio installed to run it, and if it's iLogic then you have limited debugging options.
Let's say we run into issues with KnitFeatures.Add() when running this sample code: Adding a new stitch (knit) feature API Sample
I can just remove the last part about creating the KnitFeature object and run it:
Now I have the geometry that the creation of the last feature needs, and can move the last part of the code into a separate VBA method that would only run the code that creates the KnitFeature:
Sub StitchFeatureCreate_Test() Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.ActiveDocument Dim oCompDef As PartComponentDefinition Set oCompDef = oPartDoc.ComponentDefinition Dim oSurfaces As ObjectCollection Set oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection oSurfaces.Add oCompDef.WorkSurfaces.Item(1) oSurfaces.Add oCompDef.WorkSurfaces.Item(2) Dim oKnitFeature As KnitFeature Set oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces) End Sub
As discussed in this blog post, this way you can also examine the various objects you are using - you might e.g. realize that you are trying to pass in the wrong objects to the function, or some parameters are not correct.
If you happened to find an issue with the API then it will make it much easier for us to verify the problem on our side :)
When it comes to debugging iLogic code, this might come handy too:
https://adndevblog.typepad.com/manufacturing/2014/08/debug-ilogic.html
-Adam