public Sticker(Inventor.Document pDoc, Inventor.Application m_InvApp) { InitializeComponent(); invApp = m_InvApp; m_TG = invApp.TransientGeometry; if (pDoc.DocumentType == DocumentTypeEnum.kPartDocumentObject) { m_Doc = (PartDocument)pDoc; } if (pDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { m_Asm = (AssemblyDocument)pDoc; compDef = m_Asm.ComponentDefinition; box = compDef.RangeBox; } valXML = new List <string>(); attrXML = new List <string>(); if (System.IO.File.Exists(@"C:\ProgramData\Autodesk\Inventor Addins\Stickers.xml")) { tbl = new InvDoc.XML(@"C:\ProgramData\Autodesk\Inventor Addins\Stickers.xml"); tbl.ReadXML("Sticker", ref valXML, ref attrXML); if (attrXML.Count != 0) { for (int i = 0; i < attrXML.Count; i++) { if (attrXML[i].StartsWith("Name=")) { string XMLVal = tbl.substring(attrXML[i], "Name="); this.comboBox1.Items.Add(XMLVal); } } } } }
public void _buttonDef1_OnExecute(NameValueMap Context) { Inventor.Document Document = m_inventorApplication.ActiveDocument; if (Document.DocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject) { Inventor.PartDocument PartDocument = (Inventor.PartDocument)Document; // System.Windows.Forms.MessageBox.Show("Button clicked!!", "Ribbon Demo"); SetReps mSetting = new SetReps(); mSetting.Show(); mSetting.SetSettings(ref PartDocument); } }
/// <summary> /// Derives an .ipt from a .iam and saves it in the same directory. /// Returns resulting file name /// </summary> /// <param name="AssemblyFileName">Path to the target assembly file</param> /// <param name="OptionalProgramId">Optional program identifier (ie. FCAM, ACAD...) Saves as AssemblyFileName_OptionalProgramId.ipt</param> static public string DerivePartFromAssembly(string AssemblyFileName, string OptionalProgramId = "") { Application app; try { //get running application instance app = GetInventorObject(); app.Visible = true; //Create new empty part document to derive into Inventor.PartDocument doc = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject) as PartDocument; //Create derived assembly definition from assembly file Inventor.DerivedAssemblyDefinition def = doc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssemblyFileName); //Derive from definition doc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(def); //Save document with optional program use identifier doc.SaveAs($"{AssemblyFileName}_{OptionalProgramId}.ipt", false); string fileName = doc.FullFileName; doc.Close(); return(fileName); } catch (Exception e) { throw new Exception("An error occured in the InventorHelperLib: " + e.Message); } finally { app = null; } return(""); }
override protected void ButtonDefinition_OnExecute(NameValueMap context) { try { //MessageBox.Show("ERES UN CAPO"); AutodeskInventorInterop AII = new AutodeskInventorInterop(); string filename = "..\\CMUdata\\meshanid.srf"; // Parses files into location and vertex connectivity from an SRF file AII.ReadFileDataToList(filename); //log.Info("Reading meshanid.srf"); // Parses file for elements in riemanian metric matrix in 3D filename = "..\\CMUdata\\meshanid.nt3m"; AII.ReadFileDataToList_nt3m(filename); // log.Info("Reading meshanid.nt3m"); // Decomposes the Riemanian Matrix M=Q.L.Q^-1 AII.EigenDecomp3D(AII.EigenList); // log.Info("EigenDecomposition"); // log.Info("User Coordinate System"); Inventor.Application mApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application; Inventor.PartDocument oDoc = (Inventor.PartDocument)mApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); //Defines a part component oCompDef = oDoc.ComponentDefinition; //Used to create a Unitvector where to store MajorAxis 2D for ellipse TransientGeometry oTG = mApp.TransientGeometry; UnitVector2d oUniVector = oTG.CreateUnitVector2d(1, 1); Point2d oPoint2d = mApp.TransientGeometry.CreatePoint2d(0, 0); Profile oProfile = default(Profile); //Creates a profile //EdgeCollection oEdge = default(EdgeCollection); Edge[] oSideEdges = new Edge[5]; //FilletFeature oFillet = default(FilletFeature); WorkPoint oWorkPoint1 = default(WorkPoint); WorkPoint oWorkPoint2 = default(WorkPoint); WorkPoint oWorkPoint3 = default(WorkPoint); UserCoordinateSystemDefinition oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition(); UserCoordinateSystem oUCS = default(UserCoordinateSystem); EigenVectorPatternSketchPlane selectPlaneToSketch = new EigenVectorPatternSketchPlane(); //ERASE THIS NOT USEFUL PartComponentDefinition oDef = oDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); ObjectCollection oFitPoints = mApp.TransientObjects.CreateObjectCollection(); Point2d oPoint2d_a = default(Point2d); SketchEllipticalArc oEllipticalArc = default(SketchEllipticalArc); SketchLine oAxis = default(SketchLine); RevolveFeature oRevolve = default(RevolveFeature); // WorkPlane oWPain = default(WorkPlane); #region "This is my life" /****************************************** COMMENT ***********************************************/ // Philippe Leefsma : [email protected] // Here is where all the pain happens // thank you for your help in advance. // Here is where I create a User defined coordinate system per each one of the features shown // I do not know if there is a way of making this faster? /****************************************** COMMENT ***********************************************/ for (int i = 0; i < AII.VertexLocation.Count; i++) { oWorkPoint1 = oCompDef.WorkPoints.AddFixed( oTG.CreatePoint( (double)AII.VertexLocation[i].origen.X, (double)AII.VertexLocation[i].origen.Y, (double)AII.VertexLocation[i].origen.Z) ); //Change here u1/10 this is to make it closer to the mm value check if needs to be chage to in oWorkPoint2 = oCompDef.WorkPoints.AddFixed( oTG.CreatePoint( (double)AII.EigenVectorValue[i].evc.u1 + (double)AII.VertexLocation[i].origen.X, (double)AII.EigenVectorValue[i].evc.u2 + (double)AII.VertexLocation[i].origen.Y, (double)AII.EigenVectorValue[i].evc.u3 + (double)AII.VertexLocation[i].origen.Z) ); //Check here maybe this is why my rotations are screwd up, instead of v1 maybe is w1 //If w is use I have a cool effect with the protution coming out of the screen oWorkPoint3 = oCompDef.WorkPoints.AddFixed( oTG.CreatePoint( (double)AII.EigenVectorValue[i].evc.v1 + (double)AII.VertexLocation[i].origen.X, (double)AII.EigenVectorValue[i].evc.v2 + (double)AII.VertexLocation[i].origen.Y, (double)AII.EigenVectorValue[i].evc.v3 + (double)AII.VertexLocation[i].origen.Z) ); //User Define Coordinate oUCSDef.SetByThreePoints(oWorkPoint1, oWorkPoint2, oWorkPoint3); oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef); oPoint2d.X = 0; oPoint2d.Y = 0; double l1 = AII.EigenVectorValue[i].evl.l1; double l2 = AII.EigenVectorValue[i].evl.l2; //Here maybe we can reduece time by pre-working these numbers double h1 = (1 / Math.Sqrt(l1)); //Check here double h2 = (1 / Math.Sqrt(l2)); //Change here to add alfa angle oUniVector.X = 1; // Math.Abs(AII.EigenVectorValue[i].evc.u1); //CHNAGE HERE 0 ,1 //if this is negative changes the direction oUniVector.Y = 0; // Math.Abs(AII.EigenVectorValue[i].evc.u2); oSketch = selectPlaneToSketch.SelectPlane(oDoc, oUCS); //Candidates for config file oWorkPoint1.Visible = false; oWorkPoint2.Visible = false; oWorkPoint3.Visible = false; oUCS.Visible = false; double PI = Math.Atan(1) * 4.0; double duoPI = 2 * PI; double sizeBubbleInverse = 3.5; //this changes the sizes in the features contracts the bubbles "SIZING METRIC" #region "Revolve and Join" oPoint2d_a = mApp.TransientGeometry.CreatePoint2d(0, 0); //Create Elliptical Arc oEllipticalArc = oSketch.SketchEllipticalArcs.Add(oPoint2d_a, oUniVector, h1 / (sizeBubbleInverse), h2 / (sizeBubbleInverse), 0, PI); oAxis = oSketch.SketchLines.AddByTwoPoints( oEllipticalArc.StartSketchPoint, oEllipticalArc.EndSketchPoint); oProfile = oSketch.Profiles.AddForSolid(); oRevolve = oDoc.ComponentDefinition.Features.RevolveFeatures.AddFull (oProfile, oAxis, PartFeatureOperationEnum.kJoinOperation); #endregion } #endregion } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public static String Test() { if (_invApp.Documents.Count == 0) { return "Need to open an Assembly document or Part document"; } if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject && _invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kPartDocumentObject) { return "Need to open an Assembly document or Part document"; } // Here is a slight variation in the code where I look for a PART vs a ASSEMBLY File if (_invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { AssemblyDocument doc = default(AssemblyDocument); doc = (AssemblyDocument)_invApp.ActiveDocument; type = "Assembly"; } if (_invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject) { PartDocument doc = default(PartDocument); doc = (PartDocument)_invApp.ActiveDocument; type = "Part"; } //Gets Current document name! name = (_invApp.ActiveDocument.DisplayName); //For Assembly Files if (type == "Assembly") { ASSEMBLY_DOCUMENT = (Inventor.AssemblyDocument)_invApp.ActiveDocument; AssemblyComponentDefinitions assDef = ASSEMBLY_DOCUMENT.ComponentDefinitions; GenerateExportList(assDef); //GenerateExportList(ASSEMBLY_DOCUMENT.ComponentDefinition.Parameters); } if(type == "Part") { PART_DOCUMENT = (Inventor.PartDocument)_invApp.ActiveDocument; PartFeatures pFeat = PART_DOCUMENT.ComponentDefinition.Features; GenerateExportList(pFeat); } //Saves the info into XML base SaveFile xSave = new SaveFile(program, type, length, name, attributesText); return "This exported correctly!"; }
// Load template file and extract related parameters public List <InventorParameterStructure> LoadInventorTemplateParameters(string fullPath) { NLogger.LogText("Entered LoadInventorTemplateParameters method"); var inventorParams = new List <InventorParameterStructure>(); Parameters InventorParams = null; // TODO: HANDLE THE HARDCODED PATH //var rootPath = Utilities.GetBIM360RootPath(); //var fullPath = rootPath + @"ATDSK DEV\Sample Project\Project Files\Libraries\" + templateName; try { NLogger.LogText($"Try opening assembly document {fullPath}"); try { NLogger.LogText($"Try opening assembly document {fullPath} with LOD specified"); NameValueMap oOptions = m_InventorApplication.TransientObjects.CreateNameValueMap(); oOptions.Add("LevelOfDetailRepresentation", "LOD1"); m_AssemblyDocument = (AssemblyDocument)m_InventorApplication.Documents.OpenWithOptions(fullPath, oOptions, false); NLogger.LogText($"Opening assembly document {fullPath} with LOD specified suceeded"); } catch { NLogger.LogText($"Failed opening assembly document {fullPath} with LOD specified. Try to open it without LOD specified"); m_AssemblyDocument = (AssemblyDocument)m_InventorApplication.Documents.Open(fullPath, false); NLogger.LogText($"Opening assembly document {fullPath} without LOD specified suceeded"); } // Load params NLogger.LogText("Load assembly document parameters"); InventorParams = m_AssemblyDocument.ComponentDefinition.Parameters; } catch (Exception ex) { NLogger.LogText("An error has occurred casting to an Inventor Assembly document. Try casting to a Part document"); try { NLogger.LogText($"Try opening part document {fullPath}"); m_PartDocument = (PartDocument)m_InventorApplication.Documents.Open(fullPath, false); NLogger.LogText($"Opening part document {fullPath} suceeded"); // Load params NLogger.LogText("Load Part document parameters"); InventorParams = m_PartDocument.ComponentDefinition.Parameters; } catch (Exception ex1) { NLogger.LogText("An error has occurred casting to an Inventor Part document"); NLogger.LogError(ex1); throw (ex1); } } NLogger.LogText("Create 'InventorParameterStructure'"); for (int h = 1; h <= InventorParams.Count; h++) { if (ConfigUtilities.GetInventorElementShowOnlyKeys().ToLower() == "true") { if (InventorParams[h].IsKey) { inventorParams.Add(new InventorParameterStructure { Name = InventorParams[h].Name.ToString() }); } } else { inventorParams.Add(new InventorParameterStructure { Name = InventorParams[h].Name.ToString() }); } } NLogger.LogText("Remove documents from Inventor application instance"); m_InventorApplication.Documents.CloseAll(); NLogger.LogText("Exit LoadInventorTemplateParameters method"); return(inventorParams); }
private InvPartDocument(Inventor.PartDocument invPartDocument) { InternalPartDocument = invPartDocument; }
public static InvPartDocument ByInvPartDocument(Inventor.PartDocument invPartDocument) { return(new InvPartDocument(invPartDocument)); }
private void button1_Click(object sender, EventArgs e) { try { this.Hide(); double h = 1, w = 1; if (m_Asm != null) { CommandManager cmdMgr = invApp.CommandManager; string txt = ""; //input = cmdMgr.UserInputEvents; intEvts = cmdMgr.CreateInteractionEvents(); intEvts.InteractionDisabled = false; sel = intEvts.SelectEvents; sel.AddSelectionFilter(SelectionFilterEnum.kPartFaceFilter); sel.OnSelect += new SelectEventsSink_OnSelectEventHandler(select); mouse = intEvts.MouseEvents; mouse.OnMouseClick += new MouseEventsSink_OnMouseClickEventHandler(selPt); intEvts.Start(); intEvts.StatusBarText = "Выберите поверхность:"; //input.OnSelect += new UserInputEventsSink_OnSelectEventHandler(select); //face = (Face)cmdMgr.Pick(SelectionFilterEnum.kPartFaceFilter, "Выберите поверхность:"); //input.OnSelect -= new UserInputEventsSink_OnSelectEventHandler(select); flag = true; while (flag) { invApp.UserInterfaceManager.DoEvents(); } intEvts.Stop(); sel.OnSelect -= new SelectEventsSink_OnSelectEventHandler(select); intEvts.MouseEvents.OnMouseClick -= new MouseEventsSink_OnMouseClickEventHandler(selPt); List <string> tmp = new List <string>(); string name = comboBox1.Text; m_Doc = (PartDocument)invApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, CreateVisible: false); m_Doc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure; m_Doc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits; string filename = ""; for (int i = 0; i < attrXML.Count; i++) { if (attrXML[i].StartsWith("Name=" + name)) { tmp.Add(attrXML[i]); tmp.Add(valXML[i]); i++; while (i < attrXML.Count && attrXML[i].StartsWith("RowHeight=")) { tmp.Add(attrXML[i]); tmp.Add(valXML[i]); i++; } break; } } string nameStricker = ""; string strTmp = tbl.substring(tmp[0], "PartNumber="); nameStricker = strTmp; if (strTmp != "") { m_Doc.PropertySets[3][2].Value = strTmp; filename += strTmp; } strTmp = tbl.substring(tmp[0], "Description="); if (strTmp != "") { m_Doc.PropertySets[3][14].Value = strTmp; filename += (filename == "") ? strTmp : "-" + strTmp; } Func <string, double> conv = s => { char rep = (separator == ',') ? '.' : ','; return((s.IndexOf(separator) != -1) ? Convert.ToDouble(s) : Convert.ToDouble(s.Replace(rep, separator))); }; strTmp = tbl.substring(tmp[0], "Height="); if (strTmp != "") { h = conv(strTmp); } strTmp = tbl.substring(tmp[0], "Width="); if (strTmp != "") { w = conv(strTmp); } strTmp = tbl.substring(tmp[0], "txt="); if (strTmp != "") { txt = strTmp; } strTmp = tbl.substring(tmp[0], "Sort="); if (strTmp != "") { m_Doc.PropertySets[1][4].Value = strTmp; } strTmp = tbl.substring(tmp[0], "Note="); if (strTmp != "") { m_Doc.PropertySets[1][5].Value = strTmp; } strTmp = tbl.substring(tmp[0], "Triangle="); if (strTmp == "False") { triangle = false; } else { triangle = true; } strTmp = tbl.substring(tmp[0], "Offset1="); if (strTmp != "") { offset1 = conv(strTmp) / 10; } strTmp = tbl.substring(tmp[0], "Offset2="); if (strTmp != "") { offset2 = conv(strTmp) / 10; } strTmp = tbl.substring(tmp[0], "Mirror="); if (strTmp != "") { mirror = true; } if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface) { filename += "-" + w.ToString() + "x" + h.ToString(); if (!System.IO.File.Exists(path(m_Asm.FullFileName) + filename + ".ipt")) { Plane plane = (Plane)face.Geometry; vecZ = plane.Normal; if (!triangle) { planarSticker(ref m_Doc, h, w, txt); } else { triangleSticker(ref m_Doc, h, w, txt); } } } else if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { R = Math.Round(((Cylinder)face.Geometry).Radius, 2); filename += "-" + w.ToString() + "x" + h.ToString() + "x" + (R * 10).ToString(); if (!System.IO.File.Exists(path(m_Asm.FullFileName) + filename + ".ipt")) { if (this.radioButton1.Checked) { circleSticker(ref m_Doc, w, h, R, txt); filename += "(верт)"; } else { circleSticker(ref m_Doc, h, w, R, txt); } } } filename = path(m_Asm.FullFileName) + filename + ".ipt"; if (!System.IO.File.Exists(filename)) { m_Doc.SaveAs(filename, false); Document tmp_Doc = invApp.Documents.Open(filename, false); tmp_Doc.PropertySets[3][2].Value = nameStricker; tmp_Doc.Save(); tmp_Doc.Close(); m_Doc.Close(); } Inventor.Point pt = m_TG.CreatePoint(); //pos = m_TG.CreateMatrix(); //rot.SetCoordinateSystem(insPt, m_TG.CreateVector(YCoord: 1), m_TG.CreateVector(1) , m_TG.CreateVector(ZCoord: 1)); //pos.TransformBy(rot); // if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface && !System.IO.File.Exists(filename)) // { //} AssemblyComponentDefinition compDef = m_Asm.ComponentDefinition; //pos.Cell[4, 1] = insPt.X; pos.Cell[4, 2] = insPt.Y; pos.Cell[4, 3] = insPt.Z; rot = m_TG.CreateMatrix(); ComponentOccurrence occ = compDef.Occurrences.Add(filename, rot); Vector vec1 = InvDoc.u.getAxis(face); Vector vec2 = InvDoc.u.getAxis(occ); if (!InvDoc.u.eq(vec1, vec2)) { rot.SetToRotateTo(vec1, vec2); } //m_Asm.ComponentDefinition.WorkPoints.AddFixed(insPt); vec = pt.VectorTo(insPt); rot.SetTranslation(vec); //rot.Cell[1, 4] = insPt.X; rot.Cell[2, 4] = insPt.Y; rot.Cell[3, 4] = insPt.Z; //occ.Transformation = rot; occ.SetTransformWithoutConstraints(rot); //rot.SetToRotateTo(m_TG.CreateVector(ZCoord: 1), vecZ.AsVector(), m_TG.CreateVector(XCoord: 1)); //rot.SetTranslation(vec); //return; //Face face2 = occ.SurfaceBodies[1].Faces[5]; object fac = null; occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[3], out fac); WorkPlaneProxy face2 = (WorkPlaneProxy)fac; PartComponentDefinition def = (PartComponentDefinition)occ.Definition; //Inventor.Point pt2 = def.WorkPoints[1].Point; //pos.Invert(); //pt2.TransformBy(pos); if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface) { compDef.Constraints.AddFlushConstraint(face, face2, 0); } else if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { //foreach (Face f in occ.SurfaceBodies[1].Faces) //{ // if (f.SurfaceType == SurfaceTypeEnum.kCylinderSurface) // { // if (Math.Round(((Cylinder)f.Geometry).Radius, 2) == R) // { // face2 = f; break; // } // } //} occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkAxes[2], out fac); compDef.Constraints.AddMateConstraint((WorkAxisProxy)fac, face, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine); } //Matrix trans = m_TG.CreateMatrix(); //trans.SetTranslation(vec,true); //occ.Transformation.Cell[1, 4] = insPt.X; occ.Transformation.Cell[2, 4] = insPt.Y; occ.Transformation.Cell[3, 4] = insPt.Z; object face1 = null; if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { if (offset1 > 0.05 && offset1 < 0.4) { //PartComponentDefinition pDef = ((PartDocument)((FaceProxy)face).ContainingOccurrence.Definition.Document).ComponentDefinition; ((FaceProxy)face).ContainingOccurrence.CreateGeometryProxy(InvDoc.u.getPlane((FaceProxy)face), out fac); //createProxy((FaceProxy)face, (int)(offset1 * 10), ref fac); //occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[(int)(offset1 * 10)], out fac); face1 = fac; offset1 = 0; } else /*if (offset1 != 0)*/ { offset1 += w / 20; ent = (Edge)cmdMgr.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Выберите торцевое ребро:"); if (ent.Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) { face1 = ent.Faces[1]; } else { face1 = ent.Faces[2]; } } // if (offset2 != 0) // { // offset2 += h / 20; // } //face1 = cmdMgr.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Выберите тор" } else { if (offset1 > 0.05 && offset1 < 0.4) { createProxy((FaceProxy)face, (int)(offset1 * 10), ref fac); //occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[(int)(offset1 * 10)], out fac); edge1 = fac; offset1 = 0; } else /*if (offset1 != 0)*/ { offset1 += h / 20; edge1 = cmdMgr.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Выберите ребро или плоскость:"); } } //face2 = occ.SurfaceBodies[1].Faces[2]; occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[2], out fac); face2 = (WorkPlaneProxy)fac; MateConstraint mc = null; FlushConstraint fc = null; // if (offset2 < 0.4) // { // face1 = createProxy(occ, (int)(offset2 * 10)); //compDef.WorkPlanes[(int)(offset2*10)]; // } //else if (offset2 != 0) offset2 += h / 20; if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { fc = compDef.Constraints.AddFlushConstraint(face2, face1, offset1); } else { mc = compDef.Constraints.AddMateConstraint(face2, edge1, offset1); } // Inventor.Point ptmc = occ.RangeBox.MinPoint; // SelectionFilterEnum [] f = {SelectionFilterEnum.kPartFaceFilter}; // ObjectsEnumerator en = compDef.FindUsingPoint(ptmc, ref f, 0.1); if (/*en.Count < 3*/ InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face)) { if (mc != null) { mc.Offset.Value = -(double)mc.Offset.Value; } //else fc.Offset.Value = - (double)fc.Offset.Value; } if (offset2 > 0.05 && offset2 < 0.4) { createProxy((FaceProxy)face, (int)(offset2 * 10), ref fac); //occ.CreateGeometryProxy(((PartComponentDefinition)face.ReferenceComponent.ReferencedDocumentDescriptor.ReferencedDocument.Definition).WorkPlanes[(int)(offset2 * 10)], out fac); edge2 = fac; offset2 = 0; } else /*if (offset2 != 0)*/ { if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { offset2 += h / 20; } else { offset2 += w / 20; } edge2 = cmdMgr.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Выберите ребро или плоскость:"); } //face2 = occ.SurfaceBodies[1].Faces[1]; occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[1], out fac); face2 = (WorkPlaneProxy)fac; mc = compDef.Constraints.AddMateConstraint(face2, edge2, offset2); if (mc.HealthStatus == HealthStatusEnum.kInconsistentHealth) { occ.Constraints[2].ConvertToFlushConstraint(occ.Constraints[2].EntityOne, occ.Constraints[2].EntityTwo, offset1); } //en = compDef.FindUsingPoint(ptmc, ref f, 0.1); m_Asm.Update(); if (/*en.Count < 3*/ InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face)) { mc.Delete(); mc = compDef.Constraints.AddMateConstraint(face2, edge2, offset2); m_Asm.Update(); if (InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face)) { //mc.Delete(); //mc = compDef.Constraints.AddMateConstraint(face2, edge1, -offset2); double dist = Macros.StandardAddInServer.m_inventorApplication.MeasureTools.GetMinimumDistance(occ.RangeBox.MinPoint, edge2); if (dist > offset2 * 2) { rot = m_TG.CreateMatrix(); Vector tr = occ.Transformation.Translation; rot.SetToRotation(Math.PI, InvDoc.u.getAxis(occ), m_TG.CreatePoint(tr.X, tr.Y, tr.Z)); mc.Delete(); occ.Transformation = rot; mc = compDef.Constraints.AddMateConstraint(face2, edge2, offset2); if (InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face)) { mc.Offset.Value = -(double)mc.Offset.Value; } } else if (InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face)) { mc.Offset.Value = -(double)mc.Offset.Value; } m_Asm.Update(); } //mc.Offset.Value = -(double)mc.Offset.Value; } //occ.Transformation = trans; } this.Close(); } catch (Exception) { //MessageBox.Show(ex.ToString()); this.Close(); } }