C# Help Examples for Parts General

Here are the VBA examples in this section of samples for parts converted to C#. This group of examples includes an example for an event (TestSelection) that allows you to get an entity from the user using events. It also has some parameter and brep examples. The WorkPointAtMassCenter c# example was already in the help file. (Saved me some time converting it).

image

This project has the following functions.

 Download InventorHelpExamples_Part_General

CreateParametersAndGroup
MoldBaseSample
SelectivelyLinkParams
QueryAndShowFeatureDimensions
TestSelection
IsCylindricalFaceInterior
GetPartMassProps
GetPartMassPropsWithoutDirtying
WorkPointAtMassCenter
CreateMaterial
ShowMaterials
ModelParameters
TableParameters
CreateRectangleFace

 

Here is the CreateParametersAndGroup function:

// Creating a new parameter group API Sample 
//Description 
//This sample demonstrates the creation of model, 
//reference and user parameters and 
//copying these parameters to a newly created group.
public void CreateParametersAndGroup()
{
    // Create a new Part document.
    PartDocument oPartDoc = default(PartDocument);
    oPartDoc =
      (PartDocument)ThisApplication.Documents.Add
    (DocumentTypeEnum.kPartDocumentObject,
    ThisApplication.FileManager.GetTemplateFile
    (DocumentTypeEnum.kPartDocumentObject));
 
    // Set a reference to the compdef.
    PartComponentDefinition oCompDef =
        default(PartComponentDefinition);
    oCompDef = oPartDoc.ComponentDefinition;
 
    // Create a model parameter
    ModelParameter oModelParam =
                  default(ModelParameter);
    oModelParam = oCompDef.Parameters.
    ModelParameters.AddByValue
    (2, UnitsTypeEnum.kCentimeterLengthUnits);
 
    // Create a reference parameter
    ReferenceParameter oReferenceParam =
    default(ReferenceParameter);
    oReferenceParam = oCompDef.Parameters.
    ReferenceParameters.AddByValue
    (4, UnitsTypeEnum.kCentimeterLengthUnits);
 
    // Create a user parameter
    UserParameter oUserParam =
                       default(UserParameter);
    oUserParam = oCompDef.Parameters.UserParameters.
             AddByValue("length", 6,
              UnitsTypeEnum.kCentimeterLengthUnits);
 
    // Create a new custom parameter group
    CustomParameterGroup oCustomParamGroup =
    default(CustomParameterGroup);
    oCustomParamGroup = oCompDef.Parameters.
             CustomParameterGroups.Add
                ("Custom Group", "CustomGroup1");
 
    // Add the created parameters to this group
    // Note that adding the parameters to the 
    //custom group does not remove it from the 
    // original group.
    oCustomParamGroup.Add((Parameter)oModelParam);
    oCustomParamGroup.Add
                     ((Parameter)oReferenceParam);
    oCustomParamGroup.Add((Parameter)oUserParam);
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading