public static void saveAllAsDxf(string path) { // ! Istanza inventor getIstance(); // ! Tutti gli ipt dentro la folder // ? oDoc = (PartDocument) iApp.ActiveDocument; string[] listFiles = System.IO.Directory.GetFiles(@path, "*.ipt"); int counter = 0; // ! Ciclo la lista ipt dentro la folder foreach (string file in listFiles) { counter++; if (System.IO.Path.GetExtension(file) == ".ipt") { // ! Apro il documento PartDocument oDoc = (PartDocument)iApp.Documents.Open(@file); bool dxfStatus = saveDxf(path, oDoc); if (!dxfStatus) { Console.WriteLine("dasdsadsdas"); } oDoc.Close(true); } } }
private void CreateLayoutPartFile() { string partTemplateFile = @"C:\Users\Public\Documents\Autodesk\Inventor 2014\Templates\Standard.ipt"; LayoutPartPath = "C:\\Users\\frankfralick\\Documents\\Inventor\\Dynamo 2014\\Layout.ipt"; //TODO This is just for early testing of everything. This will get set and managed elsewhere. if (!System.IO.File.Exists(LayoutPartPath)) { PartDocument layoutPartDoc = (PartDocument)InventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, partTemplateFile, true); layoutPartDoc.SaveAs(LayoutPartPath, false); layoutPartDoc.Close(); } }
public void ReplaceReferences(AssemblyDocument targetAssembly, TupleList <string, string> namePair, string folderPath) { OccurrenceList newOccs = new OccurrenceList(targetAssembly); string pathString = folderPath; List <string> patternComponentsList = new List <string>(); for (int i = 0; i < newOccs.Items.Count; i++) { if (newOccs.Items[i].DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject) { for (int f = 0; f < namePair.Count; f++) { if (namePair[f].Item1 == newOccs.Items[i].ReferencedFileDescriptor.FullFileName) { if (patternComponentsList.Contains(namePair[f].Item1)) { newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[f].Item2); } else { if (!System.IO.File.Exists(namePair[f].Item2)) { PartDocument partDoc = (PartDocument)PersistenceManager.InventorApplication.Documents.Open(namePair[f].Item1, false); partDoc.SaveAs(namePair[f].Item2, true); partDoc.Close(true); newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[f].Item2); } patternComponentsList.Add(namePair[f].Item1); } } } } else if (newOccs.Items[i].DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { for (int n = 0; n < namePair.Count; n++) { if (namePair[n].Item1 == newOccs.Items[i].ReferencedFileDescriptor.FullFileName) { AssemblyDocument subAssembly = (AssemblyDocument)PersistenceManager.InventorApplication.Documents.Open(newOccs.Items[i].ReferencedFileDescriptor.FullFileName, false); ReplaceReferences(subAssembly, namePair, pathString); string newFilePath = namePair[n].Item2; subAssembly.SaveAs(namePair[n].Item2, true); subAssembly.Close(true); newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[n].Item2); } } } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void CreateOccurrenceTag(AssemblyDocument AsmDocument, PartFeature PartFeature, ComponentOccurrence occurrence) { AttributeSet set = PartFeature.AttributeSets[_AttributeSet]; Byte[] contextData = set["ContextData"].Value as Byte[]; int keyContext = AsmDocument.ReferenceKeyManager.LoadContextFromArray(ref contextData); Byte[] refKey = new byte[] { }; occurrence.GetReferenceKey(ref refKey, keyContext); set.Add("OccurrenceRefKey", ValueTypeEnum.kByteArrayType, refKey); PartDocument doc = PartFeature.Parent.Document as PartDocument; set = doc.ComponentDefinition.AttributeSets[_AttributeSet]; string srcDocPath = set["SourcePartDoc"].Value as string; PartDocument srcDoc = FeatureUtilities.Application.Documents.Open(srcDocPath, false) as PartDocument; foreach (PartFeature feature in doc.ComponentDefinition.Features) { if (feature.AttributeSets.get_NameIsUsed(_AttributeSet)) { AttributeSet setFeature = feature.AttributeSets[_AttributeSet]; string AsmFeature = setFeature["AsmFeature"].Value as string; if (!setFeature.get_NameIsUsed("OccurrenceRefKey")) { ObjectCollection collec = srcDoc.AttributeManager.FindObjects(_AttributeSet, "AsmFeature", AsmFeature); if (collec.Count > 0) { PartFeature srcFeature = collec[1] as PartFeature; object val = srcFeature.AttributeSets[_AttributeSet]["OccurrenceRefKey"].Value; setFeature.Add("OccurrenceRefKey", ValueTypeEnum.kByteArrayType, val); } } } } srcDoc.Close(true); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Use: Create a new derived PartDocument from a ComponentDefinition (asm or part) // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static PartDocument DeriveComponent(ComponentDefinition compDef) { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; PartDocument derivedDoc = InvApp.Documents.Add( DocumentTypeEnum.kPartDocumentObject, InvApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null), false) as PartDocument; if (compDef.Type == ObjectTypeEnum.kAssemblyComponentDefinitionObject) { DerivedAssemblyComponents derAsmComps = derivedDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents; DerivedAssemblyDefinition derAsmDef = derAsmComps.CreateDefinition( (compDef.Document as Document).FullFileName); derAsmDef.InclusionOption = DerivedComponentOptionEnum.kDerivedIncludeAll; derAsmComps.Add(derAsmDef); return(derivedDoc); } if (compDef.Type == ObjectTypeEnum.kPartComponentDefinitionObject) { DerivedPartComponents derPartComps = derivedDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents; DerivedPartUniformScaleDef derPartDef = derPartComps.CreateDefinition( (compDef.Document as Document).FullFileName); derPartDef.IncludeAll(); derPartComps.Add(derPartDef as DerivedPartDefinition); return(derivedDoc); } derivedDoc.Close(true); return(null); }
private void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text.Length > 0) { PartDocument oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); //Author property is contained in "Inventor Summary Information" Set PropertySet oPropertySet = oDoc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"]; //Using Inventor.Property to avoid confusion Inventor.Property oProperty = oPropertySet["Author"]; oProperty.Value = TextBox1.Text; //Get "Inventor User Defined Properties" set oPropertySet = oDoc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"]; //Create new property oProperty = oPropertySet.Add("Parts R Us", "Supplier", null); //Save document, prompt user for filename FileDialog oDLG = null; mApp.CreateFileDialog(out oDLG); oDLG.FileName = @"C:\Temp\NewPart.ipt"; oDLG.Filter = "Inventor Files (*.ipt)|*.ipt"; oDLG.DialogTitle = "Save Part"; oDLG.ShowSave(); if (oDLG.FileName != "") { oDoc.SaveAs(oDLG.FileName, false); oDoc.Close(true); } } }
internal string SaveSurfaceAndFixedPoints(ref List <double[]> FixedPoints, ref double[] oPlane) { string StlPath = System.IO.Path.GetTempPath() + "STLFileBlankCalculator";; oPartDoc = (PartDocument)CATIA.ActiveDocument; oSel = oPartDoc.Selection; oSpa = (SPAWorkbench)oPartDoc.GetWorkbench("SPAWorkbench"); FixedPoints = new List <double[]>(); oSel.Clear(); oSel.Add(SelectSurface("Selecione qual a superficie que pretende planificar. Esc para sair.")); oSel.Copy(); oSel.Clear(); PartDocument NewPart = (PartDocument)CATIA.Documents.Add("Part"); NewPart.Selection.Clear(); NewPart.Selection.Add(NewPart.Part); NewPart.Selection.PasteSpecial("CATPrtResultWithOutLink"); if (System.IO.File.Exists(StlPath + ".stl")) { System.IO.File.Delete(StlPath + ".stl"); } NewPart.Selection.Clear(); NewPart.Part.Update(); CATIA.DisplayFileAlerts = false; NewPart.ExportData(StlPath, "stl"); NewPart.Close(); CATIA.DisplayFileAlerts = true; object[] Vec = new object[3]; oSel.Clear(); Reference Ref1 = SelectPoint("Selecione o conjunto de pontos fixos. Esc para sair."); oSel.Clear(); if (Ref1 == null) { Environment.Exit(0); } oSpa.GetMeasurable(Ref1).GetPoint(Vec); FixedPoints.Add(new double[] { (double)Vec[0], (double)Vec[1], (double)Vec[2] }); do { Ref1 = SelectPoint("Selecione o conjunto de pontos fixos (" + FixedPoints.Count + " selecionados). Esc para terminar."); oSel.Clear(); if (Ref1 == null) { break; } oSpa.GetMeasurable(Ref1).GetPoint(Vec); FixedPoints.Add(new double[] { (double)Vec[0], (double)Vec[1], (double)Vec[2] }); } while (true); if (FixedPoints.Count == 0) { Environment.Exit(0); } oSel.Clear(); oPartDoc.Part.Update(); System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(500); Vec = new object[9]; Reference Ref2 = SelectPlane("Selecione qual o plano do planificado. Esc para terminar."); oSel.Clear(); oSpa.GetMeasurable(Ref2).GetPlane(Vec); oPlane = new double[] { (double)Vec[0], (double)Vec[1], (double)Vec[2], (double)Vec[3], (double)Vec[4], (double)Vec[5], (double)Vec[6], (double)Vec[7], (double)Vec[8] }; return(StlPath + ".stl"); }
///////////////////////////////////////////////////////////// // Use: Ok Button clicked Handler // ///////////////////////////////////////////////////////////// private void bOk_Click(object sender, EventArgs e) { bool silentOp = _Application.SilentOperation; _Application.SilentOperation = true; PartDocument template = _Application.Documents.Open( _ThreadTemplatePath, false) as PartDocument; _Application.SilentOperation = silentOp; if (!ValidateTemplateParameters(template)) { DialogResult res = MessageBox.Show( "Missing sketch parameter in template file!", "Invalid Template", MessageBoxButtons.OK, MessageBoxIcon.Error); bOk.Enabled = false; _ThreadTemplatePath = string.Empty; tbTemplate.Text = string.Empty; if (template != _Application.ActiveDocument) { template.Close(true); } return; } List <ThreadFeature> threads = new List <ThreadFeature>(); foreach (System.Object selectedObj in _InteractionManager.SelectedEntities) { ThreadFeature thread = selectedObj as ThreadFeature; if (thread.Suppressed) { continue; } threads.Add(thread); } PlanarSketch templateSketch = template.ComponentDefinition.Sketches[1]; if (!ThreadWorker.ModelizeThreads( _Document, templateSketch, threads, _extraPitch)) { DialogResult res = MessageBox.Show( "Failed to create CoilFeature... " + "Try with a bigger Pitch Offset value", "Modelization Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); switch (res) { case DialogResult.OK: //template.Close(true); return; default: break; } } // Problem: closing the template doc here // will empty the undo stack (as designed)... //template.Close(true); if (!_cleaned) { CleanUp(); } _InteractionManager.Terminate(); }
public void Close() { m_Document.Close(true); }
public void RunWithArguments(Document doc, NameValueMap map) { LogTrace("Initialiting"); PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); LogTrace("Part template opened"); TransientGeometry oTG = inventorApplication.TransientGeometry; PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition; UserParameters oParams = oPartComDef.Parameters.UserParameters; XmlDocument xmlDoc = new XmlDocument(); string currentDir = System.IO.Directory.GetCurrentDirectory(); string projectDir = Directory.GetParent(currentDir).Parent.FullName; LogTrace("Reading XML input file from " + projectDir); xmlDoc.Load(System.IO.Path.Combine(projectDir, "react-test-output.xml")); //xmlDoc.Load("react-test-output.xml"); //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml"); XmlNodeList FloorList = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor"); XmlNodeList FloorPointList = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point"); XmlNodeList ComponentName = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/ComponentName"); XmlNodeList PointX = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/X"); XmlNodeList PointY = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Y"); XmlNodeList PointZ = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Z"); for (int i = 0; i < FloorList.Count; i++) { //oParams.AddByExpression("ComponentName" + i, ComponentName[i].InnerText, UnitsTypeEnum.kUnitlessUnits); int numPoint = FloorPointList.Count / FloorList.Count; Point2d[] oPoints = new Point2d[numPoint]; SketchPoint[] osPoints = new SketchPoint[numPoint]; for (int j = 0; j < numPoint; j++) { oParams.AddByExpression("PointX" + j, PointX[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits); oParams.AddByExpression("PointY" + j, PointY[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits); oParams.AddByExpression("PointZ" + j, PointZ[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits); oPoints[j] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("PointX" + j, UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("PointY" + j, UnitsTypeEnum.kMillimeterLengthUnits)); } SketchLine[] oLines = new SketchLine[numPoint]; PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[2]); osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]); osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]); osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]); osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]); oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]); oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[2]); oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[3]); oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint); oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0// oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[2], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1// Profile oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "8", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef); string PartPath = projectDir + "/results/" + ComponentName[i].InnerText + i + ".ipt"; //string PartPath = ComponentName[i].InnerText + i + ".ipt"; oPartDoc.SaveAs(PartPath, false); oExtrude.Delete(); } oPartDoc.Close(false); AssemblyDocument oAssyDoc = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true); AssemblyComponentDefinition oAssyComDef = oAssyDoc.ComponentDefinition; ComponentOccurrences oAssyCompOccs = oAssyComDef.Occurrences; Matrix oPos = oTG.CreateMatrix(); int oStep = 0; int icomp; int numite = FloorPointList.Count / FloorList.Count; for (icomp = 0; icomp <= numite; icomp++) { oStep = oStep + 150; oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false); string PartPath = projectDir + "/results/" + ComponentName[icomp].InnerText + icomp + ".ipt"; //string PartPath = ComponentName[icomp].InnerText + icomp + ".ipt"; ComponentOccurrence oOcc = oAssyCompOccs.Add(PartPath, oPos); } oAssyDoc.SaveAs(projectDir + "/results/result.iam", false); //oAssyDoc.SaveAs("result.iam", false); oAssyDoc.Close(); ZipFile.CreateFromDirectory(projectDir + "/results", projectDir + "/forgeResult.zip"); }
public static void main(string path) { // ! prendo instanza Inventor getIstance(); PartDocument oDoc = (PartDocument)iApp.ActiveDocument; // ! Imposto SheetMetalDocument setSheetMetalDocument(oDoc); // ! Imposto thickness setThickness(oDoc); SheetMetalComponentDefinition oComp = (SheetMetalComponentDefinition)oDoc.ComponentDefinition; WorkPlane oWpReference = null; List <string> nameWp = new List <string>(); bool manual = false; foreach (WorkPlane oWp in oComp.WorkPlanes) { nameWp.Add(oWp.Name); if (oWp.Name == "manualPlane") { oWpReference = oWp; manual = true; } } if (!manual) { // ! Elimino raggiature List <string> faceCollToKeep = deleteFillet(oDoc); // ! Elimino facce deleteFace(oDoc, faceCollToKeep); // ! Creo Profilo createProfile(oDoc); // ! Creo Raggiature createFillet(oDoc); // ! Cerco le lavorazioni IDictionary <Face, List <Lavorazione> > lavorazione = detectLavorazioni(oDoc); // ! Creo sketch lavorazioni List <string> nomeSketch = createSketchLavorazione(oDoc, lavorazione); // ! Elimino con direct le lavorazioni deleteLavorazione(oDoc); // ! Cut lavorazione createCutLavorazione(oDoc, nomeSketch); // ! Aggiungo piano nel mezzo oWpReference = addPlaneInTheMiddleOfBox(oDoc); // ! Aggiungo proiezione cut addProjectCut(oDoc, oWpReference, manual); // ! Coloro lato bello } else { addProjectCut(oDoc, oWpReference, manual); } setTexture(oDoc); oDoc.Close(); }
public static void main_(string path) { // ! prendo instanza Inventor getIstance(); //oDoc = (PartDocument) iApp.ActiveDocument; string[] listFiles = System.IO.Directory.GetFiles(@path, "*.ipt"); int counter = 0; foreach (string file in listFiles) { counter++; if (System.IO.Path.GetExtension(file) == ".ipt") { PartDocument oDoc = (PartDocument)iApp.Documents.Open(@file); // ! Imposto SheetMetalDocument setSheetMetalDocument(oDoc); // ! Imposto thickness setThickness(oDoc); // ! Elimino raggiature List <string> faceCollToKeep = deleteFillet(oDoc); // ! Elimino facce deleteFace(oDoc, faceCollToKeep); // ! Creo Profilo createProfile(oDoc); // ! Creo Raggiature createFillet(oDoc); // ! Cerco le lavorazioni IDictionary <Face, List <Lavorazione> > lavorazione = detectLavorazioni(oDoc); // ! Creo sketch lavorazioni List <string> nomeSketch = createSketchLavorazione(oDoc, lavorazione); // ! Elimino con direct le lavorazioni deleteLavorazione(oDoc); // ! Cut lavorazione createCutLavorazione(oDoc, nomeSketch); // ! Aggiungo piano nel mezzo WorkPlane oWpReference = addPlaneInTheMiddleOfBox(oDoc); // ! Aggiungo proiezione cut addProjectCut(oDoc, oWpReference); // ! Coloro lato bello setTexture(oDoc); oDoc.Close(); } } }
private void DrawPartDoc(string filename) { DrawingDocument oDoc; Sheet oSheet; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// SetupNewDrawingDocument(out oDoc, out oSheet); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Open the part document, invisibly. PartDocument oBlockPart = mApp.Documents.Open(filename, false) as PartDocument; TransientGeometry oTG = mApp.TransientGeometry; //0.1 = 1:10 or 0.2 = 1:5 1:20=0.02 X-> Y ^ DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document, oTG.CreatePoint2d(28.7, 21), 0.1, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null); //59.4 x 42.0 29.7 X 21.0 DrawingView oTopView = oSheet.DrawingViews.AddProjectedView(oBaseView, oTG.CreatePoint2d(28.7, 29), DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null); //Projected views DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView, oTG.CreatePoint2d(45, 21), DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null); //look through the curves in view finds top horiz curve. Find an edge oSheet.RevisionTables.Add(oTG.CreatePoint2d(48.4, 23.5)); //1mm div 10//1 row = 4 DrawingCurve oSelectedCurve = null; foreach (DrawingCurve oCurve in oBaseView.get_DrawingCurves(null)) { //Skip Circles if (oCurve.StartPoint != null && oCurve.EndPoint != null) { if (WithinTol(oCurve.StartPoint.Y, oCurve.EndPoint.Y, 0.001)) { if (oSelectedCurve == null) { //This is the first horizontal curve found. oSelectedCurve = oCurve; } else { //Check to see if this curve is higher (smaller x value) than the current selected if (oCurve.MidPoint.Y < oSelectedCurve.MidPoint.X) { oSelectedCurve = oCurve; } } } } } //Create geometry intents point for the curve. GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent); GeometryIntent oGeomIntent2 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent); Point2d oDimPos = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y); //set up Dim GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions; //Styles sty = oDoc.StylesManager.Styles ; // DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Drax Dim Above"]; //MessageBox.Show(cmbDimStyles.Text); DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles[cmbDimStyles.Text]; //Set Layer //Layer layer = oDoc.StylesManager.Layers["D"]; //MessageBox.Show(cmbLayers.Text); Layer layer = oDoc.StylesManager.Layers[cmbLayers.Text]; //Create the dimension. LinearGeneralDimension oLinearDim; oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kAlignedDimensionType, true, dimstyle, layer); string newfilename; string swapfilename; newfilename = ""; swapfilename = ""; //Build New Filname Inventor.PropertySet InvPropertySet = oBlockPart.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"]; swapfilename = oBlockPart.FullFileName.Substring(0, oBlockPart.FullFileName.LastIndexOf("\\") + 1); //MessageBox.Show(swapfilename); newfilename = swapfilename + InvPropertySet["FULLFILENAME"].Value + ".idw"; oBlockPart.Close(true); oDoc.SaveAs(newfilename, true); oDoc.Close(true); }
public static void main(string path, ToolStripProgressBar pb1, ToolStripStatusLabel tstl1, ListView lv1) { // ! Istanza inventor getIstance(); // ! Tutti gli ipt dentro la folder // ? oDoc = (PartDocument) iApp.ActiveDocument; string[] listFiles = System.IO.Directory.GetFiles(@path, "*.ipt"); int counter = 0; pb1.Minimum = 0; pb1.Maximum = listFiles.Length; // ! Ciclo la lista ipt dentro la folder foreach (string file in listFiles) { counter++; pb1.Value = counter; if (System.IO.Path.GetExtension(file) == ".ipt") { tstl1.Text = System.IO.Path.GetFileName(file); // ! Apro il documento PartDocument oDoc = (PartDocument)iApp.Documents.Open(@file); // ! Imposto SheetMetalDocument setSheetMetalDocument(oDoc); // ! Imposto thickness setThickness(oDoc); //setThicknessFisso(oDoc, "Steel DX51D THK 1.5mm"); // ! Elimino raggiature List <string> faceCollToKeep = deleteFillet(oDoc); if (faceCollToKeep == null) { ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0); item1.SubItems.Add("Errore nell'eliminazione delle raggiature"); lv1.Items.AddRange(new ListViewItem[] { item1 }); //oDoc.Close(); //continue; } else { // ! Elimino facce deleteFace(oDoc, faceCollToKeep); // ! Creo Profilo bool profStatus = createProfile(oDoc); if (!profStatus) { ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0); item1.SubItems.Add("Errore nella creazione profilo"); lv1.Items.AddRange(new ListViewItem[] { item1 }); //oDoc.Close(); continue; } //!Creo Raggiature createFillet(oDoc); } //!Cerco le lavorazioni //IDictionary<Face, List<Lavorazione>> lavorazione = detectLavorazioni(oDoc); //!Creo sketch lavorazioni // List<string> nomeSketch = createSketchLavorazione(oDoc, lavorazione); //!Elimino con direct le lavorazioni //deleteLavorazione(oDoc); //!Cut lavorazione //createCutLavorazione(oDoc, nomeSketch); //!Aggiungo piano nel mezzo WorkPlane oWpReference = addPlaneInTheMiddleOfBox(oDoc); //!Aggiungo proiezione cut bool projCutStatus = addProjectCut(oDoc, oWpReference); if (!projCutStatus) { ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0); item1.SubItems.Add("Errore nella creazione della proiezione cut"); lv1.Items.AddRange(new ListViewItem[] { item1 }); //oDoc.Close(); continue; } // ! Coloro lato bello setTexture(oDoc); // ! Faccio lo sviluppo bool sviluppoLamStatus = sviluppoLamiera(oDoc); if (!sviluppoLamStatus) { ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0); item1.SubItems.Add("Errore nella creazione dello sviluppo"); lv1.Items.AddRange(new ListViewItem[] { item1 }); } // ! Chiudo il documento //oDoc.Close(true); // Nascondo Sketch esportazione template try { oDoc.ComponentDefinition.Sketches["EXP_ConvexHull"].Visible = false; } catch { } // ! Salvo il documento //oDoc.Save(); oDoc.Close(); } } MessageBox.Show("Procedimento completato", "Creator Sheet Metal"); }