Message 1 of 3

Not applicable
12-08-2017
03:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.