Rectangular Pattern of Feature in Part - C# or .NET Example

Rectangular Pattern of Feature in Part - C# or .NET Example

Anonymous
Not applicable
1,716 Views
2 Replies
Message 1 of 3

Rectangular Pattern of Feature in Part - C# or .NET Example

Anonymous
Not applicable

Hello,

 

I'm programming my first Add-In for Inventor 2017 in C#.

 

The purpose of the Add-in is to create a steel grate. I already have the rectangle with 1 "grate". But now I have to create a rectangular pattern.

But here I'm stuck, I can't find any example that makes any sense.

 

I tried to make an objectcollection of the grate extrusion feature, and add this to a rectangularpatternfeature.

But I'm not making any progress. Could someone help me out?

 

 

  private void btn_create_Click(object sender, EventArgs e)
        {
            #region CREATE PART + GET UNIQUE FILENUMBER + SAVE PART
            PartDocument oPartDoc = (PartDocument)_invApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _invApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);

            try
            {
                StandardAddInServer.VLT_Conn = StandardAddInServer.LogMeInVault();
                if (StandardAddInServer.VLT_Conn != null)
                {
                    Autodesk.DataManagement.Client.Framework.Currency.FolderPathAbsolute fld = null;
                    fld = StandardAddInServer.VLT_Conn.WorkingFoldersManager.GetWorkingFolder("$");
                    StandardAddInServer.VLT_WorkingFolder = fld.FullPath;
                }
            }
            catch { StandardAddInServer.VLT_Conn = null; }
            if (StandardAddInServer.VLT_Conn == null)
            {
                MessageBox.Show("Gelieve u eerst in vault aan te melden!", "Foutmelding", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            string fileNumber = StandardAddInServer.FileNumber();
            string saveLocationPart = StandardAddInServer.fileLoc.Replace(System.IO.Path.GetFileName(StandardAddInServer.fileLoc), "PT" + fileNumber + ".ipt");

            #region SetProperties Iterate

            Inventor.Document doc = _invApp.ActiveDocument;
            Inventor.PropertySets oPropertySets;
            oPropertySets = doc.PropertySets;

            foreach (PropertySet oPropertySet in oPropertySets)
            {

                if (oPropertySet.DisplayName.ToLower() == "design tracking properties")
                {
                    foreach (Property oProperty in oPropertySet)
                    {
                        if (oProperty.DisplayName == oPropertySet.ItemByPropId[(int)PropertiesForDesignTrackingPropertiesEnum.kDescriptionDesignTrackingProperties].DisplayName)
                        {
                            oProperty.Value = txt_omsch.Text;
                            doc.DisplayName = txt_omsch.Text;
                            doc.DisplayNameOverridden = true;
                        }
                        else if (oProperty.DisplayName == oPropertySet.ItemByPropId[(int)PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties].DisplayName)
                        {
                            oProperty.Value = txt_afm.Text;
                        }
                    }
                }
                else if (oPropertySet.DisplayName.ToLower() == "summary information")
                {
                    foreach (Property oProperty in oPropertySet)
                    {
                        if (oProperty.DisplayName == oPropertySet.ItemByPropId[(int)PropertiesForSummaryInformationEnum.kSubjectSummaryInformation].DisplayName)
                        {
                            oProperty.Value = txt_afm.Text;
                        }
                    }
                }
            }
            #endregion

            oPartDoc.SaveAs(saveLocationPart, false);

            #endregion

            #region DRAW ROOSTER

            TransientGeometry oTG = _invApp.TransientGeometry;
            PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition;

            Point2d[] oPoints = new Point2d[4];

            oPoints[0] = oTG.CreatePoint2d(0, 0);
            oPoints[1] = oTG.CreatePoint2d(calcWidth / 10, 0);
            oPoints[2] = oTG.CreatePoint2d(calcWidth / 10, calcLength / 10);
            oPoints[3] = oTG.CreatePoint2d(0, calcLength / 10);

            PlanarSketch oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);
            SketchLine[] oLines = new SketchLine[4];

            oLines[0] = oSketch.SketchLines.AddByTwoPoints(oPoints[0], oPoints[1]);
            oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, oPoints[2]);
            oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, oPoints[3]);
            oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint);

            Profile oProfile = oSketch.Profiles.AddForSolid();

            oProfile.AttributeSets[0].Name = "Length";

            ExtrudeFeature oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, cb_rdikte.SelectedItem, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, 0);


            MessageBox.Show(oExtrude.FeatureDimensions.Count.ToString());

            oExtrude.FeatureDimensions[1].Parameter.Name = "DikteRooster";
            oExtrude.FeatureDimensions[2].Parameter.Name = "TaperAngleRooster";

            oSketch = oCompDef.Sketches.AddWithOrientation(oExtrude.StartFaces[1], oCompDef.WorkAxes[1], true, true, oCompDef.WorkPoints[1], false);
            oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0.7, 0.7), oTG.CreatePoint2d(3.8, 3.8));

            oProfile = oSketch.Profiles.AddForSolid();
            oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, cb_rdikte.Text, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation, 0);

            oExtrude.FeatureDimensions[1].Parameter.Name = "MaasExtrudeDikte";
            oExtrude.FeatureDimensions[2].Parameter.Name = "TaperAngleMazen";
            oExtrude.Name = "Mazen";

            #endregion

            #region CREATE PATTERN

            ObjectCollection objColFeatures = _invApp.TransientObjects.CreateObjectCollection();
            objColFeatures.Add(oCompDef.Features.ExtrudeFeatures[2]);

            RectangularPatternFeature oRectFeature = oCompDef.Features.RectangularPatternFeatures.AddByDefinition();
            

            #endregion


            oPartDoc.Update();
            oPartDoc.Save();

            this.Close();
        }

 

 

Thanks in advance

0 Likes
Accepted solutions (2)
1,717 Views
2 Replies
Replies (2)
Message 2 of 3

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-6D6F1140-F264-42E2-A0DB-4C967742267E

 

My example solution, but I'm using inventor 2014 and VBA:

 

https://forums.autodesk.com/t5/inventor-customization/rectangular-pattern-part-ilogic/m-p/7599859#M7...

 

 

When I see API inventor 2017 there are difference:

 

RectangularPatternFeatures.AddByDefinition(....) or

RectangularPatternFeatures.CreateDefinition(....) <-- Same like my example

 

but in inventor 2014:

Dim RecFeat as RectangularPatternFeatures

set RecFeat  = ....RectangularPatternFeatures.Add(...)

 

Maybe you can find any clue from my example.

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Hello,

 

Thanks for the push in the right direction.

This is what I came up with:

 

#region CREATE PATTERN
            ObjectCollection oObjColl = _invApp.TransientObjects.CreateObjectCollection();
            oObjColl.Add(oExtrude);
            RectangularPatternFeatureDefinition oRecFeatDef = oCompDef.Features.RectangularPatternFeatures.CreateDefinition(oObjColl, oCompDef.WorkAxes[1], true, 5, 3.8, PatternSpacingTypeEnum.kDefault);
            RectangularPatternFeature oRecFeat = oCompDef.Features.RectangularPatternFeatures.AddByDefinition(oRecFeatDef);         
#endregion

Now I just have to find out how to create a pattern in two directions Smiley LOL

0 Likes